refactor security to Flask-Security - Part 1
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
from functools import wraps
|
||||
from flask_jwt_extended import get_jwt, verify_jwt_in_request
|
||||
|
||||
|
||||
def super_required():
|
||||
def wrapper(fn):
|
||||
@wraps(fn)
|
||||
def decorator(*args, **kwargs):
|
||||
verify_jwt_in_request()
|
||||
claims = get_jwt()
|
||||
if not claims['is_super']:
|
||||
return {'message': 'Authentication Error: Super users only!'}, 403
|
||||
else:
|
||||
return fn(*args, **kwargs)
|
||||
|
||||
return decorator
|
||||
return wrapper
|
||||
|
||||
|
||||
# Decorators
|
||||
|
||||
|
||||
def admin_required():
|
||||
def wrapper(fn):
|
||||
@wraps(fn)
|
||||
def decorator(*args, **kwargs):
|
||||
verify_jwt_in_request()
|
||||
claims = get_jwt()
|
||||
if not claims['is_admin']:
|
||||
return {'message': 'Authentication Error: Admins only!'}, 403
|
||||
else:
|
||||
return fn(*args, **kwargs)
|
||||
|
||||
return decorator
|
||||
return wrapper
|
||||
|
||||
|
||||
def tester_required():
|
||||
def wrapper(fn):
|
||||
@wraps(fn)
|
||||
def decorator(*args, **kwargs):
|
||||
verify_jwt_in_request()
|
||||
claims = get_jwt()
|
||||
if not claims['is_tester']:
|
||||
return {'message': 'Authentication Error: Testers only!'}, 403
|
||||
else:
|
||||
return fn(*args, **kwargs)
|
||||
|
||||
return decorator
|
||||
return wrapper
|
||||
Reference in New Issue
Block a user