mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Proper socketio_login/admin_required decorators
This commit is contained in:
parent
f86301112b
commit
8d201a29ae
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user