37 lines
1.0 KiB
Python
37 lines
1.0 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
|
|
|
|
|
|
# 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)):
|
|
update_otp(data=data, db=db)
|
|
response = resend_otp(data=data, db=db)
|
|
return response
|