diff options
Diffstat (limited to 'api/events.py')
-rw-r--r-- | api/events.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/api/events.py b/api/events.py index ef3ae12..150f403 100644 --- a/api/events.py +++ b/api/events.py @@ -7,27 +7,28 @@ 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 + cookie = environ.get("HTTP_COOKIE") + if not cookie: return None + + parsed = cookies.SimpleCookie() + parsed.load(cookie) - parsed = cookies.SimpleCookie() - parsed.load(cookie) + token = parsed.get("token") + if not token: return None - token = parsed.get("token") - if not token: return None + return token.value - return token.value # 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 + token = get_token(request.environ) + if not token: return - join_room("user-" + user_id) + user_id = token_login(token) + if not user_id: return + join_room("user-" + user_id) |