Ajout d'une base pour le login
This commit is contained in:
parent
e82672b8cb
commit
5b28213075
33
src/user.py
33
src/user.py
@ -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'))
|
||||||
|
Loading…
Reference in New Issue
Block a user