Created
November 21, 2012 19:07
-
-
Save jawsthegame/4126952 to your computer and use it in GitHub Desktop.
This file contains 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 admin_required(func): | |
""" | |
Wraps a function to ensure that it's only viewable by logged in admins. If a | |
user is not logged in, it redirects to a login page with an acceptable error | |
message. If a user is logged in, but not a admin, it takes them to the root | |
page with an error. | |
""" | |
@wraps(func) | |
@login_required | |
def view_wrapper(*args, **kwargs): | |
if not g.user.is_admin: | |
flash("You must have a admin account to view this page.", 'error') | |
remove_user(g.user) | |
return redirect('/admin/') | |
return func(*args, **kwargs) | |
return view_wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment