from fastapi import APIRouter, Depends, HTTPException, Response from sqlalchemy.orm import Session from app.schemas import * from app.external_services import send_otp from database.crud import get_db, insert_data, verify_otp router = APIRouter() @router.post("/register") def create_user(request: UserCreate, db: Session = Depends(get_db)): insert_data(model="Users", data=request, db=db) send_otp(receiver=request.mobile) return {"message": "User created, pending OTP verification"} # FIXME Use OAuth2 for verification @router.post("/login") async def log_in(request: UserLogin, response: Response, db: Session = Depends(get_db)): return {"message": "Logged in successfully"} # response.status_code = status.HTTP_400_BAD_REQUEST # return {"message": "The email/password combination is not correct"} @router.post("/otpVerification") async def validate_otp( request: OTPVerify, response: Response, db: Session = Depends(get_db) ): if verify_otp(data=request, db=db): return {"message": "The OTP has been verified successfully"} raise HTTPException(status_code=400, detail="The OTP is not correct")