mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05: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_login import current_user
|
||||||
from flask_socketio import disconnect
|
from flask_socketio import disconnect
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
@ -39,15 +39,17 @@ def socketio_admin_required(f):
|
|||||||
if current_user.is_administrator:
|
if current_user.is_administrator:
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
disconnect()
|
response = {'code': 401, 'desc': 'Unauthorized'}
|
||||||
|
socketio.emit(request.event['message'], response, room=request.sid)
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
def socketio_login_required(f):
|
def socketio_login_required(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapped(*args, **kwargs):
|
def wrapped(*args, **kwargs):
|
||||||
if not current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
disconnect()
|
|
||||||
else:
|
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
|
else:
|
||||||
|
response = {'code': 401, 'desc': 'Unauthorized'}
|
||||||
|
socketio.emit(request.event['message'], response, room=request.sid)
|
||||||
return wrapped
|
return wrapped
|
||||||
|
Loading…
Reference in New Issue
Block a user