mirror of
https://github.com/partitioncloud/partitioncloud-server.git
synced 2025-01-23 09:16:25 +01:00
Redirect logged-in users
This commit is contained in:
parent
c735b1e496
commit
e4777cf7a6
@ -82,9 +82,9 @@ def add_user():
|
||||
return render_template("auth/register.html", albums=get_all_albums(), user=current_user)
|
||||
|
||||
|
||||
# Automatically close db after each request
|
||||
@app.after_request
|
||||
def after_request(response):
|
||||
"""Automatically close db after each request"""
|
||||
if ('db' in g) and (g.db is not None):
|
||||
g.db.close()
|
||||
return response
|
||||
|
@ -38,6 +38,19 @@ def login_required(view):
|
||||
return wrapped_view
|
||||
|
||||
|
||||
def anon_required(view):
|
||||
"""View decorator that redirects authenticated users to the index."""
|
||||
|
||||
@functools.wraps(view)
|
||||
def wrapped_view(**kwargs):
|
||||
if g.user is not None:
|
||||
return redirect(url_for("albums.index"))
|
||||
|
||||
return view(**kwargs)
|
||||
|
||||
return wrapped_view
|
||||
|
||||
|
||||
def admin_required(view):
|
||||
"""View decorator that redirects anonymous users to the login page."""
|
||||
|
||||
@ -72,6 +85,7 @@ def load_logged_in_user():
|
||||
|
||||
|
||||
@bp.route("/register", methods=("GET", "POST"))
|
||||
@anon_required
|
||||
def register():
|
||||
"""Register a new user.
|
||||
Validates that the username is not already taken. Hashes the
|
||||
@ -115,6 +129,7 @@ def register():
|
||||
|
||||
|
||||
@bp.route("/login", methods=("GET", "POST"))
|
||||
@anon_required
|
||||
def login():
|
||||
"""Log in a registered user by adding the user id to the session."""
|
||||
if request.method == "POST":
|
||||
|
Loading…
Reference in New Issue
Block a user