Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
teknikattan-scoring-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
tddd96-grupp1
teknikattan-scoring-system
Commits
ecfea952
Commit
ecfea952
authored
4 years ago
by
robban64
Browse files
Options
Downloads
Patches
Plain Diff
add: JWT-token for login code
parent
e1211e0a
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!102
Resolve "Add presentation authorization"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
server/app/apis/__init__.py
+9
-4
9 additions, 4 deletions
server/app/apis/__init__.py
server/app/apis/auth.py
+14
-1
14 additions, 1 deletion
server/app/apis/auth.py
server/app/database/models.py
+2
-1
2 additions, 1 deletion
server/app/database/models.py
with
25 additions
and
6 deletions
server/app/apis/__init__.py
+
9
−
4
View file @
ecfea952
...
@@ -21,14 +21,19 @@ def check_jwt(editor=False, *views):
...
@@ -21,14 +21,19 @@ def check_jwt(editor=False, *views):
claims
=
get_jwt_claims
()
claims
=
get_jwt_claims
()
role
=
claims
.
get
(
"
role
"
)
role
=
claims
.
get
(
"
role
"
)
view
=
claims
.
get
(
"
view
"
)
view
=
claims
.
get
(
"
view
"
)
competition_id
=
claims
.
get
(
"
competition_id
"
)
competition_id_args
=
kwargs
.
get
(
"
competition_id
"
)
if
role
==
"
Admin
"
:
if
role
==
"
Admin
"
:
return
fn
(
*
args
,
**
kwargs
)
return
fn
(
*
args
,
**
kwargs
)
elif
editor
and
role
==
"
Editor
"
:
elif
editor
and
role
==
"
Editor
"
:
return
fn
(
*
args
,
**
kwargs
)
return
fn
(
*
args
,
**
kwargs
)
elif
view
in
views
:
return
fn
(
*
args
,
**
kwargs
)
if
competition_id_args
and
view
in
views
:
else
:
if
competition_id
==
competition_id_args
:
abort
(
http_codes
.
UNAUTHORIZED
)
return
fn
(
*
args
,
**
kwargs
)
abort
(
http_codes
.
UNAUTHORIZED
)
return
decorator
return
decorator
...
...
This diff is collapsed.
Click to expand it.
server/app/apis/auth.py
+
14
−
1
View file @
ecfea952
...
@@ -33,6 +33,10 @@ def get_user_claims(item_user):
...
@@ -33,6 +33,10 @@ def get_user_claims(item_user):
return
{
"
role
"
:
item_user
.
role
.
name
,
"
city_id
"
:
item_user
.
city_id
}
return
{
"
role
"
:
item_user
.
role
.
name
,
"
city_id
"
:
item_user
.
city_id
}
def
get_code_claims
(
item_code
):
return
{
"
view
"
:
item_code
.
view_type
.
name
,
"
competition_id
"
:
item_code
.
competition_id
}
@api.route
(
"
/signup
"
)
@api.route
(
"
/signup
"
)
class
AuthSignup
(
Resource
):
class
AuthSignup
(
Resource
):
@check_jwt
(
editor
=
False
)
@check_jwt
(
editor
=
False
)
...
@@ -89,7 +93,16 @@ class AuthLoginCode(Resource):
...
@@ -89,7 +93,16 @@ class AuthLoginCode(Resource):
api
.
abort
(
codes
.
BAD_REQUEST
,
"
Invalid code
"
)
api
.
abort
(
codes
.
BAD_REQUEST
,
"
Invalid code
"
)
item_code
=
dbc
.
get
.
code_by_code
(
code
)
item_code
=
dbc
.
get
.
code_by_code
(
code
)
return
item_response
(
CodeDTO
.
schema
.
dump
(
item_code
))
access_token
=
create_access_token
(
item_code
.
id
,
user_claims
=
get_code_claims
(
item_code
))
response
=
{
"
competition_id
"
:
item_code
.
competition_id
,
"
view_type_id
"
:
item_code
.
view_type_id
,
"
team_id
"
:
item_code
.
team_id
,
"
access_token
"
:
access_token
,
}
return
response
@api.route
(
"
/logout
"
)
@api.route
(
"
/logout
"
)
...
...
This diff is collapsed.
Click to expand it.
server/app/database/models.py
+
2
−
1
View file @
ecfea952
...
@@ -230,6 +230,8 @@ class Code(db.Model):
...
@@ -230,6 +230,8 @@ class Code(db.Model):
competition_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
competition.id
"
),
nullable
=
False
)
competition_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
competition.id
"
),
nullable
=
False
)
team_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
team.id
"
),
nullable
=
True
)
team_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
team.id
"
),
nullable
=
True
)
view_type
=
db
.
relationship
(
"
ViewType
"
,
uselist
=
False
)
def
__init__
(
self
,
code
,
view_type_id
,
competition_id
=
None
,
team_id
=
None
):
def
__init__
(
self
,
code
,
view_type_id
,
competition_id
=
None
,
team_id
=
None
):
self
.
code
=
code
self
.
code
=
code
self
.
view_type_id
=
view_type_id
self
.
view_type_id
=
view_type_id
...
@@ -240,7 +242,6 @@ class Code(db.Model):
...
@@ -240,7 +242,6 @@ class Code(db.Model):
class
ViewType
(
db
.
Model
):
class
ViewType
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
name
=
db
.
Column
(
db
.
String
(
STRING_SIZE
),
unique
=
True
)
name
=
db
.
Column
(
db
.
String
(
STRING_SIZE
),
unique
=
True
)
codes
=
db
.
relationship
(
"
Code
"
,
backref
=
"
view_type
"
)
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
name
=
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