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
19bb88c3
Commit
19bb88c3
authored
3 years ago
by
Johan Thörnblom
Browse files
Options
Downloads
Patches
Plain Diff
refresh problem
parent
6ac1a6b4
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_3/Twidder/server.py
+1
-0
1 addition, 0 deletions
Lab_3/Twidder/server.py
Lab_3/Twidder/static/client.js
+22
-14
22 additions, 14 deletions
Lab_3/Twidder/static/client.js
with
23 additions
and
14 deletions
Lab_3/Twidder/server.py
+
1
−
0
View file @
19bb88c3
...
...
@@ -100,6 +100,7 @@ def echo(socket):
# Put socket in global dict so server knows my connection is open
signedInUser
[
myEmail
]
=
socket
print
(
signedInUser
)
socket
.
send
(
json
.
dumps
({
"
action
"
:
"
signIn
"
}))
...
...
This diff is collapsed.
Click to expand it.
Lab_3/Twidder/static/client.js
+
22
−
14
View file @
19bb88c3
...
...
@@ -14,11 +14,16 @@ function connectWithSocket() {
let
token
=
localStorage
.
getItem
(
"
currentUser
"
);
// Changes the view to profile view and loads user info
document
.
getElementById
(
"
error
"
).
innerHTML
=
"
You are signed in
"
;
//
document.getElementById("error").innerHTML = "You are signed in";
displayView
();
setUserDetails
(
"
home
"
);
// Establish web socket
// if (socket.readyState !== WebSocket.CLOSED) {
// socket.close();
// }
// socket.close();
socket
=
new
WebSocket
(
'
ws://
'
+
document
.
domain
+
'
:5000/myServer/api
'
);
socket
.
onopen
=
function
(
event
)
{
let
myEmail
=
localStorage
.
getItem
(
"
homeEmail
"
);
...
...
@@ -33,8 +38,9 @@ function connectWithSocket() {
console
.
log
(
"
Nu fick jag svar
"
);
switch
(
response
[
"
action
"
])
{
case
"
signOut
"
:
socket
.
close
();
console
.
log
(
response
);
// hej
// Reset token in the localStorage
localStorage
.
setItem
(
"
currentUser
"
,
""
);
localStorage
.
setItem
(
"
homeEmail
"
,
""
);
...
...
@@ -351,9 +357,9 @@ displayView = function(){
window
.
onload
=
function
()
{
// Delete when done - används för att hoppa tillbaka till rtt view under utveckling
localStorage
.
setItem
(
"
currentUser
"
,
""
);
localStorage
.
setItem
(
"
homeEmail
"
,
""
);
localStorage
.
setItem
(
"
browseEmail
"
,
""
);
//
localStorage.setItem("currentUser", "");
//
localStorage.setItem("homeEmail", "");
//
localStorage.setItem("browseEmail", "");
// All key/value pairs stored in out localStorage
// If first time? check this:
...
...
@@ -364,21 +370,23 @@ window.onload = function () {
if
(
localStorage
.
getItem
(
"
currentUser
"
)
==
null
)
localStorage
.
setItem
(
"
currentUser
"
,
""
);
// Todo - problem
if
(
localStorage
.
getItem
(
"
currentUser
"
)
!=
""
)
connectWithSocket
();
// Initialize div objects (global variables)
welcomeDiv
=
document
.
getElementById
(
"
welcomeview
"
);
profileDiv
=
document
.
getElementById
(
"
profileview
"
);
windowDiv
=
document
.
getElementById
(
"
windowDiv
"
);
if
(
localStorage
.
getItem
(
"
currentUser
"
)
!=
""
)
{
//if logged in
connectWithSocket
();
}
else
{
// Set correct view depending on if someone is signed in or not
displayView
();
// Set correct view depending on if someone is signed in or not
displayView
();
// Load user details to home page and browse page
// setUserDetails("home");
// setUserDetails("browse");
}
// Load user details to home page and browse page
setUserDetails
(
"
home
"
);
setUserDetails
(
"
browse
"
);
};
// Function for setting user details, either for yourself or for some other user
...
...
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