Created
March 10, 2018 13:28
-
-
Save CubexX/5cdd15dfb9ac59ced815891e42edc8fb to your computer and use it in GitHub Desktop.
Python flask login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONFIG['password'] = 'PASS' | |
def login_required(func): | |
def wrapper(*args, **kwargs): | |
if not session or session['hash'] != generate_hash(CONFIG['password']): | |
return redirect('/login') | |
else: | |
return func(*args, **kwargs) | |
wrapper.__name__ = func.__name__ | |
return wrapper | |
######### | |
@app.route('/login', methods=['GET', 'POST']) | |
def login_view(): | |
if request.method == 'POST': | |
session['hash'] = generate_hash(request.form['password']) | |
if session['hash'] == generate_hash(CONFIG['password']): | |
return redirect('/') | |
else: | |
return redirect('/login') | |
return render_template('login.html') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment