Skip to content
Snippets Groups Projects
Commit 6e9c9584 authored by Lawrence Zawahri's avatar Lawrence Zawahri
Browse files

problem

parent 19bb88c3
No related branches found
No related tags found
No related merge requests found
...@@ -28,8 +28,7 @@ app = Flask(__name__, static_url_path = '/static')#in case flask does not recogn ...@@ -28,8 +28,7 @@ app = Flask(__name__, static_url_path = '/static')#in case flask does not recogn
sock = Sock(app) sock = Sock(app)
app.debug = True app.debug = True
session = {'token':'email'} session = {'token': ("email", "wsObj")}
signedInUser = {'email':'wsObj'}
@app.route('/') @app.route('/')
def root(): def root():
...@@ -73,34 +72,34 @@ def echo(socket): ...@@ -73,34 +72,34 @@ def echo(socket):
if not socket: if not socket:
return return
# Making sure message format is OK and store email & token in string # Making sure message format is OK and store email & token in string
data = socket.receive() data = socket.receive()
try: try:
myEmail = json.loads(data)["email"] myEmail = json.loads(data)["email"]
except: except:
signedInUser[email].close() # session[token?][1].close()
return return
try: try:
myToken = json.loads(data)["token"] myToken = json.loads(data)["token"]
except: except:
signedInUser[email].close() # session[token?][1].close()
return return
print(signedInUser) print(session)
# sign out if I am logged in somewhere else # sign out if I am logged in somewhere else
for email in list(signedInUser.keys()): for token in list(session.keys()):
if email == myEmail: if session[token][0] == myEmail and session[token][1] != "":
print("You got kicked out") print("You got kicked out")
signedInUser[email].send(json.dumps({"action" : "signOut"})) session[token][1].send(json.dumps({"action" : "signOut"}))
signedInUser[email].close() session[token][1].close()
signedInUser.pop(email) session.pop(token)
print(signedInUser)
print(session)
# Put socket in global dict so server knows my connection is open # Put socket in global dict so server knows my connection is open
signedInUser[myEmail] = socket session[myToken] = (myEmail, socket)
print(signedInUser) print(session)
socket.send(json.dumps({"action" : "signIn"})) socket.send(json.dumps({"action" : "signIn"}))
...@@ -130,7 +129,7 @@ def sign_in(): ...@@ -130,7 +129,7 @@ def sign_in():
# Generate a random token # Generate a random token
token = str(uuid.uuid4()) token = str(uuid.uuid4())
session[token] = email session[token] = (email, "")
# return the token in the Authorization header # return the token in the Authorization header
response = make_response(jsonify({})) #"Server inserted user data into database" response = make_response(jsonify({})) #"Server inserted user data into database"
...@@ -197,15 +196,14 @@ def sign_out(): ...@@ -197,15 +196,14 @@ def sign_out():
if tmp[0]: if tmp[0]:
return jsonify({}), tmp[1] return jsonify({}), tmp[1]
print(signedInUser)
# Close my socket # Close my socket
myEmail = session[token] print(session)
try: try:
signedInUser[myEmail].close() session[token][1].close()
signedInUser.pop(myEmail)
except: except:
pass # samma sak som ingenting pass # samma sak som ingenting
print(signedInUser) print(session)
# set user to not logged in # set user to not logged in
session.pop(token) session.pop(token)
...@@ -239,7 +237,7 @@ def change_password(): ...@@ -239,7 +237,7 @@ def change_password():
new_password = tmp[2] new_password = tmp[2]
# Extracting theemail of the current user # Extracting theemail of the current user
email = session[token] email = session[token][0]
# Validation of the old password and attemption to change it to the new one # Validation of the old password and attemption to change it to the new one
if old_password == database_helper.find_user(email)[1]: #checks if old_password is correct if old_password == database_helper.find_user(email)[1]: #checks if old_password is correct
...@@ -263,7 +261,7 @@ def get_user_data_by_token(): ...@@ -263,7 +261,7 @@ def get_user_data_by_token():
return jsonify({}), 401 # "User not signed in or invalid access token" return jsonify({}), 401 # "User not signed in or invalid access token"
# Extracting the email of the current user # Extracting the email of the current user
email = session[token] email = session[token][0]
return get_user_data_by_email(email) return get_user_data_by_email(email)
...@@ -304,7 +302,7 @@ def get_user_messages_by_token(): ...@@ -304,7 +302,7 @@ def get_user_messages_by_token():
return jsonify({}), tmp[1] return jsonify({}), tmp[1]
# Extracting the email of the current user # Extracting the email of the current user
email = session[token] email = session[token][0]
return get_user_messages_by_email(email) return get_user_messages_by_email(email)
@app.route("/myServer/getMessagesByEmail/<req_email>", methods=['GET']) @app.route("/myServer/getMessagesByEmail/<req_email>", methods=['GET'])
...@@ -353,7 +351,7 @@ def post_message(): ...@@ -353,7 +351,7 @@ def post_message():
return jsonify({}), tmp[1] return jsonify({}), tmp[1]
# Extracting the email of the current user # Extracting the email of the current user
my_email = session[token] my_email = session[token][0]
# Find out & check email we are posting to # Find out & check email we are posting to
tmp = input_has_error('email') tmp = input_has_error('email')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment