push
This commit is contained in:
16
app/utils/decorators.py
Normal file
16
app/utils/decorators.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from functools import wraps
|
||||
from flask import abort
|
||||
from flask_login import current_user
|
||||
|
||||
|
||||
def roles_required(*roles):
|
||||
def decorator(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
if not current_user.is_authenticated:
|
||||
abort(401)
|
||||
if current_user.role not in roles:
|
||||
abort(403)
|
||||
return func(*args, **kwargs)
|
||||
return wrapper
|
||||
return decorator
|
||||
Reference in New Issue
Block a user