You've already forked RekomenciBackend
feat(): yandex sign up route
This commit is contained in:
@@ -24,7 +24,7 @@ def upgrade() -> None:
|
||||
op.create_table('auth_identities',
|
||||
sa.Column('id', sa.UUID(), nullable=False),
|
||||
sa.Column('user_id', sa.UUID(), nullable=False),
|
||||
sa.Column('method', sa.Enum('EMAIL', name='auth_method'), nullable=False),
|
||||
sa.Column('method', sa.Enum('EMAIL', 'YANDEX', name='auth_method'), nullable=False),
|
||||
sa.Column('identifier', sa.String(), nullable=False),
|
||||
sa.Column('secret_key', sa.String(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from collections.abc import AsyncIterator
|
||||
@@ -73,6 +74,9 @@ def make_asgi_application(
|
||||
async def _main(
|
||||
configuration_path: Path,
|
||||
) -> None:
|
||||
logging.getLogger("httpx").setLevel(logging.WARNING)
|
||||
logging.getLogger("httpcore").setLevel(logging.WARNING)
|
||||
|
||||
configuration = load_configuration(configuration_path)
|
||||
ioc = make_ioc(configuration)
|
||||
asgi_application = make_asgi_application(ioc)
|
||||
|
||||
@@ -1,31 +1,54 @@
|
||||
from dishka import FromDishka
|
||||
from dishka.integrations.fastapi import DishkaRoute
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
from pydantic import BaseModel, SecretStr
|
||||
|
||||
from template_project.application.auth_identity.errors import AuthError, InvalidCodeError
|
||||
from template_project.application.auth_identity.interactors.sign_up import AuthIdentityInteractor
|
||||
from template_project.application.common.containers import SecretString
|
||||
|
||||
router = APIRouter(route_class=DishkaRoute)
|
||||
|
||||
|
||||
class UserSignUpRequest(BaseModel):
|
||||
class EmailSignUpRequest(BaseModel):
|
||||
email: str
|
||||
password: SecretStr
|
||||
|
||||
|
||||
class UserSignUpResponse(BaseModel):
|
||||
class EmailSignUpResponse(BaseModel):
|
||||
access_token: str
|
||||
|
||||
|
||||
@router.post("/auth/sign_up/email")
|
||||
async def sign_up(
|
||||
request: UserSignUpRequest,
|
||||
async def sign_up_email(
|
||||
request: EmailSignUpRequest,
|
||||
interactor: FromDishka[AuthIdentityInteractor],
|
||||
) -> UserSignUpResponse:
|
||||
) -> EmailSignUpResponse:
|
||||
response_interactor = await interactor.sign_up_email(
|
||||
email=request.email, password=SecretString(request.password.get_secret_value())
|
||||
)
|
||||
return UserSignUpResponse(
|
||||
return EmailSignUpResponse(
|
||||
access_token=response_interactor.access_token,
|
||||
)
|
||||
|
||||
|
||||
class YandexSignUpRequest(BaseModel):
|
||||
code: str
|
||||
|
||||
|
||||
class YandexSignUpResponse(BaseModel):
|
||||
access_token: str
|
||||
|
||||
|
||||
@router.post("/auth/sign_up/yandex")
|
||||
async def sign_up_yandex(
|
||||
request: YandexSignUpRequest,
|
||||
interactor: FromDishka[AuthIdentityInteractor],
|
||||
) -> YandexSignUpResponse:
|
||||
try:
|
||||
response_interactor = await interactor.sign_up_yandex(code=request.code)
|
||||
|
||||
except (InvalidCodeError, AuthError) as error:
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Authentication failed") from error
|
||||
|
||||
return YandexSignUpResponse(access_token=response_interactor.access_token)
|
||||
|
||||
Reference in New Issue
Block a user