2020-09-22 13:59:29 +02:00
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
2020-09-11 00:00:48 +02:00
|
|
|
from sqlalchemy.orm import Session
|
2020-06-05 01:09:55 +02:00
|
|
|
|
2020-09-17 17:36:15 +02:00
|
|
|
from app.external_services import send_otp
|
2020-09-22 13:59:29 +02:00
|
|
|
from app.schemas import *
|
2020-09-11 00:00:48 +02:00
|
|
|
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
|
|
|
|
2020-09-22 13:59:29 +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
|
|
|
|
|
|
|
|
2020-06-05 01:09:55 +02:00
|
|
|
# FIXME Use OAuth2 for verification
|
2020-09-22 13:59:29 +02:00
|
|
|
@router.post("/login", response_model=UserLoginResponse)
|
|
|
|
def log_in(request: UserLogin, db: Session = Depends(get_db)):
|
|
|
|
pass
|
2020-05-28 00:53:23 +02:00
|
|
|
|
|
|
|
|
2020-09-22 13:59:29 +02:00
|
|
|
@router.post("/otpVerification", response_model=OTPVerifyResponse)
|
|
|
|
def validate_otp(request: OTPVerify, db: Session = Depends(get_db)):
|
2020-09-11 00:00:48 +02:00
|
|
|
if verify_otp(data=request, db=db):
|
2020-06-05 01:09:55 +02:00
|
|
|
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")
|