nopaque/app/decorators.py

35 lines
811 B
Python
Raw Normal View History

from flask import abort
from flask_login import current_user
from flask_socketio import disconnect
2020-03-27 11:06:11 +00:00
from functools import wraps
from .models import Permission
def admin_required(f):
@wraps(f)
def wrapped(*args, **kwargs):
if not current_user.can(Permission.ADMIN):
abort(403)
return f(*args, **kwargs)
return wrapped
def socketio_login_required(f):
@wraps(f)
def wrapped(*args, **kwargs):
if not current_user.is_authenticated:
disconnect()
else:
return f(*args, **kwargs)
return wrapped
def socketio_admin_required(f):
@wraps(f)
def wrapped(*args, **kwargs):
if not current_user.can(Permission.ADMIN):
disconnect()
else:
return f(*args, **kwargs)
return wrapped