Commit existing codebase

This commit is contained in:
Andrey Chervyakov 2021-02-25 01:39:14 +06:00
commit 49bc902bb9
24 changed files with 1208 additions and 0 deletions

17
app/auth/handlers.py Normal file
View file

@ -0,0 +1,17 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.auth.dto import Credentials, TokenModel
from app.auth.service import authenticate
from app.db import get_db
router = APIRouter()
@router.post("/auth", status_code=200, response_model=TokenModel)
def issue_access_token(credentials: Credentials, db: Session = Depends(get_db)) -> TokenModel:
token = authenticate(credentials, db)
if token is None:
raise HTTPException(status_code=401)
else:
return TokenModel(token=token)