-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
101 lines (83 loc) · 3.35 KB
/
Copy pathviews.py
File metadata and controls
101 lines (83 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from typing import Annotated
from fastapi import APIRouter
from fastapi import Depends
from fastapi import Security
from fastapi.security import HTTPAuthorizationCredentials
from fastapi.security import HTTPBearer
from wacruit.src.apps.auth.exceptions import EmailConflictException
from wacruit.src.apps.auth.exceptions import ExpiredPasswordResetCodeException
from wacruit.src.apps.auth.exceptions import InvalidPasswordResetCodeException
from wacruit.src.apps.auth.exceptions import PasswordResetCodeNotVerifiedException
from wacruit.src.apps.auth.exceptions import UserNotFoundException
from wacruit.src.apps.auth.schemas import LoginRequest
from wacruit.src.apps.auth.schemas import PasswordResetEmailRequest
from wacruit.src.apps.auth.schemas import PasswordResetRequest
from wacruit.src.apps.auth.schemas import PasswordResetVerifyRequest
from wacruit.src.apps.auth.schemas import TokenResponse
from wacruit.src.apps.auth.schemas import UserCheckRequest
from wacruit.src.apps.auth.services import AuthService
from wacruit.src.apps.common.exceptions import responses_from
from wacruit.src.apps.mail.exceptions import MailConfigException
from wacruit.src.apps.mail.exceptions import MailSendFailedException
v3_router = APIRouter(prefix="/v3/auth", tags=["auth"])
security = HTTPBearer(
scheme_name="refresh_token", description="토큰 갱신을 위한 Bearer 토큰"
)
@v3_router.post("/login")
def login(
req: LoginRequest, auth_service: Annotated[AuthService, Depends()]
) -> TokenResponse:
res = auth_service.login(req.email, req.password)
return TokenResponse(access_token=res[0], refresh_token=res[1])
@v3_router.post("/refresh")
def refresh_token(
refresh_credentials: Annotated[HTTPAuthorizationCredentials, Security(security)],
auth_service: Annotated[AuthService, Depends()],
) -> TokenResponse:
res = auth_service.refresh_token(refresh_credentials.credentials)
return TokenResponse(access_token=res[0], refresh_token=res[1])
@v3_router.post("/check", status_code=200)
def check_available_email(
req: UserCheckRequest, auth_service: Annotated[AuthService, Depends()]
) -> None:
res = auth_service.check_available_email(req.email)
if not res:
raise EmailConflictException()
@v3_router.post(
"/password-reset/email",
status_code=200,
responses=responses_from(MailConfigException, MailSendFailedException),
)
def send_password_reset_email(
req: PasswordResetEmailRequest,
auth_service: Annotated[AuthService, Depends()],
) -> None:
auth_service.send_password_reset_email(req.email)
@v3_router.post(
"/password-reset/verify",
status_code=200,
responses=responses_from(
InvalidPasswordResetCodeException,
ExpiredPasswordResetCodeException,
),
)
def verify_password_reset_code(
req: PasswordResetVerifyRequest,
auth_service: Annotated[AuthService, Depends()],
) -> None:
auth_service.verify_password_reset_code(req.email, req.code)
@v3_router.post(
"/password-reset",
status_code=200,
responses=responses_from(
InvalidPasswordResetCodeException,
ExpiredPasswordResetCodeException,
PasswordResetCodeNotVerifiedException,
UserNotFoundException,
),
)
def reset_password(
req: PasswordResetRequest,
auth_service: Annotated[AuthService, Depends()],
) -> None:
auth_service.reset_password(req.email, req.code, req.new_password)