add endpoint /login

This commit is contained in:
IluaAir
2025-07-13 11:59:03 +03:00
parent e5dec473cb
commit a0f9aaeaea
3 changed files with 15 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
from fastapi import APIRouter from fastapi import APIRouter
from src.api.dependacies.db_dep import sessionDep 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.core.settings import settings
from src.services.auth import AuthService from src.services.auth import AuthService
@@ -9,6 +9,12 @@ router = APIRouter(prefix=settings.api.v1.auth, tags=["Auth"])
@router.post(path="/signup") @router.post(path="/signup")
async def registration(session: sessionDep, credential: UserRequest): async def registration(session: sessionDep, credential: UserRequestADD):
auth = await AuthService(session).registration(credential) auth = await AuthService(session).registration(credential)
return auth return auth
@router.post(path="/login")
async def login(session: sessionDep, credential: UserRequest):
...

View File

@@ -19,6 +19,11 @@ class UserWithHashedPass(User):
class UserRequest(BaseModel): class UserRequest(BaseModel):
username: str
password: str
class UserRequestADD(BaseModel):
username: str username: str
email: EmailStr | None = None email: EmailStr | None = None
password: Annotated[str, BeforeValidator(ensure_password)] password: Annotated[str, BeforeValidator(ensure_password)]

View File

@@ -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.services.base import BaseService
from src.utils.auth_manager import AuthManger from src.utils.auth_manager import AuthManger
class AuthService(BaseService): 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) hashed_pass = AuthManger.get_password_hash(cred.password)
user_to_insert = UserAdd( user_to_insert = UserAdd(
username=cred.username, username=cred.username,