main: Login fixes
All checks were successful
Build Docker / Build Bot (push) Successful in 25s
Build Docker / Build Master (push) Successful in 27s

This commit is contained in:
Nathan Woodburn 2023-08-25 16:36:53 +10:00
parent 9e485265af
commit 8f962804a4
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -10,7 +10,7 @@ dotenv.load_dotenv()
app = Flask(__name__)
loggins = []
logins = []
# API add license key (requires API key in header)
@app.route('/add-licence', methods=['POST'])
@ -447,33 +447,35 @@ def home():
return html
# Admin page
@app.route('/admin', methods=['GET', 'POST'])
@app.route('/admin')
def admin():
# Check if logged in
login_key = request.cookies.get('login_key')
if login_key == None:
return "<h1>Admin</h1><br><form action='/login' method='POST'><input type='password' name='Master API'><input type='submit' value='Login'></form>"
if login_key not in logins:
return "<h1>Admin</h1><br><form action='/login' method='POST'><input type='password' name='Master API'><input type='submit' value='Login'></form>"
return "<h1>Admin</h1><br>Logged in"
@app.route('/login', methods=['POST'])
def admin():
if request.method == 'POST':
# Handle login
print('Login attempt', flush=True)
password = request.form['password']
if os.getenv(ADMIN_KEY) == password:
if os.getenv('ADMIN_KEY') == password:
# Generate login key
login_key = os.urandom(32).hex()
loggins.append(login_key)
logins.append(login_key)
# Set cookie
resp = make_response(redirect('/admin'))
resp.set_cookie('login_key', login_key)
return resp
if login_key == None:
return "<h1>Admin</h1><br><form action='/admin' method='POST'><input type='password' name='Master API'><input type='submit' value='Login'></form>"
if login_key not in loggins:
return "<h1>Admin</h1><br><form action='/admin' method='POST'><input type='password' name='Master API'><input type='submit' value='Login'></form>"
return "<h1>Admin</h1><br>Logged in"