From dd07b92bdeae93a339adcb1e1585e6905c4be185 Mon Sep 17 00:00:00 2001 From: Lawrence Zawahri <louza078@student.liu.se> Date: Mon, 21 Mar 2022 21:22:35 +0100 Subject: [PATCH] lab 3 working on bug ficx --- Lab_3/Twidder/server.py | 27 ++++++++++++++++++++++----- Lab_3/Twidder/static/client.js | 3 +-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Lab_3/Twidder/server.py b/Lab_3/Twidder/server.py index d8b132c..e85ba16 100644 --- a/Lab_3/Twidder/server.py +++ b/Lab_3/Twidder/server.py @@ -85,19 +85,36 @@ def echo(socket): return # sign out if I am logged in somewhere else + + print("Before loop") + print("/n") print(session) + print("/n") + for token in list(session.keys()): - if session[token][0] == myEmail and token != myToken: - if session[token][1] != "": - session[token][1].send(json.dumps({"action" : "signOut"})) - session[token][1].close() + if session[token][0] == myEmail and token != myToken and session[token][1] != "": + print("Inside first if") + #if session[token][1] != "": + print("Inside second if") + session[token][1].send(json.dumps({"action" : "signOut"})) + print(token[1]) + session[token][1].close() print("You got kicked out") session.pop(token) + + print("After loop") + print("/n") print(session) + print("/n") # Put socket in global dict so server knows my connection is open session[myToken] = (myEmail, socket) + + print("After insertion into dict") + print("/n") print(session) + print("/n") + socket.send(json.dumps({"action" : "signIn"})) @@ -123,7 +140,7 @@ def sign_in(): return jsonify({}), 404 #"No user found by your email" if password != rows[1]: - return jsonify({}), 401 #"Incorrect password") + return jsonify({}), 401 #"Incorrect password") x # Generate a random token token = str(uuid.uuid4()) diff --git a/Lab_3/Twidder/static/client.js b/Lab_3/Twidder/static/client.js index a4995c8..95fc651 100644 --- a/Lab_3/Twidder/static/client.js +++ b/Lab_3/Twidder/static/client.js @@ -17,7 +17,6 @@ function connectWithSocket() { displayView(); setUserDetails("home"); - // Establish web socket socket = new WebSocket('ws://' + document.domain + ':5000/myServer/api'); @@ -37,7 +36,7 @@ function connectWithSocket() { case "signOut": // If old socket open, close it. - socket.close(); + //socket.close(); console.log(response); // Reset token in the localStorage -- GitLab