Add url param to login form to control redirect

Site layouts that include a login form on every page can now include
their relative URI (`request.path`) so the user can be redirected back
to the same page after login.
This commit is contained in:
Noah 2014-05-09 19:29:49 +00:00
parent afa783386b
commit da81ea21bc

View File

@ -34,6 +34,12 @@ def login():
session["uid"] = db["uid"]
session["name"] = db["name"]
session["role"] = db["role"]
# Redirect them to a local page?
url = request.form.get("url", "")
if url[0] == "/":
return redirect(url)
return redirect(url_for("index"))
else:
flash("Authentication failed.")
@ -126,4 +132,4 @@ def validate_create_form(username, pw1=None, pw2=None, skip_passwd=False):
if len(errors):
return errors
else:
return None
return None