Add support for 'next' URL parameter for redirect after auth
This commit is contained in:
parent
32e06e9d98
commit
9d122264e5
8
main.py
8
main.py
|
@ -84,10 +84,16 @@ def login_page() -> str | werkzeug.Response:
|
||||||
# Login failed: Show an error message on the login page
|
# Login failed: Show an error message on the login page
|
||||||
return flask.render_template("login.html", error="Invalid credentials")
|
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)
|
expire_date = datetime.now() + timedelta(days=180)
|
||||||
flask.flash("Welcome back! You have successfully logged in.")
|
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(
|
response.set_cookie(
|
||||||
"auth_token",
|
"auth_token",
|
||||||
generate_auth_token(user["username"]),
|
generate_auth_token(user["username"]),
|
||||||
|
|
Loading…
Reference in a new issue