From 5b28213075db5bafe5705c893ac221c24d2708bb Mon Sep 17 00:00:00 2001 From: n07070 Date: Tue, 15 Mar 2022 14:50:10 +0100 Subject: [PATCH] Ajout d'une base pour le login --- src/user.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/user.py b/src/user.py index 0d73c5b..1776c1b 100644 --- a/src/user.py +++ b/src/user.py @@ -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'))