fix auth manager

This commit is contained in:
IluaAir
2025-07-14 11:58:12 +03:00
parent a0f9aaeaea
commit dd6f06cd12
6 changed files with 7 additions and 8 deletions

35
src/core/auth_manager.py Normal file
View File

@@ -0,0 +1,35 @@
from datetime import timedelta, datetime, timezone
import jwt
from passlib.context import CryptContext
from src.core.settings import settings
class AuthManger:
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
@classmethod
def verify_password(cls, plain_password, hashed_password):
return cls.pwd_context.verify(plain_password, hashed_password)
@classmethod
def get_password_hash(cls, password):
return cls.pwd_context.hash(password)
@classmethod
def create_access_token(cls, data: dict, expires_delta: timedelta | None = None):
to_encode = data.copy()
if expires_delta:
expire = datetime.now(timezone.utc) + expires_delta
else:
expire = datetime.now(timezone.utc) + timedelta(
minutes=settings.access_token.expire_minutes
)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(
to_encode,
settings.access_token.secret_key,
algorithm=settings.access_token.algorithm,
)
return encoded_jwt

View File

@@ -3,10 +3,10 @@ from typing import Protocol
from src.repository.users import UsersRepo
class IUnitOfWork(Protocol):
class IUOWDB(Protocol):
user: UsersRepo
async def __aenter__(self) -> "IUnitOfWork": ...
async def __aenter__(self) -> "IUOWDB": ...
async def __aexit__(self, exc_type, exc_val, exc_tb) -> None: ...

View File

@@ -38,4 +38,3 @@ class Settings(BaseSettings):
settings = Settings()
print(settings.db.url)