Compare commits
2 Commits
d10f32519e
...
239fa59d09
Author | SHA1 | Date |
---|---|---|
|
239fa59d09 | |
|
6030d8edd9 |
src/routers
|
@ -5,3 +5,4 @@
|
|||
__pycache__
|
||||
**/__pycache__
|
||||
static/temp/
|
||||
static/chat/
|
|
@ -6,6 +6,7 @@ from pydantic import BaseModel
|
|||
from jose import ExpiredSignatureError, JWTError
|
||||
|
||||
from ..crud.user_crud import select_account_by
|
||||
from ..utils.email_code import verify_code
|
||||
from ..utils.password import verify_password
|
||||
from ..utils.token_handler import (
|
||||
create_signin_token,
|
||||
|
@ -30,6 +31,7 @@ class TokenPayload(BaseModel):
|
|||
async def signin_by_username(form_data: OAuth2PasswordRequestForm = Depends()):
|
||||
username = form_data.username
|
||||
password = form_data.password
|
||||
|
||||
is_existence, user = await select_account_by("username", username)
|
||||
|
||||
if not is_existence:
|
||||
|
@ -43,6 +45,24 @@ async def signin_by_username(form_data: OAuth2PasswordRequestForm = Depends()):
|
|||
return {"code": 10201, "msg": "Username or Password Is Incorrect"}
|
||||
|
||||
|
||||
@router.post("/email", response_model=UserAccountResponse)
|
||||
async def signin_by_email(form_data: OAuth2PasswordRequestForm = Depends()):
|
||||
email = form_data.username
|
||||
code = form_data.password
|
||||
|
||||
is_existence, user = await select_account_by("email", email)
|
||||
|
||||
if not is_existence:
|
||||
return {"code": 10202, "msg": "The Email Has Not Been Registered"}
|
||||
|
||||
is_correct = verify_code(email, code)
|
||||
|
||||
if is_correct:
|
||||
return {"code": 10200, "msg": "Sign in Successfully", "data": user.to_dict()}
|
||||
else:
|
||||
return {"code": 10201, "msg": "The Verification Code Is Not Correct"}
|
||||
|
||||
|
||||
@router.post("/token", response_model=TokenCreationResponse)
|
||||
async def create_token(token_payload: TokenPayload):
|
||||
token = create_signin_token(**token_payload.model_dump())
|
||||
|
|
Loading…
Reference in New Issue