Last active
August 30, 2018 00:06
-
-
Save Julian-Nash/1386d91f3e8507d0ee2e1fb130acaeb0 to your computer and use it in GitHub Desktop.
Flask session wrapper - Control view access with this decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def in_session(f): | |
@wraps(f) | |
def decorated_function(*args, **kwargs): | |
if session.get("LOGGED_IN") == False: | |
return redirect(url_for('login')) | |
return f(*args, **kwargs) | |
return decorated_function | |
# Usage -------------------------------------------------------- | |
@app.route("/shop/profile", methods=["GET", "POST"]) | |
@in_session | |
def profile(): | |
user = get_user() | |
page_title = "Profile" | |
return render_template("frontent/client_profile.html", app_title=app_title, page_title=page_title, user=user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment