Created
March 3, 2018 14:01
-
-
Save taiypeo/b1dcce31b736faca84c8fb01d67c31aa to your computer and use it in GitHub Desktop.
A bunch of Flask decorators that I used
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 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