Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
pymongo
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
docker101
pymongo
Commits
bee39955
Commit
bee39955
authored
Sep 01, 2019
by
Ahmad Anvari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add auth middleware
parent
6bb0e5e3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
auth.py
middlewares/auth.py
+13
-2
No files found.
middlewares/auth.py
View file @
bee39955
from
functools
import
wraps
from
functools
import
wraps
from
flask
import
g
,
request
,
redirect
,
url_for
from
flask
import
g
,
request
from
utils.jwt
import
decode_jwt
from
db.user
import
User
from
flask
import
jsonify
def
login_required
(
f
):
def
login_required
(
f
):
@
wraps
(
f
)
@
wraps
(
f
)
def
decorated_function
(
*
args
,
**
kwargs
):
def
decorated_function
(
*
args
,
**
kwargs
):
auth
=
request
.
headers
.
get
(
'Authorization'
)
auth
=
request
.
headers
.
get
(
'Authorization'
)
print
(
auth
)
token
=
auth
.
split
(
' '
)[
1
]
try
:
payload
=
decode_jwt
(
token
)
user
=
User
.
find_by_id
(
payload
[
'user_id'
])
if
user
is
None
:
return
jsonify
({
"Error"
:
"Not authorized"
}),
401
g
.
user
=
user
except
:
return
jsonify
({
"Error"
:
"Not authorized"
}),
401
return
f
(
*
args
,
**
kwargs
)
return
f
(
*
args
,
**
kwargs
)
return
decorated_function
return
decorated_function
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment