odapi/app/routes.py

29 lines
959 B
Python
Raw Normal View History

from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
2020-09-17 17:36:15 +02:00
from app.external_services import send_otp
from app.schemas import *
from database.crud import get_db, insert_data, verify_otp
2020-03-23 21:17:16 +01:00
2020-09-03 18:31:52 +02:00
router = APIRouter()
2020-03-23 21:17:16 +01:00
2020-09-03 18:31:52 +02:00
@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
2020-04-19 21:30:41 +02:00
# 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"}
2020-07-24 19:27:15 +02:00
raise HTTPException(status_code=400, detail="The OTP is not correct")