Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Hodor Web Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
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
Sachin Kamath
Hodor Web Backend
Commits
8e7c16dc
Verified
Commit
8e7c16dc
authored
7 years ago
by
Sachin Kamath
Browse files
Options
Downloads
Patches
Plain Diff
Add user endpoint to pull users
Signed-off-by:
Sachin S. Kamath
<
sskamath96@gmail.com
>
parent
a187ac33
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
hodor/controllers/user.py
+19
-9
19 additions, 9 deletions
hodor/controllers/user.py
hodor/models/user.py
+1
-0
1 addition, 0 deletions
hodor/models/user.py
with
20 additions
and
9 deletions
hodor/controllers/user.py
+
19
−
9
View file @
8e7c16dc
...
...
@@ -8,18 +8,29 @@ from sqlalchemy.exc import IntegrityError
# Get all Users
@app.route
(
'
/users
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
get_all_users
():
response
=
{}
response
[
'
status
'
]
=
200
response
[
'
data
'
]
=
[]
# TODO: Authentication for calling this API endpoint. Admin only.
"""
This function iterates the database to find all users and returns it as JSON.
:return: Response Code
"""
response
=
dict
()
response
[
'
status
'
]
=
200
response
[
'
data
'
]
=
[]
for
user
in
User
.
get_all
():
current_user
=
dict
()
'''
This can be done by directly dumping the dictionary but there
'
s always a risk of data leak.
So, we pick what we need to give out out of the API.
'''
current_user
[
'
username
'
]
=
user
.
username
current_user
[
'
first_name
'
]
=
user
.
first_name
current_user
[
'
last_name
'
]
=
user
.
last_name
current_user
[
'
email
'
]
=
user
.
email
current_user
[
'
verified_account
'
]
=
user
.
verified_account
response
[
'
data
'
].
append
(
current_user
)
for
ele
in
User
.
get_all
():
user
=
ele
.
__dict__
print
user
return
'
Work in Progress
'
return
response
@app.route
(
'
/users/new
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
...
...
@@ -37,11 +48,10 @@ def add_new_user():
newuser
[
'
last_name
'
]
=
str
(
request
.
data
.
get
(
'
last_name
'
).
strip
())
newuser
[
'
email
'
]
=
str
(
request
.
data
.
get
(
'
email
'
).
strip
())
newuser
[
'
password
'
]
=
str
(
request
.
data
.
get
(
'
password
'
).
strip
())
newuser
[
'
verification_code
'
]
=
str
(
request
.
data
.
get
(
'
verification_code
'
).
strip
())
or
newuser
[
'
verification_code
'
]
newuser
[
'
verification_code
'
]
=
str
(
request
.
data
.
get
(
'
verification_code
'
).
strip
())
except
Exception
as
e
:
print
(
e
)
abort
(
500
)
print
newuser
user
=
User
(
**
newuser
)
user
.
save
()
return
make_response
(
jsonify
(
status
=
201
,
msg
=
"
User {} successfully added to database
"
.
format
(
user
.
username
)),
201
)
...
...
This diff is collapsed.
Click to expand it.
hodor/models/user.py
+
1
−
0
View file @
8e7c16dc
...
...
@@ -12,6 +12,7 @@ class User(db.Model):
first_name
=
db
.
Column
(
db
.
String
(
32
),
nullable
=
False
)
last_name
=
db
.
Column
(
db
.
String
(
32
),
nullable
=
False
)
email
=
db
.
Column
(
db
.
String
(
64
),
unique
=
True
,
nullable
=
False
)
country
=
db
.
Column
(
db
.
String
(
64
))
'''
PasswordType is an awesome function. To check for passwords later,
you can just do user[
'
password
'
] ==
'
plaintext
'
for a boolean response.
'''
password
=
db
.
Column
(
PasswordType
(
...
...
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