Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
fa-2_exam
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
Мырзабеков Бекайдар
fa-2_exam
Commits
df6fc0e4
Commit
df6fc0e4
authored
Jan 13, 2024
by
Мырзабеков Бекайдар
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed
parent
beb6f38d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
10 deletions
+24
-10
routes.py
auth/code/routes.py
+6
-6
schemas.py
auth/code/schemas.py
+4
-0
services.py
auth/code/services.py
+13
-3
docker-compose.yml
auth/docker-compose.yml
+1
-1
No files found.
auth/code/routes.py
View file @
df6fc0e4
import
fastapi
from
fastapi.security
import
OAuth2PasswordRequestForm
from
schemas
import
CreateUserSchema
,
CreatedUserResponseSchema
,
RefreshTokenSchema
from
schemas
import
CreateUserSchema
,
CreatedUserResponseSchema
,
RefreshTokenSchema
,
AccessTokenSchema
from
ctrl
import
UserController
import
services
...
...
@@ -25,16 +25,16 @@ async def login(
return
await
services
.
auth_service
.
login
(
form_data
)
@
user_router
.
get
(
'/me
'
)
async
def
read_user_me
(
user
:
dict
=
fastapi
.
Depends
(
services
.
auth_service
.
get_current_user
)
@
auth_router
.
post
(
'/check_token
'
)
async
def
check_token
(
data
:
AccessTokenSchema
,
):
return
user
response
=
await
services
.
auth_service
.
check_token
(
data
.
token
)
return
response
@
auth_router
.
post
(
'/refresh'
)
async
def
refresh_token
(
data
:
RefreshTokenSchema
,
user
:
dict
=
fastapi
.
Depends
(
services
.
auth_service
.
get_current_user
)
):
return
services
.
token_service
.
refresh_token
(
data
.
refresh_token
)
auth/code/schemas.py
View file @
df6fc0e4
...
...
@@ -34,3 +34,7 @@ class TokenData:
class
LoginRequestModel
:
username
:
str
password
:
str
class
AccessTokenSchema
(
BaseModel
):
token
:
str
auth/code/services.py
View file @
df6fc0e4
...
...
@@ -5,6 +5,7 @@ import fastapi.security as fs
from
jose
import
jwt
,
JWTError
from
passlib.context
import
CryptContext
import
schemas
import
const
from
repository
import
UserRepository
...
...
@@ -85,9 +86,18 @@ class AuthService:
return
token_service
.
create_tokens
(
schemas
.
TokenData
(
sub
=
user
.
id
))
async
def
get_current_user
(
self
,
token
:
str
=
fa
.
Security
(
oauth2_scheme
)):
token_data
=
token_service
.
decode_token
(
token
)
return
await
self
.
user_repo
.
get
(
id
=
token_data
.
sub
)
async
def
check_token
(
self
,
token
:
str
):
try
:
token_data
=
token_service
.
decode_token
(
token
)
user
=
await
auth_service
.
user_repo
.
get
(
id
=
token_data
.
sub
)
if
user
is
None
:
return
{
'success'
:
False
}
return
{
'success'
:
True
}
except
fa
.
HTTPException
:
return
{
'success'
:
False
}
except
Exception
:
return
{
'success'
:
False
}
auth_service
=
AuthService
()
auth/docker-compose.yml
View file @
df6fc0e4
...
...
@@ -16,7 +16,7 @@ services:
-
.env
command
:
bash -c "python3 code/main.py"
db
:
auth-
db
:
image
:
postgres:14-alpine
container_name
:
auth-pg
env_file
:
...
...
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