Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TJTS5901 K23 Template
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Startuplab
Courses
TJTS5901 Continuous Software Engineering
TJTS5901 K23 Template
Commits
65726025
Commit
65726025
authored
2 years ago
by
Teemu Autto
Browse files
Options
Downloads
Patches
Plain Diff
Helper function to retrieve user by email.
parent
5de4b295
No related branches found
Branches containing commit
No related tags found
1 merge request
!70
Tokens
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/tjts5901/auth.py
+25
-3
25 additions, 3 deletions
src/tjts5901/auth.py
with
25 additions
and
3 deletions
src/tjts5901/auth.py
+
25
−
3
View file @
65726025
...
...
@@ -52,6 +52,30 @@ def load_logged_in_user(user_id):
return
user
def
get_user_by_email
(
email
:
str
)
->
User
:
"""
Get a user from the database, given the user
'
s email.
If the email is
'
me
'
, then the current user is returned.
:param email: The email of the user to get.
"""
if
email
is
None
:
abort
(
404
)
if
email
==
"
me
"
and
current_user
.
is_authenticated
:
email
=
current_user
.
email
try
:
user
=
User
.
objects
.
get_or_404
(
email
=
email
)
except
DoesNotExist
:
logger
.
error
(
"
User not found: %s
"
,
email
)
abort
(
404
)
return
user
@bp.route
(
'
/register
'
,
methods
=
(
'
GET
'
,
'
POST
'
))
def
register
():
if
request
.
method
==
'
POST
'
:
...
...
@@ -152,10 +176,8 @@ def profile(email):
If the email is
'
me
'
, then the current user
'
s profile is shown.
"""
if
email
==
'
me
'
:
email
=
current_user
.
email
user
:
User
=
User
.
objects
.
get_or_404
(
email
=
email
)
user
:
User
=
get_user_by_
email
(
email
)
# List the items user has created
items
=
Item
.
objects
(
seller
=
user
).
all
()
...
...
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