Ajout d'une base pour le login

This commit is contained in:
n07070 2022-03-15 14:50:10 +01:00
parent e82672b8cb
commit 5b28213075

View File

@ -4,3 +4,36 @@ class User(object):
def __init__(self, arg): def __init__(self, arg):
super(User, self).__init__() super(User, self).__init__()
self.arg = arg 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'))