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
Show 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
import
fastapi
from
fastapi.security
import
OAuth2PasswordRequestForm
from
fastapi.security
import
OAuth2PasswordRequestForm
from
schemas
import
CreateUserSchema
,
CreatedUserResponseSchema
,
RefreshTokenSchema
from
schemas
import
CreateUserSchema
,
CreatedUserResponseSchema
,
RefreshTokenSchema
,
AccessTokenSchema
from
ctrl
import
UserController
from
ctrl
import
UserController
import
services
import
services
...
@@ -25,16 +25,16 @@ async def login(
...
@@ -25,16 +25,16 @@ async def login(
return
await
services
.
auth_service
.
login
(
form_data
)
return
await
services
.
auth_service
.
login
(
form_data
)
@
user_router
.
get
(
'/me
'
)
@
auth_router
.
post
(
'/check_token
'
)
async
def
read_user_me
(
async
def
check_token
(
user
:
dict
=
fastapi
.
Depends
(
services
.
auth_service
.
get_current_user
)
data
:
AccessTokenSchema
,
):
):
return
user
response
=
await
services
.
auth_service
.
check_token
(
data
.
token
)
return
response
@
auth_router
.
post
(
'/refresh'
)
@
auth_router
.
post
(
'/refresh'
)
async
def
refresh_token
(
async
def
refresh_token
(
data
:
RefreshTokenSchema
,
data
:
RefreshTokenSchema
,
user
:
dict
=
fastapi
.
Depends
(
services
.
auth_service
.
get_current_user
)
):
):
return
services
.
token_service
.
refresh_token
(
data
.
refresh_token
)
return
services
.
token_service
.
refresh_token
(
data
.
refresh_token
)
auth/code/schemas.py
View file @
df6fc0e4
...
@@ -34,3 +34,7 @@ class TokenData:
...
@@ -34,3 +34,7 @@ class TokenData:
class
LoginRequestModel
:
class
LoginRequestModel
:
username
:
str
username
:
str
password
:
str
password
:
str
class
AccessTokenSchema
(
BaseModel
):
token
:
str
auth/code/services.py
View file @
df6fc0e4
...
@@ -5,6 +5,7 @@ import fastapi.security as fs
...
@@ -5,6 +5,7 @@ import fastapi.security as fs
from
jose
import
jwt
,
JWTError
from
jose
import
jwt
,
JWTError
from
passlib.context
import
CryptContext
from
passlib.context
import
CryptContext
import
schemas
import
schemas
import
const
import
const
from
repository
import
UserRepository
from
repository
import
UserRepository
...
@@ -85,9 +86,18 @@ class AuthService:
...
@@ -85,9 +86,18 @@ class AuthService:
return
token_service
.
create_tokens
(
schemas
.
TokenData
(
sub
=
user
.
id
))
return
token_service
.
create_tokens
(
schemas
.
TokenData
(
sub
=
user
.
id
))
async
def
get_current_user
(
self
,
token
:
str
=
fa
.
Security
(
oauth2_scheme
)):
async
def
check_token
(
self
,
token
:
str
):
try
:
token_data
=
token_service
.
decode_token
(
token
)
token_data
=
token_service
.
decode_token
(
token
)
return
await
self
.
user_repo
.
get
(
id
=
token_data
.
sub
)
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_service
=
AuthService
()
auth/docker-compose.yml
View file @
df6fc0e4
...
@@ -16,7 +16,7 @@ services:
...
@@ -16,7 +16,7 @@ services:
-
.env
-
.env
command
:
bash -c "python3 code/main.py"
command
:
bash -c "python3 code/main.py"
db
:
auth-
db
:
image
:
postgres:14-alpine
image
:
postgres:14-alpine
container_name
:
auth-pg
container_name
:
auth-pg
env_file
:
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