main: Add failed login page
All checks were successful
Build Docker / Build Bot (push) Successful in 22s
Build Docker / Build Master (push) Successful in 28s

This commit is contained in:
Nathan Woodburn 2023-08-25 16:47:22 +10:00
parent 843d2d12a0
commit 9853214d83
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -462,18 +462,25 @@ def admin():
@app.route('/login', methods=['POST'])
def login():
if request.method == 'POST':
# Handle login
print('Login attempt', flush=True)
password = request.form['password']
if os.getenv('ADMIN_KEY') == password:
# Generate login key
login_key = os.urandom(32).hex()
logins.append(login_key)
# Set cookie
resp = make_response(redirect('/admin'))
resp.set_cookie('login_key', login_key)
return resp
# Handle login
print('Login attempt', flush=True)
password = request.form['password']
print('Password: ' + password, flush=True)
if os.getenv('ADMIN_KEY') == password:
print('Login success', flush=True)
# Generate login key
login_key = os.urandom(32).hex()
logins.append(login_key)
# Set cookie
resp = make_response(redirect('/admin'))
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>"