Compare commits

..

2 Commits

Author SHA1 Message Date
htylight 239fa59d09 email signin 2024-04-09 16:59:14 +08:00
htylight 6030d8edd9 email signin 2024-04-09 16:58:30 +08:00
2 changed files with 22 additions and 1 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
__pycache__
**/__pycache__
static/temp/
static/chat/

View File

@ -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())