odapi/app/routes.py

29 lines
959 B
Python

from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.external_services import send_otp
from app.schemas import *
from database.crud import get_db, insert_data, verify_otp
router = APIRouter()
@router.post("/register", response_model=UserCreateResponse)
def create_user(data: UserCreate, db: Session = Depends(get_db)):
user = insert_data(model="Users", data=data, db=db)
send_otp(data=user, db=db)
return user
# FIXME Use OAuth2 for verification
@router.post("/login", response_model=UserLoginResponse)
def log_in(request: UserLogin, db: Session = Depends(get_db)):
pass
@router.post("/otpVerification", response_model=OTPVerifyResponse)
def validate_otp(request: OTPVerify, 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")