Last active
January 3, 2016 14:59
-
-
Save mike1e/8479758 to your computer and use it in GitHub Desktop.
Flask authorization
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 login_required(role="ANY"): | |
def wrapper(fn): | |
@wraps(fn) | |
def decorated_view(*args, **kwargs): | |
if not current_user.is_authenticated(): | |
return current_app.login_manager.unauthorized() | |
urole = current_user.get_role() | |
if ( (urole != role) and (role != "ANY")): | |
logout_user() | |
return current_app.login_manager.unauthorized() | |
return fn(*args, **kwargs) | |
return decorated_view | |
return wrapper | |
@app.route('/school/') | |
@login_required(role="SCHOOL") | |
def restricted_view_for_school(): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment