odapi/app/routes.py

34 lines
990 B
Python
Raw Normal View History

2020-09-28 18:19:59 +02:00
from fastapi import APIRouter, Depends
from fastapi.security import OAuth2PasswordBearer
from sqlalchemy.orm import Session
2020-09-17 17:36:15 +02:00
from app.external_services import send_otp
from app.schemas import *
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-28 18:19:59 +02:00
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
2020-09-03 18:31:52 +02:00
2020-09-28 18:19:59 +02:00
# FIXME Password hash
@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-09-28 18:19:59 +02:00
# TODO Use OAuth2 for verification
@router.post("/login", response_model=UserLoginResponse)
2020-09-28 18:19:59 +02:00
def log_in(
data: UserLogin, db: Session = Depends(get_db), token: str = Depends(oauth2_scheme),
):
pass
@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