add authentication by trusted X-HTTP-Header

This commit is contained in:
Jakobus Schürz 2019-09-26 09:24:54 +02:00
parent 3d33f37f23
commit fa2fe85b12

View file

@ -104,6 +104,29 @@ def login():
return redirect(url_for('pubkeys.index'))
flash(error)
elif request.method == 'GET':
print(request.headers.get('X-AUTHENTICATION-id'))
#print(dict(request.headers))
db = get_db()
error = None
if request.headers.get('X-AUTHENTICATION-id') is not None:
username = request.headers.get('X-AUTHENTICATION-id')
user = db.execute(
'SELECT * FROM user WHERE username = ?', (username,)
).fetchone()
if user is None:
error = 'Incorrect username.'
return redirect(url_for('auth.register'))
if error is None:
session.clear()
session['user_id'] = user['id']
return redirect(url_for('pubkeys.index'))
else:
return redirect(url_for('auth.register'))
return render_template('auth/login.html')