diff options
Diffstat (limited to 'api/events.py')
-rw-r--r-- | api/events.py | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/api/events.py b/api/events.py index 150f403..695edb1 100644 --- a/api/events.py +++ b/api/events.py @@ -1,34 +1,10 @@ -from flask import Blueprint, request, make_response -from flask_socketio import SocketIO, emit, Namespace, join_room, leave_room, rooms +from flask_socketio import join_room from socket_io import io -from auth.login_token import token_login -from http import cookies - -from game.cleanup import set_interval -import time - - -# get token from flask_socketio's request.environment -def get_token(environ): - cookie = environ.get("HTTP_COOKIE") - if not cookie: return None - - parsed = cookies.SimpleCookie() - parsed.load(cookie) - - token = parsed.get("token") - if not token: return None - - return token.value +from hierarchy import io_auth_required # global socket connection @io.on("connect") -def connect(): - token = get_token(request.environ) - if not token: return - - user_id = token_login(token) - if not user_id: return - +@io_auth_required("none") +def connect(data, user_id): join_room("user-" + user_id) |