Skip to content
Snippets Groups Projects
Commit c5fa65ad authored by Martin Mareš's avatar Martin Mareš
Browse files

Hack pro přihlašování testovacích uživatelů

Úmyslně udělaný tak, aby i kdyby ho někdo omylem zapnul na produkčním
OSMO, stejně se na žádného existujícího uživatele nepůjde přihlásit.
parent 6070aaba
No related branches found
No related tags found
1 merge request!121Testovací prostředí
This commit is part of merge request !121. Comments created here will be created in the context of that merge request.
......@@ -73,3 +73,7 @@ CURRENT_YEAR = 71
MO_WEB_SERVER = 'http://localhost:5001'
MO_WEB_LOGIN = 'matemaicky_hroch'
MO_WEB_PASSWD = 'BrumBrum'
# Povolení loginu bez hesla pro testovací uživatele (s adresou končící na @test).
# Nezapínat mimo testovací prostředí! Bydlí na /test-login/<email>.
#INSECURE_TEST_LOGIN = True
......@@ -659,3 +659,21 @@ def confirm_reset():
@app.errorhandler(werkzeug.exceptions.Forbidden)
def handle_forbidden(e):
return render_template('forbidden.html'), 403
if getattr(config, 'INSECURE_TEST_LOGIN', False):
@app.route('/test-login/<email>')
def test_login(email: str):
if not email.endswith('@test'):
app.logger.error('Test login: Uživatel <%s> nekončí na @test', email)
raise werkzeug.exceptions.NotFound()
user = mo.users.user_by_email(email)
if not user:
app.logger.error('Test login: Neznámý uživatel <%s>', email)
raise werkzeug.exceptions.Forbidden()
app.logger.info('Test login: Přihlásil se uživatel #%s <%s>', user.user_id, email)
mo.users.login(user)
db.get_session().commit()
return login_and_redirect(user)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment