From a0f9aaeaea897ff9628337d3cfe03d02f525d26f Mon Sep 17 00:00:00 2001 From: IluaAir Date: Sun, 13 Jul 2025 11:59:03 +0300 Subject: [PATCH] add endpoint /login --- src/api/v1/auth.py | 10 ++++++++-- src/schemas/users.py | 5 +++++ src/services/auth.py | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/api/v1/auth.py b/src/api/v1/auth.py index 5b3b59b..3f80867 100644 --- a/src/api/v1/auth.py +++ b/src/api/v1/auth.py @@ -1,7 +1,7 @@ from fastapi import APIRouter from src.api.dependacies.db_dep import sessionDep -from src.schemas.users import UserRequest +from src.schemas.users import UserRequestADD, UserRequest from src.core.settings import settings from src.services.auth import AuthService @@ -9,6 +9,12 @@ router = APIRouter(prefix=settings.api.v1.auth, tags=["Auth"]) @router.post(path="/signup") -async def registration(session: sessionDep, credential: UserRequest): +async def registration(session: sessionDep, credential: UserRequestADD): auth = await AuthService(session).registration(credential) return auth + + +@router.post(path="/login") +async def login(session: sessionDep, credential: UserRequest): + + ... diff --git a/src/schemas/users.py b/src/schemas/users.py index 48e7c38..ff9cbf3 100644 --- a/src/schemas/users.py +++ b/src/schemas/users.py @@ -19,6 +19,11 @@ class UserWithHashedPass(User): class UserRequest(BaseModel): + username: str + password: str + + +class UserRequestADD(BaseModel): username: str email: EmailStr | None = None password: Annotated[str, BeforeValidator(ensure_password)] diff --git a/src/services/auth.py b/src/services/auth.py index 5241296..fd5f33d 100644 --- a/src/services/auth.py +++ b/src/services/auth.py @@ -1,10 +1,10 @@ -from src.schemas.users import UserRequest, User, UserAdd +from src.schemas.users import UserRequestADD, User, UserAdd from src.services.base import BaseService from src.utils.auth_manager import AuthManger class AuthService(BaseService): - async def registration(self, cred: UserRequest) -> User: + async def registration(self, cred: UserRequestADD) -> User: hashed_pass = AuthManger.get_password_hash(cred.password) user_to_insert = UserAdd( username=cred.username,