Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDDD97-Webprog
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
Oliver Green
TDDD97-Webprog
Commits
7381e820
Commit
7381e820
authored
2 years ago
by
Gustav Elmqvist
Browse files
Options
Downloads
Patches
Plain Diff
sign_in and and sign_up might be complete
parent
807741fc
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
lab2/server.py
+20
-30
20 additions, 30 deletions
lab2/server.py
with
20 additions
and
30 deletions
lab2/server.py
+
20
−
30
View file @
7381e820
...
...
@@ -16,41 +16,30 @@ def index():
@app.route
(
'
/signin
'
,
methods
=
[
'
POST
'
])
def
sign_in
(
email
=
'
test@gmail.com
'
,
password
=
'
123123123
'
):
def
sign_in
():
"""
Authenticate the username by the provided password.
"""
args
=
request
.
get_json
()
if
set
(
args
)
!=
{
'
email
'
,
'
password
'
,
'
firstname
'
,
'
familyname
'
,
'
gender
'
,
'
city
'
,
'
country
'
}:
if
set
(
args
)
!=
{
'
email
'
,
'
password
'
}:
return
{
"
success
"
:
"
false
"
,
"
message
"
:
"
Form data missing or incorrect type.
"
}
if
re
.
fullmatch
(
r
'
\w+@\w+.\w+
'
,
args
[
'
email
'
])
is
None
:
return
False
if
len
(
args
[
'
password
'
])
<
8
:
return
False
pw_hash
=
hashlib
.
sha256
((
args
[
'
password
'
]
+
args
[
'
email
'
]).
encode
()).
hexdigest
()
# TODO: test if empty email and password will sign in
if
pw_hash
!=
dbh
.
get_password
(
args
[
'
email
'
]):
return
{
"
success
"
:
"
false
"
,
"
message
"
:
"
Wrong username or password.
"
}
email
=
args
[
'
email
'
]
password
=
args
[
'
password
'
]
letters
=
"
abcdefghiklmnopqrstuvwwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
"
token
=
''
.
join
(
letters
[
random
.
randint
(
0
,
len
(
letters
)
-
1
)]
for
_
in
range
(
36
))
hashed_password
=
hashlib
.
sha256
((
password
+
email
).
encode
()).
hexdigest
(
)
dbh
.
update_logged_in_users
(
args
[
'
email
'
],
token
)
database_password
=
dbh
.
get_password
(
email
)
return
{
"
success
"
:
"
true
"
,
"
message
"
:
"
Successfully signed in.
"
,
"
data
"
:
token
}
if
hashed_password
==
database_password
:
letters
=
"
abcdefghiklmnopqrstuvwwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
"
token
=
''
.
join
(
letters
[
random
.
randint
(
0
,
len
(
letters
)
-
1
)]
for
_
in
range
(
36
))
# syncStorage();
# if(users[email] != null && users[email].password == password){
# loggedInUsers[token] = email;
# persistLoggedInUsers();
return
{
"
success
"
:
"
true
"
,
"
message
"
:
"
Successfully signed in.
"
,
"
data
"
:
token
}
return
{
"
success
"
:
"
false
"
,
"
message
"
:
"
Wrong username or password.
"
}
@app.route
(
'
/signup
'
,
methods
=
[
'
POST
'
])
def
sign_up
():
...
...
@@ -59,6 +48,14 @@ def sign_up():
"""
args
=
request
.
get_json
()
if
set
(
args
)
!=
{
'
email
'
,
'
password
'
,
'
firstname
'
,
'
familyname
'
,
'
gender
'
,
'
city
'
,
'
country
'
}:
return
{
"
success
"
:
"
false
"
,
"
message
"
:
"
Form data missing or incorrect type.
"
}
if
re
.
fullmatch
(
r
'
\w+@\w+.\w+
'
,
args
[
'
email
'
])
is
None
:
return
{
"
success
"
:
"
false
"
,
"
message
"
:
"
Invalid email address.
"
}
if
len
(
args
[
'
password
'
])
<
8
:
return
{
"
success
"
:
"
false
"
,
"
message
"
:
"
Password needs to be at least 8 characters long.
"
}
if
dbh
.
get_user_data
(
args
[
'
email
'
])
is
not
None
:
return
{
"
success
"
:
"
false
"
,
"
message
"
:
"
User already exists.
"
}
...
...
@@ -69,19 +66,12 @@ def sign_up():
args
[
'
email
'
],
pw_hash
,
args
[
'
firstname
'
],
args
[
'
last
name
'
],
args
[
'
family
name
'
],
args
[
'
gender
'
],
args
[
'
city
'
],
args
[
'
country
'
],
)
return
{
"
success
"
:
"
true
"
,
"
message
"
:
"
Successfully created a new user.
"
};
}
else
{
}
}
else
{
}
pass
return
{
"
success
"
:
"
true
"
,
"
message
"
:
"
Successfully created a new user.
"
}
def
sign_out
(
token
):
...
...
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