freeleaps-service-hub/apps/authentication/webapi/routes/signin/try_signin_with_email.py
2024-10-30 08:44:37 -07:00

39 lines
1.1 KiB
Python

from backend.application.signin_hub import SignInHub
from pydantic import BaseModel
from fastapi import APIRouter
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
router = APIRouter()
# Web API
# try_signin_with_email
#
class UserSignWithEmailBody(BaseModel):
email: str
host: str
class UserSignWithEmailResponse(BaseModel):
signin_type: int
@router.post(
"/try-signin-with-email",
operation_id="user-try-signin-with-email",
summary="try to signin with email",
description="A client user is trying to sign in with their email. \
The system will determine to send an authentication code to the email \
or let the uesr use their FLID and passward to sign in",
response_description="signin_type:0 meaning simplified(using email) signin, \
1 meaning standard(using FLID and passward) signin",
)
async def try_signin_with_email(
item: UserSignWithEmailBody,
):
result = await SignInHub().try_signin_with_email(item.email, item.host)
result = {"signin_type": result}
return JSONResponse(content=jsonable_encoder(result))