Реализовать ЛР 7 на оценку 4
Skeleton contracts / contracts (pull_request) Blocked by required conditions
Skeleton contracts / contracts (pull_request) Blocked by required conditions
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user