Proper socketio_login/admin_required decorators

This commit is contained in:
Patrick Jentsch 2020-05-20 09:36:59 +02:00
parent f86301112b
commit 8d201a29ae

View File

@ -1,4 +1,4 @@
from flask import abort, current_app
from flask import abort, current_app, request
from flask_login import current_user
from flask_socketio import disconnect
from functools import wraps
@ -39,15 +39,17 @@ def socketio_admin_required(f):
if current_user.is_administrator:
return f(*args, **kwargs)
else:
disconnect()
response = {'code': 401, 'desc': 'Unauthorized'}
socketio.emit(request.event['message'], response, room=request.sid)
return wrapped
def socketio_login_required(f):
@wraps(f)
def wrapped(*args, **kwargs):
if not current_user.is_authenticated:
disconnect()
else:
if current_user.is_authenticated:
return f(*args, **kwargs)
else:
response = {'code': 401, 'desc': 'Unauthorized'}
socketio.emit(request.event['message'], response, room=request.sid)
return wrapped