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
418c360e
Commit
418c360e
authored
3 years ago
by
Johan Thörnblom
Browse files
Options
Downloads
Patches
Plain Diff
m
parent
578577b0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Lab_4/Twidder/server.py
+15
-6
15 additions, 6 deletions
Lab_4/Twidder/server.py
Lab_4/Twidder/static/client.js
+0
-4
0 additions, 4 deletions
Lab_4/Twidder/static/client.js
with
15 additions
and
10 deletions
Lab_4/Twidder/server.py
+
15
−
6
View file @
418c360e
...
...
@@ -5,6 +5,8 @@ import uuid
import
database_helper
import
json
from
flask_sock
import
Sock
import
threading
from
gevent
import
monkey
monkey
.
patch_all
()
...
...
@@ -28,7 +30,7 @@ sock = Sock(app)
app
.
debug
=
True
session
=
{
'
token
'
:
(
"
email
"
,
"
wsObj
"
)}
lock
=
threading
.
Lock
()
@app.route
(
'
/
'
)
...
...
@@ -86,6 +88,8 @@ def echo(socket):
# sign out if I am logged in somewhere else
print
(
session
)
lock
.
acquire
()
for
token
in
list
(
session
.
keys
()):
if
session
[
token
][
0
]
==
myEmail
and
token
!=
myToken
:
if
session
[
token
][
1
]
!=
""
:
...
...
@@ -93,6 +97,8 @@ def echo(socket):
session
[
token
][
1
].
close
()
print
(
"
You got kicked out
"
)
session
.
pop
(
token
)
lock
.
release
()
print
(
session
)
# Put socket in global dict so server knows my connection is open
...
...
@@ -127,7 +133,9 @@ def sign_in():
# Generate a random token
token
=
str
(
uuid
.
uuid4
())
lock
.
acquire
()
session
[
token
]
=
(
email
,
""
)
lock
.
release
()
# return the token in the Authorization header
response
=
make_response
(
jsonify
({}))
#"Server inserted user data into database"
...
...
@@ -195,15 +203,16 @@ def sign_out():
return
jsonify
({}),
tmp
[
1
]
# Close my socket
print
(
session
)
lock
.
acquire
(
)
try
:
session
[
token
][
1
].
close
()
except
:
pass
# samma sak som ingenting
print
(
session
)
# set user to not logged in
session
.
pop
(
token
)
try
:
session
.
pop
(
token
)
except
:
pass
lock
.
release
()
return
jsonify
({}),
204
# "Successfully signed out")
...
...
This diff is collapsed.
Click to expand it.
Lab_4/Twidder/static/client.js
+
0
−
4
View file @
418c360e
...
...
@@ -67,10 +67,6 @@ function connectWithSocket() {
switch
(
response
[
"
action
"
])
{
case
"
signOut
"
:
// If old socket open, close it.
socket
.
close
();
console
.
log
(
response
);
// Reset token in the localStorage
localStorage
.
setItem
(
"
currentUser
"
,
""
);
localStorage
.
setItem
(
"
homeEmail
"
,
""
);
...
...
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