2020-09-28 18:19:59 +02:00
|
|
|
from fastapi import APIRouter, Depends
|
2020-09-11 00:00:48 +02:00
|
|
|
from sqlalchemy.orm import Session
|
2020-06-05 01:09:55 +02:00
|
|
|
|
2020-09-28 18:46:44 +02:00
|
|
|
from app.external_services import resend_otp, send_otp
|
2020-09-22 13:59:29 +02:00
|
|
|
from app.schemas import *
|
2020-10-03 14:50:19 +02:00
|
|
|
from database.crud import *
|
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-28 18:19:59 +02:00
|
|
|
|
2020-09-22 13:59:29 +02:00
|
|
|
@router.post("/register", response_model=UserCreateResponse)
|
2020-09-30 23:53:26 +02:00
|
|
|
def add_user(data: UserCreate, db: Session = Depends(get_db)):
|
|
|
|
user = create_user(data=data, db=db)
|
2020-09-22 13:59:29 +02:00
|
|
|
send_otp(data=user, db=db)
|
|
|
|
return user
|
2020-04-19 21:30:41 +02:00
|
|
|
|
|
|
|
|
2020-09-22 13:59:29 +02:00
|
|
|
@router.post("/login", response_model=UserLoginResponse)
|
2020-10-05 15:35:13 +02:00
|
|
|
def login(data: UserLogin, db: Session = Depends(get_db)):
|
|
|
|
response = authenticate_user(data=data, db=db)
|
|
|
|
return response
|
2020-05-28 00:53:23 +02:00
|
|
|
|
|
|
|
|
2020-09-22 13:59:29 +02:00
|
|
|
@router.post("/otpVerification", response_model=OTPVerifyResponse)
|
2020-09-28 18:19:59 +02:00
|
|
|
def validate_otp(data: OTPVerify, db: Session = Depends(get_db)):
|
|
|
|
response = verify_otp(data=data, db=db)
|
|
|
|
return response
|
2020-09-28 18:46:44 +02:00
|
|
|
|
|
|
|
|
2020-10-03 14:50:19 +02:00
|
|
|
@router.post("/resendOTP", response_model=OTPResendResponse)
|
|
|
|
def deliver_otp(data: OTPResend, db: Session = Depends(get_db)):
|
|
|
|
update_otp(data=data, db=db)
|
2020-09-28 18:46:44 +02:00
|
|
|
response = resend_otp(data=data, db=db)
|
|
|
|
return response
|
2020-10-08 20:47:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
@router.post("/forgot_password", response_model=ForgotPasswordResponse)
|
|
|
|
def forgot_password(data: ForgotPassword, db: Session = Depends(get_db)):
|
|
|
|
mark_password_reset(data=data, db=db)
|
2020-10-08 21:23:19 +02:00
|
|
|
update_otp(data=data, db=db)
|
2020-10-08 20:47:10 +02:00
|
|
|
response = resend_otp(data=data, db=db)
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
2020-10-08 21:23:19 +02:00
|
|
|
@router.post("/reset_password", response_model=ResetPasswordResponse)
|
|
|
|
def reset_password(data: ResetPassword, db: Session = Depends(get_db)):
|
|
|
|
response = verify_password_reset(data=data, db=db)
|
|
|
|
return response
|