freeleaps-service-hub/apps/payment/webapi/routes/auth/send_mobile_code.py
2024-11-18 22:01:54 -08:00

41 lines
1.3 KiB
Python

from backend.application.signin_hub import SignInHub
from pydantic import BaseModel
from common.token.token_manager import TokenManager
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from fastapi import APIRouter, Depends, HTTPException
from starlette.status import HTTP_401_UNAUTHORIZED
router = APIRouter()
token_manager = TokenManager()
# Web API
# send_email_code
#
class RequestIn(BaseModel):
email: str
@router.post(
"/send-mobile-code",
operation_id="send-mobile-code",
summary="Send a verification code to the specified mobile number",
description="This API requires an authenticated user and will send a code to the specified mobile. \
The code can be used later to verify the mobile.",
response_description="Indicates success or failure of the mobile code send operation",
)
async def send_email_code(
item: RequestIn,
current_user: dict = Depends(token_manager.get_current_user),
):
user_id = current_user.get("id")
if not user_id:
raise HTTPException(
status_code=HTTP_401_UNAUTHORIZED, detail="Could not validate credentials"
)
result = await SignInHub(user_id).send_mobile_code(item.email)
return JSONResponse(content=jsonable_encoder(result))