From 19a9b36173f663cf0af7de35fa6b2cac74ef4c87 Mon Sep 17 00:00:00 2001 From: IluaAir Date: Mon, 14 Jul 2025 12:08:50 +0300 Subject: [PATCH] add OAuth2PasswordRequestForm --- poetry.lock | 14 +++++++++++++- pyproject.toml | 1 + src/api/v1/auth.py | 15 ++++++++++----- src/services/auth.py | 4 +++- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/poetry.lock b/poetry.lock index 0229d83..f3cc33f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -590,6 +590,18 @@ files = [ [package.extras] cli = ["click (>=5.0)"] +[[package]] +name = "python-multipart" +version = "0.0.20" +description = "A streaming multipart parser for Python" +optional = false +python-versions = ">=3.8" +groups = ["main"] +files = [ + {file = "python_multipart-0.0.20-py3-none-any.whl", hash = "sha256:8a62d3a8335e06589fe01f2a3e178cdcc632f3fbe0d492ad9ee0ec35aab1f104"}, + {file = "python_multipart-0.0.20.tar.gz", hash = "sha256:8dd0cab45b8e23064ae09147625994d090fa46f5b0d1e13af944c331a7fa9d13"}, +] + [[package]] name = "ruff" version = "0.11.12" @@ -793,4 +805,4 @@ standard = ["colorama (>=0.4) ; sys_platform == \"win32\"", "httptools (>=0.6.3) [metadata] lock-version = "2.1" python-versions = ">=3.12" -content-hash = "bddd2102f9e1901ece4bcffde03bc1512cf4319a897a0f14444236d5e0cb8401" +content-hash = "7f9ca5ce7505707747e59087ccbb804dc0fef135c963fd2d2ebc8c91285ec188" diff --git a/pyproject.toml b/pyproject.toml index c96ca88..4e31eb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ dependencies = [ "passlib (>=1.7.4,<2.0.0)", "email-validator (>=2.2.0,<3.0.0)", "bcrypt (==4.0.1)", + "python-multipart (>=0.0.20,<0.0.21)", ] diff --git a/src/api/v1/auth.py b/src/api/v1/auth.py index 3f80867..18a92ac 100644 --- a/src/api/v1/auth.py +++ b/src/api/v1/auth.py @@ -1,7 +1,10 @@ -from fastapi import APIRouter +from typing import Annotated + +from fastapi import APIRouter, Depends +from fastapi.security import OAuth2PasswordRequestForm from src.api.dependacies.db_dep import sessionDep -from src.schemas.users import UserRequestADD, UserRequest +from src.schemas.users import UserRequestADD from src.core.settings import settings from src.services.auth import AuthService @@ -15,6 +18,8 @@ async def registration(session: sessionDep, credential: UserRequestADD): @router.post(path="/login") -async def login(session: sessionDep, credential: UserRequest): - - ... +async def login( + session: sessionDep, + credential: Annotated[OAuth2PasswordRequestForm, Depends()], + ): + user = AuthService(session).login(credential.username, credential.password) diff --git a/src/services/auth.py b/src/services/auth.py index eb7b905..7a51697 100644 --- a/src/services/auth.py +++ b/src/services/auth.py @@ -14,6 +14,8 @@ class AuthService(BaseService): is_superuser=False, ) result = await self.session.user.create_one(user_to_insert) - print(result) await self.session.commit() return User.model_validate(result) + + async def login(self, username: str, password: str): + ...