added permissions api and websocket stuff
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user