Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WebProgramming
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
Maxime Oliva
WebProgramming
Commits
f96f7159
Commit
f96f7159
authored
2 years ago
by
ComeF2
Browse files
Options
Downloads
Patches
Plain Diff
Modification HTTP request finie
parent
b42614b9
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
Twidder (Lab3)/database.db
+0
-0
0 additions, 0 deletions
Twidder (Lab3)/database.db
Twidder (Lab3)/static/client.js
+73
-52
73 additions, 52 deletions
Twidder (Lab3)/static/client.js
with
73 additions
and
52 deletions
Twidder (Lab3)/database.db
+
0
−
0
View file @
f96f7159
No preview for this file type
This diff is collapsed.
Click to expand it.
Twidder (Lab3)/static/client.js
+
73
−
52
View file @
f96f7159
...
@@ -45,25 +45,45 @@ function checkPasswords(formData){
...
@@ -45,25 +45,45 @@ function checkPasswords(formData){
}
}
function
changePassword
(
formData
)
{
function
changePassword
(
formData
)
{
let
oldPassword
=
formData
.
oldPassword
.
value
;
let
old
_
Password
=
formData
.
oldPassword
.
value
;
let
newPassword
=
formData
.
newPassword
.
value
;
let
new
_
Password
=
formData
.
newPassword
.
value
;
let
newPassword2
=
formData
.
newPassword2
.
value
;
let
new
_
Password2
=
formData
.
newPassword2
.
value
;
if
(
newPassword
.
length
<
6
)
{
if
(
new
_
Password
.
length
<
6
)
{
document
.
getElementById
(
"
pwderror
"
).
style
.
display
=
"
block
"
;
document
.
getElementById
(
"
pwderror
"
).
style
.
display
=
"
block
"
;
document
.
getElementById
(
"
pwderror
"
).
innerHTML
=
"
Your new password must be 6 characters at least.
"
;
document
.
getElementById
(
"
pwderror
"
).
innerHTML
=
"
Your new password must be 6 characters at least.
"
;
}
else
if
(
newPassword
!=
newPassword2
)
{
}
else
if
(
new
_
Password
!=
new
_
Password2
)
{
document
.
getElementById
(
"
pwderror
"
).
style
.
display
=
"
block
"
;
document
.
getElementById
(
"
pwderror
"
).
style
.
display
=
"
block
"
;
document
.
getElementById
(
"
pwderror
"
).
innerHTML
=
"
Your didn't enter the same passwords.
"
;
document
.
getElementById
(
"
pwderror
"
).
innerHTML
=
"
Your didn't enter the same passwords.
"
;
}
else
{
}
else
{
let
serverAnswer
=
serverstub
.
changePassword
(
localStorage
.
getItem
(
"
token
"
),
oldPassword
,
newPassword
);
let
value
=
{
let
success
=
serverAnswer
.
success
;
oldPassword
:
old_Password
,
let
message
=
serverAnswer
.
message
;
newPassword
:
new_Password
let
form
=
document
.
getElementById
(
"
changePassword
"
);
}
let
req
=
new
XMLHttpRequest
();
req
.
open
(
"
PUT
"
,
"
/account/change_password
"
,
true
);
req
.
setRequestHeader
(
"
Content-type
"
,
"
application/json;charset=UTF-8
"
);
req
.
setRequestHeader
(
"
token
"
,
localStorage
.
getItem
(
"
token
"
));
req
.
send
(
JSON
.
stringify
(
value
));
document
.
getElementById
(
"
pwderror
"
).
style
.
display
=
"
block
"
;
document
.
getElementById
(
"
pwderror
"
).
style
.
display
=
"
block
"
;
document
.
getElementById
(
"
pwderror
"
).
innerHTML
=
message
;
req
.
onreadystatechange
=
function
()
{
if
(
success
)
{
if
(
req
.
readyState
==
4
){
form
.
reset
();
if
(
req
.
status
==
204
){
document
.
getElementById
(
"
pwderror
"
).
innerHTML
=
"
Password changed
"
let
form
=
document
.
getElementById
(
"
changePassword
"
);
form
.
reset
();
}
else
if
(
req
.
status
==
404
){
document
.
getElementById
(
"
pwderror
"
).
innerHTML
=
"
Not found
"
}
else
if
(
req
.
status
==
403
){
document
.
getElementById
(
"
pwderror
"
).
innerHTML
=
"
Old password wrong
"
}
else
if
(
req
.
status
==
401
){
document
.
getElementById
(
"
pwderror
"
).
innerHTML
=
"
You are not online
"
}
else
if
(
req
.
status
==
405
){
document
.
getElementById
(
"
pwderror
"
).
innerHTML
=
"
Password too short. Must be 6 characters at leats.
"
}
else
if
(
req
.
status
==
400
){
document
.
getElementById
(
"
pwderror
"
).
innerHTML
=
"
Missing information
"
}
}
}
}
}
}
}
}
...
@@ -215,13 +235,17 @@ function message_management(tab){
...
@@ -215,13 +235,17 @@ function message_management(tab){
let
token
=
localStorage
.
getItem
(
"
token
"
);
let
token
=
localStorage
.
getItem
(
"
token
"
);
let
req
=
new
XMLHttpRequest
();
let
req
=
new
XMLHttpRequest
();
console
.
log
(
"
Message posté ?
"
);
req
.
open
(
"
POST
"
,
"
/account/post_message
"
,
true
);
req
.
open
(
"
POST
"
,
"
/account/post_message
"
,
true
);
req
.
setRequestHeader
(
"
Content-type
"
,
"
application/json;charset=UTF-8
"
);
req
.
setRequestHeader
(
"
Content-type
"
,
"
application/json;charset=UTF-8
"
);
req
.
setRequestHeader
(
"
token
"
,
token
);
req
.
setRequestHeader
(
"
token
"
,
token
);
req
.
send
(
JSON
.
stringify
(
value
));
req
.
send
(
JSON
.
stringify
(
value
));
req
.
onreadystatechange
=
function
(){
display_wall
(
email
,
tab
);
if
(
req
.
readyState
==
4
){
if
(
req
.
status
==
201
){
display_wall
(
email
,
tab
);
}
}
}
}
}
textaera
.
value
=
""
;
textaera
.
value
=
""
;
...
@@ -245,7 +269,11 @@ function openTab(tabName) {
...
@@ -245,7 +269,11 @@ function openTab(tabName) {
localStorage
.
setItem
(
"
tab
"
,
tabName
);
localStorage
.
setItem
(
"
tab
"
,
tabName
);
if
(
tabName
!=
"
browsePage
"
)
{
if
(
tabName
!=
"
browsePage
"
)
{
if
(
!
(
serverstub
.
getUserMessagesByEmail
(
localStorage
.
getItem
(
"
token
"
),
localStorage
.
getItem
(
"
browsed_email
"
)).
success
))
{
var
xhttp
=
new
XMLHttpRequest
();
xhttp
.
open
(
"
GET
"
,
"
/account/get/message/
"
+
localStorage
.
getItem
(
"
browsed_email
"
),
true
);
xhttp
.
setRequestHeader
(
"
token
"
,
localStorage
.
getItem
(
"
token
"
));
xhttp
.
send
();
if
(
xhttp
.
readyState
==
4
&&
xhttp
.
status
!=
204
){
localStorage
.
removeItem
(
"
browsed_email
"
);
localStorage
.
removeItem
(
"
browsed_email
"
);
}
}
}
}
...
@@ -277,67 +305,61 @@ function openTab(tabName) {
...
@@ -277,67 +305,61 @@ function openTab(tabName) {
function
display_wall_info
(
email
,
tab
)
{
function
display_wall_info
(
email
,
tab
)
{
//check if we already have the data stored of if we have to call the server
//check if we already have the data stored of if we have to call the server
let
data_user
=
get_user_info
(
email
,
tab
);
let
data_user
;
console
.
log
(
"
data_user of display_wall_info =
"
,
data_user
);
get_user_info
(
email
,
tab
,
function
(
data
){
if
(
data_user
.
success
)
{
data_user
=
data
;
if
(
tab
==
"
BP
"
)
{
if
(
data_user
.
success
)
{
if
(
tab
==
"
BP
"
)
{
browsecontent
=
document
.
getElementsByClassName
(
"
browsecontent
"
);
for
(
i
=
0
;
i
<
browsecontent
.
length
;
i
++
)
{
document
.
getElementById
(
"
browse_error
"
).
style
.
display
=
"
none
"
;
browsecontent
[
i
].
style
.
display
=
"
block
"
;
}
}
fills_data
(
tab
,
data_user
);
display_wall
(
email
,
tab
);
}
else
{
browsecontent
=
document
.
getElementsByClassName
(
"
browsecontent
"
);
browsecontent
=
document
.
getElementsByClassName
(
"
browsecontent
"
);
for
(
i
=
0
;
i
<
browsecontent
.
length
;
i
++
)
{
for
(
i
=
0
;
i
<
browsecontent
.
length
;
i
++
)
{
document
.
getElementById
(
"
browse_error
"
).
style
.
display
=
"
none
"
;
browsecontent
[
i
].
style
.
display
=
"
none
"
;
browsecontent
[
i
].
style
.
display
=
"
block
"
;
}
}
if
(
localStorage
.
getItem
(
"
browsed_email
"
)
!=
null
){
document
.
getElementById
(
"
browse_error
"
).
style
.
display
=
"
block
"
;
document
.
getElementById
(
"
browse_error
"
).
innerHTML
=
data_user
.
message
;
}
}
}
fills_data
(
tab
,
data_user
);
});
display_wall
(
email
,
tab
);
}
else
{
browsecontent
=
document
.
getElementsByClassName
(
"
browsecontent
"
);
for
(
i
=
0
;
i
<
browsecontent
.
length
;
i
++
)
{
browsecontent
[
i
].
style
.
display
=
"
none
"
;
}
document
.
getElementById
(
"
browse_error
"
).
style
.
display
=
"
block
"
;
document
.
getElementById
(
"
browse_error
"
).
innerHTML
=
data_user
.
message
;
}
}
}
function
get_user_info
(
email
,
tab
)
{
function
get_user_info
(
email
,
tab
,
callback
)
{
//call the server if data aren't already stored
//call the server if data aren't already stored
console
.
log
(
"
=================================================
"
);
console
.
log
(
"
browsed_email =
"
,
localStorage
.
getItem
(
"
browsed_email
"
));
if
((
tab
==
"
BP
"
)
&&
(
localStorage
.
getItem
(
"
browsed_email
"
)
!=
email
||
data_user_browse
==
null
))
{
if
((
tab
==
"
BP
"
)
&&
(
localStorage
.
getItem
(
"
browsed_email
"
)
!=
email
||
data_user_browse
==
null
))
{
console
.
log
(
"
Je rentre dans la boucle
"
);
//data_user_browse = serverstub.getUserDataByEmail(localStorage.getItem("token"), email);
let
req
=
new
XMLHttpRequest
();
let
req
=
new
XMLHttpRequest
();
console
.
log
(
1
);
req
.
open
(
"
GET
"
,
"
/account/get/data/
"
+
email
,
true
);
req
.
open
(
"
GET
"
,
"
/account/get/data/
"
+
email
,
true
);
console
.
log
(
2
);
req
.
setRequestHeader
(
"
token
"
,
localStorage
.
getItem
(
"
token
"
));
req
.
setRequestHeader
(
"
token
"
,
localStorage
.
getItem
(
"
token
"
));
console
.
log
(
3
);
console
.
log
(
4
);
req
.
onreadystatechange
=
function
(){
req
.
onreadystatechange
=
function
(){
console
.
log
(
5
);
if
(
req
.
readyState
==
4
){
if
(
req
.
readyState
==
4
){
console
.
log
(
6
);
if
(
req
.
status
==
200
){
if
(
req
.
status
==
200
){
data_user_browse
=
{
data_user_browse
=
{
data
:
JSON
.
parse
(
req
.
responseText
),
data
:
JSON
.
parse
(
req
.
responseText
),
success
:
true
success
:
true
};
};
callback
(
data_user_browse
);
}
else
if
(
req
.
status
==
404
){
}
else
if
(
req
.
status
==
404
){
console
.
log
(
"
Le req status est de 404
"
);
data_user_browse
=
{
data_user_browse
=
{
message
:
"
This user doesn't exist
"
,
message
:
"
This user doesn't exist
"
,
success
:
false
success
:
false
};
};
}
callback
(
data_user_browse
);
else
if
(
req
.
status
==
401
){
}
else
if
(
req
.
status
==
401
){
data_user_browse
=
{
data_user_browse
=
{
message
:
"
Problem with the server
"
,
message
:
"
Problem with the server
"
,
success
:
false
success
:
false
};
};
callback
(
data_user_browse
);
}
}
console
.
log
(
"
first data_user_browse =
"
,
data_user_browse
);
}
}
};
};
req
.
send
();
req
.
send
();
...
@@ -353,10 +375,12 @@ function get_user_info(email, tab) {
...
@@ -353,10 +375,12 @@ function get_user_info(email, tab) {
data
:
JSON
.
parse
(
req
.
responseText
),
data
:
JSON
.
parse
(
req
.
responseText
),
success
:
true
success
:
true
};
};
callback
(
data_user_home
);
}
else
if
(
req
.
status
==
404
||
req
.
status
==
401
){
}
else
if
(
req
.
status
==
404
||
req
.
status
==
401
){
data_user_home
=
{
data_user_home
=
{
success
:
false
success
:
false
};
};
callback
(
data_user_home
);
}
}
}
}
}
}
...
@@ -366,21 +390,18 @@ function get_user_info(email, tab) {
...
@@ -366,21 +390,18 @@ function get_user_info(email, tab) {
switch
(
tab
)
{
switch
(
tab
)
{
case
"
HP
"
:
case
"
HP
"
:
data_user
=
data_user_home
;
data_user
=
data_user_home
;
console
.
log
(
"
data_user_home =
"
,
data_user_home
);
break
;
break
;
default
:
default
:
data_user
=
data_user_browse
;
data_user
=
data_user_browse
;
console
.
log
(
"
data_user_browse lolololol =
"
,
data_user_browse
);
break
;
break
;
}
}
return
data_user
;
callback
(
data_user
)
;
}
}
function
display_wall
(
email
,
tab
)
{
function
display_wall
(
email
,
tab
)
{
let
messages
=
[];
let
messages
=
[];
var
xhttp
=
new
XMLHttpRequest
();
var
xhttp
=
new
XMLHttpRequest
();
console
.
log
(
"
Je suis dans display_wall
"
);
xhttp
.
open
(
"
GET
"
,
"
/account/get/message/
"
+
email
,
true
);
xhttp
.
open
(
"
GET
"
,
"
/account/get/message/
"
+
email
,
true
);
xhttp
.
setRequestHeader
(
"
token
"
,
localStorage
.
getItem
(
"
token
"
));
xhttp
.
setRequestHeader
(
"
token
"
,
localStorage
.
getItem
(
"
token
"
));
xhttp
.
onreadystatechange
=
function
()
{
xhttp
.
onreadystatechange
=
function
()
{
...
...
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