odapi/app/routes.py

44 lines
1.3 KiB
Python

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.external_services import resend_otp, send_otp
from app.schemas import *
from database.crud import *
router = APIRouter()
@router.post("/register", response_model=UserCreateResponse)
def add_user(data: UserCreate, db: Session = Depends(get_db)):
user = create_user(data=data, db=db)
send_otp(data=user, db=db)
return user
@router.post("/login", response_model=UserLoginResponse)
def login(data: UserLogin, db: Session = Depends(get_db)):
response = authenticate_user(data=data, db=db)
return response
@router.post("/otpVerification", response_model=OTPVerifyResponse)
def validate_otp(data: OTPVerify, db: Session = Depends(get_db)):
response = verify_otp(data=data, db=db)
return response
@router.post("/resendOTP", response_model=OTPResendResponse)
def deliver_otp(data: OTPResend, db: Session = Depends(get_db)):
update_otp(data=data, db=db)
response = resend_otp(data=data, db=db)
return response
@router.post("/forgot_password", response_model=ForgotPasswordResponse)
def forgot_password(data: ForgotPassword, db: Session = Depends(get_db)):
mark_password_reset(data=data, db=db)
response = resend_otp(data=data, db=db)
return response