ac-user-auth / app /controllers /otp_controller.py
MukeshKapoor25's picture
first commit
4438ee0
raw
history blame contribute delete
994 Bytes
from fastapi import APIRouter, HTTPException
from app.services.otp_service import generate_otp_service, validate_otp_service
otp_router = APIRouter()
@otp_router.post("/generate-otp")
async def generate_otp(identifier: str):
"""
Generate and send an OTP for a given identifier (email or mobile).
"""
try:
await generate_otp_service(identifier)
return {"message": "OTP generated and sent successfully."}
except HTTPException as e:
raise e
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@otp_router.post("/validate-otp")
async def validate_user_otp(identifier: str, otp: str):
"""
Validate the OTP for a given identifier (email or mobile).
"""
try:
await validate_otp_service(identifier, otp)
return {"message": "OTP validated successfully."}
except HTTPException as e:
raise e
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))