30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
from fastapi import Response, status
|
|
|
|
from app import app
|
|
from app.schemas import *
|
|
from app.twilio import send_otp
|
|
from database.crud import insert_data, verify_otp
|
|
|
|
|
|
@app.post("/register", status_code=status.HTTP_200_OK)
|
|
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
|
|
@app.post("/login", status_code=status.HTTP_200_OK)
|
|
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"}
|
|
|
|
|
|
@app.post("/otpVerification", status_code=status.HTTP_200_OK)
|
|
async def validate_otp(request: OTPSchema, response: Response):
|
|
if verify_otp(data=request):
|
|
return {"message": "The OTP has been verified successfully"}
|
|
response.status_code = status.HTTP_400_BAD_REQUEST
|
|
return {"message": "The OTP is not correct"}
|