main: Add failed login page
This commit is contained in:
parent
843d2d12a0
commit
9853214d83
@ -462,18 +462,25 @@ def admin():
|
|||||||
|
|
||||||
@app.route('/login', methods=['POST'])
|
@app.route('/login', methods=['POST'])
|
||||||
def login():
|
def login():
|
||||||
if request.method == 'POST':
|
# Handle login
|
||||||
# Handle login
|
print('Login attempt', flush=True)
|
||||||
print('Login attempt', flush=True)
|
password = request.form['password']
|
||||||
password = request.form['password']
|
print('Password: ' + password, flush=True)
|
||||||
if os.getenv('ADMIN_KEY') == password:
|
if os.getenv('ADMIN_KEY') == password:
|
||||||
# Generate login key
|
print('Login success', flush=True)
|
||||||
login_key = os.urandom(32).hex()
|
# Generate login key
|
||||||
logins.append(login_key)
|
login_key = os.urandom(32).hex()
|
||||||
# Set cookie
|
logins.append(login_key)
|
||||||
resp = make_response(redirect('/admin'))
|
# Set cookie
|
||||||
resp.set_cookie('login_key', login_key)
|
resp = make_response(redirect('/admin'))
|
||||||
return resp
|
resp.set_cookie('login_key', login_key)
|
||||||
|
return resp
|
||||||
|
print('Login failed', flush=True)
|
||||||
|
return redirect('/failed-login')
|
||||||
|
|
||||||
|
@app.route('/failed-login')
|
||||||
|
def failed_login():
|
||||||
|
return "<h1>Failed login</h1><br><form action='/login' method='POST'><input type='password' name='Master API'><input type='submit' value='Login'></form>"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user