Skip to content

Instantly share code, notes, and snippets.

@taiypeo
Created March 3, 2018 14:01
Show Gist options
  • Save taiypeo/b1dcce31b736faca84c8fb01d67c31aa to your computer and use it in GitHub Desktop.
Save taiypeo/b1dcce31b736faca84c8fb01d67c31aa to your computer and use it in GitHub Desktop.
A bunch of Flask decorators that I used
def role_required(role=ROLE_USER):
def wrapper(f):
@wraps(f)
def role_checker(*args, **kwargs):
if not current_user.is_authenticated:
abort(403)
if role == ROLE_USER or current_user.role == role:
return f(*args, **kwargs)
else:
abort(403)
return role_checker
return wrapper
def unauthenticated_required(f):
@wraps(f)
def wrapper(*args, **kwargs):
if not current_user.is_authenticated:
return f(*args, **kwargs)
return redirect(url_for('index'))
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment