27 lines
672 B
Python
Executable File
27 lines
672 B
Python
Executable File
from flask_login import current_user
|
|
from flask import abort
|
|
|
|
from functools import wraps
|
|
from app.common.responses import error_response
|
|
|
|
def login_required(f):
|
|
@wraps(f)
|
|
|
|
def decorated_function(*args, **kwargs):
|
|
if current_user.is_authenticated:
|
|
pass
|
|
else:
|
|
abort(401)
|
|
return f(*args, **kwargs)
|
|
|
|
return decorated_function
|
|
|
|
|
|
def admin_required(f):
|
|
@wraps(f)
|
|
def decorated_function(*args, **kwargs):
|
|
if not current_user.is_authenticated or not current_user.admin_role:
|
|
return error_response("Admin access required", 403)
|
|
return f(*args, **kwargs)
|
|
return decorated_function
|