Compare commits

...

6 Commits

Author SHA1 Message Date
5b28213075 Ajout d'une base pour le login 2022-03-15 14:50:10 +01:00
e82672b8cb Mise à jour des logs 2022-03-15 14:49:58 +01:00
4fea7c1e86 Ajout d'un try/except 2022-03-15 14:49:26 +01:00
be3770956c Ajout d'un try/except' 2022-03-15 14:49:05 +01:00
5a0cc6011b Mise à jour des templates 2022-03-15 14:48:15 +01:00
81a99b6a80 Ajout d'un exécutable pour lancer le serveur 2022-03-15 14:48:05 +01:00
10 changed files with 58 additions and 13 deletions

3
run.sh Executable file
View File

@ -0,0 +1,3 @@
export FLASK_APP=src/main.py
export FLASK_ENV=development
flask run --host 192.168.0.42 --debugger --eager-loading

View File

@ -87,7 +87,11 @@ def api_print_sms():
flash(e)
redirect(url_for('index'))
flash(web.print_sms(txt,sign))
try:
web.print_sms(txt,sign)
except Exception as e:
pass
return redirect(url_for('index'))
@app.route('/api/print/image', methods=['POST'])

View File

@ -120,13 +120,17 @@ class Printer(object):
return False
if not os.getenv('LIPY_DEBUG') == True:
self.printer.open(self.usb_args);
self.printer.set(align='left', font='a', bold=False, underline=0, width=1, height=1, density=8, invert=False, smooth=True, flip=False, double_width=False, double_height=False, custom_size=False)
self.printer.textln(clean_msg)
self.printer.set(align='left', font='b', bold=False, underline=1, width=1, height=1, density=9, invert=False, smooth=True, flip=False, double_width=False, double_height=False, custom_size=False)
self.printer.textln("> " + clean_signature + " @ " + strftime("%Y-%m-%d %H:%M:%S", gmtime()))
self.printer.cut()
self.printer.close()
try:
self.printer.open(self.usb_args);
self.printer.set(align='left', font='a', bold=False, underline=0, width=1, height=1, density=8, invert=False, smooth=True, flip=False, double_width=False, double_height=False, custom_size=False)
self.printer.textln(clean_msg)
self.printer.set(align='left', font='b', bold=False, underline=1, width=1, height=1, density=9, invert=False, smooth=True, flip=False, double_width=False, double_height=False, custom_size=False)
self.printer.textln("> " + clean_signature + " @ " + strftime("%Y-%m-%d %H:%M:%S", gmtime()))
self.printer.cut()
self.printer.close
except Exception as e:
flash("Unable to print because : " + e)
flash("Message printed : " + clean_msg ,category='info')
return True

View File

View File

View File

@ -12,11 +12,12 @@
<div class="col-md-6 offset-md-3">
<img class="rounded" width="100px" src="{{ url_for('static', filename='images/little-printer.png') }}" alt="LittlePrynter icon"><h1 class="card-title font-weight-bold">Little Prynter</h1>
<hr>
<div class="alert alert-dark" role="alert">LittlePrynter is under heavy developpement, you may encounter bugs ! If so, try again. Thanks !</div>
<br>
{% with messages = get_flashed_messages(category_filter=('error')) %}
{% if messages %}
{% for message in messages %}
<div class="alert alert-warning" role="alert">{{ message }}</div>
<div class="alert alert-danger" role="alert">{{ message }}</div>
{% endfor %}
{% endif %}
{% endwith %}
@ -54,7 +55,7 @@
<br>
<br>
<hr>
<footer>Little Prynter is built for fun by <a href="https://n07070.xyz/about-me/">n07070</a> for fun :) </footer>
<footer>Little Prynter is built by <a href="https://n07070.xyz/about-me/">n07070</a> for fun :) </footer>
</div>
</body>
</html>

0
src/templates/login.html Normal file
View File

0
src/templates/print.html Normal file
View File

View File

@ -4,3 +4,36 @@ class User(object):
def __init__(self, arg):
super(User, self).__init__()
self.arg = arg
# @app.route('/login', methods=['POST','GET'])
# @limiter.limit("100 per minute", error_message=error_handler_limiter)
def login():
if request.method == 'POST':
if not session.get('logged_in'):
if request.form['username'] and request.form['password']:
# Get the json
with open('users.json') as f:
users_file = json.load(f)
for user in users_file["users"]:
if users_file["users"][user] == request.form['password']:
session['logged_in'] = True
session['user'] = request.form['username']
if not session.get('logged_in'):
flash('Mot de passe ou pseudo invalide.','danger')
return redirect(url_for('login'))
else:
return redirect(url_for('display_index_page'))
else:
flash('Incorrect logins')
return render_template('password.html')
else:
return render_template('password.html')
else:
return render_template('password.html')
@app.route("/logout")
def logout():
session['logged_in'] = False
flash('Tu est déconnecté', 'info')
return redirect(url_for('login'))

View File

@ -13,15 +13,15 @@ class Web(object):
def print_sms(self, texte, sign: str):
# TODO: verify the texte before printing it here ?
self.app.logger.debug("Printing : " + str(texte))
self.app.logger.debug("Printing : " + str(texte) + " from " + str(sign))
if not os.getenv('LIPY_DEBUG'):
time.sleep(10)
time.sleep(1)
return self.printer.print_sms(texte, sign)
def print_image(self, image):
pass
def login(username: str,password: str) -> bool:
pass