Spaces:
Sleeping
Sleeping
File size: 2,819 Bytes
13ba451 |
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 |
from fastapi import APIRouter, Query
from request import RequestAuth
from response import ResponseAuth as res
from service import AuthService
from function import support_function
from fastapi import HTTPException
router = APIRouter()
@router.post('/login', tags=["Authentication"])
async def login(request: RequestAuth.RequestLoginEmail):
email = request.email
check = support_function.check_value_email_controller(email)
if check is not True:
return check
password = request.password
if password is None or password.strip() == "":
return res.ReponseError(status=400,
data=res.Message(message="Password is required."))
return await AuthService.login(request)
@router.post('/login_google', tags=["Authentication"])
async def login_google(request: RequestAuth.RequestLoginGoogle):
email = request.email
token_google = request.token_google
check = support_function.check_value_email_controller(email)
if check is not True:
return check
if token_google is None or token_google.strip() == "":
return res.ReponseError(status=400,
data=res.Message(message="token_google oauth2 is required."))
if token_google.isdigit():
return res.ReponseError(status=400,
data=res.Message(message="token_google must be a string, not a number."))
return await AuthService.login_google(request)
@router.post('/sign_up', tags=["Authentication"])
async def signup(request: RequestAuth.RequestRegister):
email = request.email
check = support_function.check_value_email_controller(email)
if check is not True:
return check
password = request.password
confirm_password = request.confirm_password
if password is None or password.strip( )== "":
return res.ReponseError(status=400,
data=res.Message(message="Password is required."))
if confirm_password is None or confirm_password.strip() == "":
return res.ReponseError(status=400,
data=res.Message(message="Confirm Password is required."))
return await AuthService.sign_up(request)
@router.post('/refresh_token', tags=["Authentication"])
async def refresh_token_account(request: RequestAuth.RequestRefreshTokenLogin):
token = request.refresh_token
if token is None or token.strip() == "":
return res.ReponseError(status=400,
data=res.Message(message="token is required."))
elif token.isdigit():
return res.ReponseError(status=400,
data=res.Message(message="token must be string"))
return await AuthService.refresh_token(request) |