42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from app.authentication.backend.application.signin_hub import SignInHub
|
|
from pydantic import BaseModel
|
|
from infra.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
|
|
sender_id: str
|
|
|
|
|
|
@router.post(
|
|
"/send-email-code",
|
|
operation_id="send-email-code",
|
|
summary="Send a verification code to the specified email address",
|
|
description="This API requires an authenticated user and will send a code to the specified email. \
|
|
The code can be used later to verify the email address.",
|
|
response_description="Indicates success or failure of the email 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_email_code(item.sender_id, item.email)
|
|
return JSONResponse(content=jsonable_encoder(result))
|