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
1ffb3f7a
Commit
1ffb3f7a
authored
3 years ago
by
Lawrence Zawahri
Browse files
Options
Downloads
Patches
Plain Diff
lab 3 progress
parent
6a093929
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
+20
-5
20 additions, 5 deletions
Lab_3/Twidder/server.py
Lab_3/Twidder/static/client.js
+21
-14
21 additions, 14 deletions
Lab_3/Twidder/static/client.js
with
41 additions
and
19 deletions
Lab_3/Twidder/server.py
+
20
−
5
View file @
1ffb3f7a
...
...
@@ -38,8 +38,13 @@ def token_has_error(token):
def
input_has_error
(
input
):
"""
All standard input error checks
"""
# tmp = ""
# try:
# tmp = request.get_json()[input]
# except:
# return jsonify({}), 401
if
input
is
None
:
# "Server received no " + str
return
True
,
40
0
return
True
,
40
1
if
len
(
input
)
>
50
:
# "Server received too long " + str
return
True
,
400
return
False
,
0
...
...
@@ -49,11 +54,21 @@ def input_has_error(input):
def
sign_in
():
"""
Sign in user
"""
# return jsonify({}), 204
email
=
request
.
get_json
()[
'
email
'
]
password
=
request
.
get_json
()[
'
password
'
]
print
(
"
1st try
"
)
try
:
email
=
request
.
get_json
()[
'
email
'
]
print
(
request
.
get_json
()[
'
email
'
])
except
:
return
jsonify
({}),
401
print
(
"
2st try
"
)
try
:
password
=
request
.
get_json
()[
'
password
'
]
except
:
return
jsonify
({}),
401
print
(
"
3st try
"
)
# Validate Email
tmp
=
input_has_error
(
email
)
tmp
=
input_has_error
(
'
email
'
)
if
tmp
[
0
]:
return
jsonify
({}),
tmp
[
1
]
...
...
@@ -76,13 +91,13 @@ def sign_in():
# return the token in the Authorization header
response
=
make_response
(
jsonify
({}))
#"Server inserted user data into database"
response
.
headers
.
add
(
"
Access-Control-Allow-Origin
"
,
"
*
"
)
response
.
headers
[
"
Authorization
"
]
=
token
return
response
,
204
@app.route
(
"
/myServer/sign_up
"
,
methods
=
[
'
POST
'
])
def
sign_up
():
print
(
'
hello
'
)
"""
Sign up a user
"""
json_obj
=
request
.
get_json
()
...
...
This diff is collapsed.
Click to expand it.
Lab_3/Twidder/static/client.js
+
21
−
14
View file @
1ffb3f7a
...
...
@@ -102,12 +102,12 @@ function sign_up() {
//----------------//----------------//----------------//----------------
let
xhttp
=
new
XMLHttpRequest
();
//
xhttp.onreadystatechange = function () {
//
if (this.readyState == 4 && this.status == 200) {
//
// Typical action to be performed when the document is ready:
//
errorMess.innerHTML = xhttp.responseText;
//
}
//
};
xhttp
.
onreadystatechange
=
function
()
{
if
(
this
.
readyState
==
4
&&
this
.
status
==
200
)
{
// Typical action to be performed when the document is ready:
errorMess
.
innerHTML
=
xhttp
.
responseText
;
}
};
//xhttp.addEventListener("load", reqListener);
xhttp
.
open
(
"
POST
"
,
"
http://127.0.0.1:5000/myServer/sign_up
"
,
true
);
xhttp
.
setRequestHeader
(
'
Authorization
'
,
'
1f191d40-c128-477d-9f9f-196c81810f02
'
);
...
...
@@ -131,18 +131,18 @@ function sign_up() {
function
sign_in
()
{
let
form
=
document
.
getElementById
(
"
sign_in_form
"
);
let
email
=
form
[
0
].
value
;
let
password
=
form
[
1
].
value
;
let
email
Obj
=
form
[
0
].
value
;
let
password
Obj
=
form
[
1
].
value
;
let
errorMess
=
document
.
getElementById
(
"
error
"
);
// Error checks
if
(
password
.
length
<
minPassLength
)
if
(
password
Obj
.
length
<
minPassLength
)
errorMess
.
innerHTML
=
"
Password's length is too short
"
;
else
{
//Todo
// Sending sign_in request to "server"
let
signInObj
=
serverstub
.
signIn
(
email
,
password
);
let
signInObj
=
serverstub
.
signIn
(
email
Obj
,
password
Obj
);
var
signInRequest
=
new
XMLHttpRequest
();
signInRequest
.
onreadystatechange
=
function
()
{
...
...
@@ -159,7 +159,16 @@ function sign_in() {
}
};
signInRequest
.
open
(
"
POST
"
,
"
http://127.0.0.1:5000/myServer/sign_in
"
,
true
);
signInRequest
.
send
();
//signInRequest.send();
// xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
signInRequest
.
send
(
JSON
.
stringify
({
email
:
emailObj
,
password
:
passwordObj
}));
// var xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
// var theUrl = "/json-handler";
// xmlhttp.open("POST", theUrl);
// xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
// xmlhttp.send(JSON.stringify({ "email": "hello@user.com", "response": { "name": "Tester" } }));
// Set message to user
errorMess
.
innerHTML
=
signInObj
[
"
message
"
];
...
...
@@ -167,7 +176,7 @@ function sign_in() {
let
token
=
signInObj
[
"
data
"
];
localStorage
.
setItem
(
"
currentUser
"
,
token
);
localStorage
.
setItem
(
"
homeEmail
"
,
email
);
localStorage
.
setItem
(
"
homeEmail
"
,
email
Obj
);
// Changes the view to profile view an loads user info
displayView
();
...
...
@@ -196,8 +205,6 @@ function sign_out(){
}
}
// - - - - - Changing tabs - - - - - //
function
showPage
(
ourEvent
,
name
){
...
...
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