Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDDD97 Web Programming
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lawrence Zawahri
TDDD97 Web Programming
Commits
6e9c9584
Commit
6e9c9584
authored
3 years ago
by
Lawrence Zawahri
Browse files
Options
Downloads
Patches
Plain Diff
problem
parent
19bb88c3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Lab_3/Twidder/server.py
+22
-24
22 additions, 24 deletions
Lab_3/Twidder/server.py
with
22 additions
and
24 deletions
Lab_3/Twidder/server.py
+
22
−
24
View file @
6e9c9584
...
...
@@ -28,8 +28,7 @@ app = Flask(__name__, static_url_path = '/static')#in case flask does not recogn
sock
=
Sock
(
app
)
app
.
debug
=
True
session
=
{
'
token
'
:
'
email
'
}
signedInUser
=
{
'
email
'
:
'
wsObj
'
}
session
=
{
'
token
'
:
(
"
email
"
,
"
wsObj
"
)}
@app.route
(
'
/
'
)
def
root
():
...
...
@@ -73,34 +72,34 @@ def echo(socket):
if
not
socket
:
return
# Making sure message format is OK and store email & token in string
data
=
socket
.
receive
()
try
:
myEmail
=
json
.
loads
(
data
)[
"
email
"
]
except
:
signedInUser
[
email
].
close
()
# session[token?][1
].close()
return
try
:
myToken
=
json
.
loads
(
data
)[
"
token
"
]
except
:
signedInUser
[
email
].
close
()
# session[token?][1
].close()
return
print
(
s
ignedInUser
)
print
(
s
ession
)
# sign out if I am logged in somewhere else
for
email
in
list
(
s
ignedInUser
.
keys
()):
if
email
==
myEmail
:
for
token
in
list
(
s
ession
.
keys
()):
if
session
[
token
][
0
]
==
myEmail
and
session
[
token
][
1
]
!=
""
:
print
(
"
You got kicked out
"
)
signedInUser
[
email
].
send
(
json
.
dumps
({
"
action
"
:
"
signOut
"
}))
signedInUser
[
email
].
close
()
signedInUser
.
pop
(
email
)
print
(
signedInUser
)
session
[
token
][
1
].
send
(
json
.
dumps
({
"
action
"
:
"
signOut
"
}))
session
[
token
][
1
].
close
()
session
.
pop
(
token
)
print
(
session
)
# Put socket in global dict so server knows my connection is open
s
ignedInUser
[
myEmail
]
=
socket
print
(
s
ignedInUser
)
s
ession
[
myToken
]
=
(
myEmail
,
socket
)
print
(
s
ession
)
socket
.
send
(
json
.
dumps
({
"
action
"
:
"
signIn
"
}))
...
...
@@ -130,7 +129,7 @@ def sign_in():
# Generate a random token
token
=
str
(
uuid
.
uuid4
())
session
[
token
]
=
email
session
[
token
]
=
(
email
,
""
)
# return the token in the Authorization header
response
=
make_response
(
jsonify
({}))
#"Server inserted user data into database"
...
...
@@ -197,15 +196,14 @@ def sign_out():
if
tmp
[
0
]:
return
jsonify
({}),
tmp
[
1
]
print
(
signedInUser
)
# Close my socket
myEmail
=
session
[
token
]
print
(
session
)
try
:
signedInUser
[
myEmail
].
close
()
signedInUser
.
pop
(
myEmail
)
session
[
token
][
1
].
close
()
except
:
pass
# samma sak som ingenting
print
(
s
ignedInUser
)
print
(
s
ession
)
# set user to not logged in
session
.
pop
(
token
)
...
...
@@ -239,7 +237,7 @@ def change_password():
new_password
=
tmp
[
2
]
# 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
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():
return
jsonify
({}),
401
# "User not signed in or invalid access token"
# Extracting the email of the current user
email
=
session
[
token
]
email
=
session
[
token
]
[
0
]
return
get_user_data_by_email
(
email
)
...
...
@@ -304,7 +302,7 @@ def get_user_messages_by_token():
return
jsonify
({}),
tmp
[
1
]
# Extracting the email of the current user
email
=
session
[
token
]
email
=
session
[
token
]
[
0
]
return
get_user_messages_by_email
(
email
)
@app.route
(
"
/myServer/getMessagesByEmail/<req_email>
"
,
methods
=
[
'
GET
'
])
...
...
@@ -353,7 +351,7 @@ def post_message():
return
jsonify
({}),
tmp
[
1
]
# Extracting the email of the current user
my_email
=
session
[
token
]
my_email
=
session
[
token
]
[
0
]
# Find out & check email we are posting to
tmp
=
input_has_error
(
'
email
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment