Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
siibra-explorer
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xiao Gui
siibra-explorer
Commits
b3cb95d2
Commit
b3cb95d2
authored
1 year ago
by
Xiao Gui
Browse files
Options
Downloads
Patches
Plain Diff
fix: namespace
parent
48dd393f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
backend/app/user.py
+5
-11
5 additions, 11 deletions
backend/app/user.py
with
5 additions
and
11 deletions
backend/app/user.py
+
5
−
11
View file @
b3cb95d2
from
typing
import
Any
,
Coroutine
from
starlette.requests
import
Request
from
starlette.responses
import
Response
from
fastapi
import
FastAPI
,
APIRouter
from
fastapi
import
APIRouter
from
functools
import
wraps
from
inspect
import
iscoroutine
...
...
@@ -11,7 +10,7 @@ from .auth import _store
class
NotAuthenticatedEx
(
Exception
):
...
def
get_user
(
request
:
Request
):
def
get_user
_from_request
(
request
:
Request
):
if
PROFILE_KEY
not
in
request
.
session
:
return
None
...
...
@@ -23,7 +22,7 @@ def get_user(request: Request):
def
is_authenticated
(
fn
):
@wraps
(
fn
)
async
def
async_wrapper
(
*
args
,
request
:
Request
,
**
kwargs
):
user
=
get_user
(
request
)
user
=
get_user
_from_request
(
request
)
if
not
user
:
return
Response
(
"
Not authenticated
"
,
401
)
request
.
state
.
user
=
user
...
...
@@ -31,7 +30,7 @@ def is_authenticated(fn):
@wraps
(
fn
)
def
sync_wrapper
(
*
args
,
request
:
Request
,
**
kwargs
):
user
=
get_user
(
request
)
user
=
get_user
_from_request
(
request
)
if
not
user
:
return
Response
(
"
Not authenticated
"
,
401
)
request
.
state
.
user
=
user
...
...
@@ -41,15 +40,10 @@ def is_authenticated(fn):
router
=
APIRouter
()
@router.get
(
"
/foo
"
)
@is_authenticated
def
foo
(
request
:
Request
):
return
"
foo
"
@router.get
(
""
)
@router.get
(
"
/
"
)
@is_authenticated
def
get_user
(
request
:
Request
):
def
route_
get_user
(
request
:
Request
):
try
:
user
=
request
.
state
.
user
if
user
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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