added permissions api and websocket stuff

This commit is contained in:
2019-11-28 19:39:53 +01:00
parent c4b54357f7
commit a709dbcaef
14 changed files with 229 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
import logging
import threading
from flask_jwt_extended import verify_jwt_in_request, get_current_user, jwt_required, get_jwt_claims, get_jwt_identity
from flask_login import current_user
from flask_socketio import SocketIO, emit
@@ -35,17 +36,16 @@ class WebSocketBase:
@socketio.on('connect')
def connect_handler():
logger.debug("new connection...")
print(current_user)
if current_user.is_authenticated:
logger.debug("user is authenticated")
print("allowed!")
emit('my response',
{'message': '{0} has joined'.format(current_user.name)},
broadcast=True)
else:
try:
print(verify_jwt_in_request())
print(get_jwt_identity())
except:
logger.info("user is not authenticated!")
print("not allowed!!")
return False # not allowed here
logger.debug("user is authenticated")
print("allowed!")
return True
@socketio.on_error()
def handle_error(self, error):
@@ -55,5 +55,5 @@ class WebSocketBase:
if __name__ == '__main__':
wsb = WebSocketBase()
#wsb.start_websocket_in_thread(debug=True)
# wsb.start_websocket_in_thread(debug=True)
wsb.start_websocket(debug=True)