odapi/app/routes.py

40 lines
1.2 KiB
Python

from fastapi import APIRouter, Depends
from fastapi.security import OAuth2PasswordBearer
from sqlalchemy.orm import Session
from app.external_services import resend_otp, send_otp
from app.schemas import *
from database.crud import get_db, insert_data, verify_otp
router = APIRouter()
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
# FIXME Password hash
@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
# TODO Use OAuth2 for verification
@router.post("/login", response_model=UserLoginResponse)
def log_in(
data: UserLogin, db: Session = Depends(get_db), token: str = Depends(oauth2_scheme),
):
pass
@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)):
response = resend_otp(data=data, db=db)
return response