from backend.application.signin_hub import SignInHub from pydantic import BaseModel from common.token.token_manager import TokenManager, CurrentUser 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: CurrentUser = Depends(token_manager.get_current_user), ): user_id = current_user.user_id if not user_id: raise HTTPException( status_code=HTTP_401_UNAUTHORIZED, detail="Could not validate credentials" ) result = await SignInHub().send_mobile_code(item.email) return JSONResponse(content=jsonable_encoder(result))