30 lines
987 B
Python
30 lines
987 B
Python
from fastapi import APIRouter, HTTPException, Response
|
|
|
|
from app.schemas import *
|
|
from app.twilio import send_otp
|
|
from database.crud import insert_data, verify_otp
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/register")
|
|
async def create_user(request: RegisterSchema):
|
|
insert_data(schema="Users", data=request)
|
|
send_otp(receiver=request.mobile)
|
|
return {"message": "User created, pending OTP verification"}
|
|
|
|
|
|
# FIXME Use OAuth2 for verification
|
|
@router.post("/login")
|
|
async def log_in(request: LoginSchema, response: Response):
|
|
return {"message": "Logged in successfully"}
|
|
# response.status_code = status.HTTP_400_BAD_REQUEST
|
|
# return {"message": "The email/password combination is not correct"}
|
|
|
|
|
|
@router.post("/otpVerification")
|
|
async def validate_otp(request: OTPSchema, response: Response):
|
|
if verify_otp(data=request):
|
|
return {"message": "The OTP has been verified successfully"}
|
|
raise HTTPException(status_code=400, detail="The OTP is not correct")
|