Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Salamander - API
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Herman Andersen Dyrkorn
Salamander - API
Commits
fdf339c2
Commit
fdf339c2
authored
4 years ago
by
Herman Andersen Dyrkorn
Browse files
Options
Downloads
Plain Diff
Merge branch '9-register-location-endpoint' into 'master'
Resolve "register location endpoint" Closes
#9
See merge request
!12
parents
1bfd2fe1
179f87b8
No related branches found
No related tags found
1 merge request
!12
Resolve "register location endpoint"
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/database/database.db
+0
-0
0 additions, 0 deletions
api/database/database.db
api/endpoints/registerlocation.py
+6
-2
6 additions, 2 deletions
api/endpoints/registerlocation.py
api/endpoints/registeruser.py
+4
-2
4 additions, 2 deletions
api/endpoints/registeruser.py
with
10 additions
and
4 deletions
api/database/database.db
+
0
−
0
View file @
fdf339c2
No preview for this file type
This diff is collapsed.
Click to expand it.
api/endpoints/registerlocation.py
+
6
−
2
View file @
fdf339c2
...
...
@@ -3,6 +3,10 @@ from flask_restful import Resource
from
flask_jwt_extended
import
jwt_required
from
api
import
db
from
api.models.dbmodels
import
Location
import
re
COORDINATES_REGEX
=
"
^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$
"
# findSalamanderInfo endpoint
...
...
@@ -13,12 +17,12 @@ class RegisterLocation(Resource):
data
=
request
.
form
if
"
coordinates
"
in
data
and
"
name
"
in
data
and
"
radius
"
in
data
:
location
=
db
.
session
.
query
(
Location
).
filter_by
(
name
=
data
[
'
name
'
]).
first
()
if
not
location
:
if
not
location
and
re
.
search
(
COORDINATES_REGEX
,
data
[
'
coordinates
'
])
:
new_location
=
Location
(
name
=
data
[
'
name
'
],
coordinates
=
data
[
'
coordinates
'
],
radius
=
data
[
'
radius
'
])
db
.
session
.
add
(
new_location
)
db
.
session
.
commit
()
return
jsonify
({
"
message
"
:
"
new location registered
"
})
else
:
return
jsonify
({
"
message
"
:
"
this location name already in use
"
})
return
jsonify
({
"
message
"
:
"
this location name already in use
or bad coordinates
"
})
else
:
return
jsonify
({
"
message
"
:
"
wrong data
"
})
This diff is collapsed.
Click to expand it.
api/endpoints/registeruser.py
+
4
−
2
View file @
fdf339c2
...
...
@@ -5,15 +5,17 @@ from api import bcrypt, db
import
re
EMAIL_REGEX
=
"
^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$
"
class
RegisterUser
(
Resource
):
@staticmethod
def
post
():
data
=
request
.
form
if
data
[
'
name
'
]
or
data
[
'
email
'
]
or
data
[
'
password
'
]
or
data
[
'
confirmPassword
'
]:
if
data
[
'
password
'
]
==
data
[
'
confirmPassword
'
]:
email_regex
=
"
^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$
"
user
=
db
.
session
.
query
(
User
).
filter_by
(
email
=
data
[
'
email
'
]).
first
()
if
not
user
and
re
.
search
(
email_regex
,
data
[
'
email
'
]):
if
not
user
and
re
.
search
(
EMAIL_REGEX
,
data
[
'
email
'
]):
password_hash
=
bcrypt
.
generate_password_hash
(
data
[
'
password
'
])
new_user
=
User
(
name
=
data
[
'
name
'
],
email
=
data
[
'
email
'
],
pwd
=
password_hash
)
db
.
session
.
add
(
new_user
)
...
...
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