Add support for 'next' URL parameter for redirect after auth

This commit is contained in:
Edward Betts 2024-01-21 16:22:37 +00:00
parent 32e06e9d98
commit 9d122264e5

View file

@ -84,10 +84,16 @@ def login_page() -> str | werkzeug.Response:
# Login failed: Show an error message on the login page
return flask.render_template("login.html", error="Invalid credentials")
redirect_to = (
flask.request.args.get("next")
or flask.session.get("next")
or flask.url_for("dashboard")
)
expire_date = datetime.now() + timedelta(days=180)
flask.flash("Welcome back! You have successfully logged in.")
response = flask.redirect(flask.session.get("next") or flask.url_for("dashboard"))
response = flask.redirect(redirect_to)
response.set_cookie(
"auth_token",
generate_auth_token(user["username"]),