odapi/app/routes.py

29 lines
973 B
Python
Raw Normal View History

2020-07-24 19:27:15 +02:00
from fastapi import HTTPException, Response, status
2020-03-23 21:17:16 +01:00
from app import app
from app.schemas import *
from app.twilio import send_otp
2020-07-03 02:03:02 +02:00
from database.crud import insert_data, verify_otp
2020-03-23 21:17:16 +01:00
2020-07-24 19:27:15 +02:00
@app.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"}
2020-04-19 21:30:41 +02:00
# FIXME Use OAuth2 for verification
2020-07-24 19:27:15 +02:00
@app.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"}
2020-07-24 19:27:15 +02:00
@app.post("/otpVerification")
async def validate_otp(request: OTPSchema, response: Response):
if verify_otp(data=request):
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")