forked from mtusi2026/mtusi2026lab4
Реализация лабораторной работы 4 на 4
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from .user_service import UserService
|
||||
|
||||
__all__ = ["UserService"]
|
||||
@@ -0,0 +1,17 @@
|
||||
from config import LOGGER
|
||||
from domain import CreateUserSchema, UserSchema
|
||||
from infrastructure.security import PasswordHasher
|
||||
from interfaces import UserRepository
|
||||
|
||||
|
||||
class UserService:
|
||||
def __init__(self, repository: UserRepository, hasher: PasswordHasher) -> None:
|
||||
self._repo = repository
|
||||
self._hasher = hasher
|
||||
|
||||
async def register(self, data: CreateUserSchema) -> UserSchema:
|
||||
"""Пароль сохраняется только как hash Argon2id"""
|
||||
password_hash = await self._hasher.hash(data.password)
|
||||
user = await self._repo.create(data.username, data.display_name, password_hash)
|
||||
LOGGER.info(f"Зарегистрирован пользователь {user.id}")
|
||||
return user
|
||||
Reference in New Issue
Block a user