mirror of
https://github.com/Xevion/v1.xevion.dev.git
synced 2025-12-06 01:16:47 -06:00
19 lines
435 B
Python
19 lines
435 B
Python
from functools import wraps
|
|
|
|
from flask import abort
|
|
from flask_login import current_user
|
|
|
|
|
|
def require_role(roles=["User"]):
|
|
def wrap(func):
|
|
@wraps(func)
|
|
def decorated_view(*args, **kwargs):
|
|
if current_user.is_authenticated:
|
|
if current_user.has_roles(roles):
|
|
return func(*args, **kwargs)
|
|
return abort(401)
|
|
|
|
return decorated_view
|
|
|
|
return wrap
|