Skip to content

Instantly share code, notes, and snippets.

@mike1e mike1e/
Last active Jan 3, 2016

What would you like to do?
Flask authorization
def login_required(role="ANY"):
def wrapper(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")):
return current_app.login_manager.unauthorized()
return fn(*args, **kwargs)
return decorated_view
return wrapper
def restricted_view_for_school():
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.