Реализовать ЛР 7 на оценку 4
Skeleton contracts / contracts (pull_request) Blocked by required conditions

This commit is contained in:
2026-12-04 16:15:18 +03:00
parent 7996ebbb48
commit 94a8a5c1da
29 changed files with 918 additions and 85 deletions
+9 -2
View File
@@ -3,7 +3,9 @@ from __future__ import annotations
from datetime import datetime, timezone
from uuid import UUID, uuid4
from ..auth.passwords import hash_password, password_matches
from starlette.concurrency import run_in_threadpool
from ..auth.passwords import hash_password, verify_and_upgrade
from ..domain.errors import Unauthorized
from ..domain.models import User
from ..repositories import UserRepository
@@ -30,6 +32,11 @@ class UserService:
async def authenticate(self, username: str, password: str) -> User | None:
row = await self._repository.get_credentials(username)
if row is None or not password_matches(row.password_hash, password):
if row is None:
return None
verified, upgraded = await run_in_threadpool(verify_and_upgrade, row.password_hash, password)
if not verified:
return None
if upgraded is not None:
await self._repository.update_password_hash(row.id, row.password_hash, upgraded)
return self._repository.to_domain(row)