Сборка

This commit is contained in:
Халимов Рустам
2026-03-31 00:16:18 +03:00
parent f1f8f6e012
commit b09e197626
16 changed files with 68 additions and 102 deletions
@@ -1,16 +1,16 @@
using Knot.Contracts.Auth.Domain;
using BCrypt.Net;
using BCrypt.Net;
using Knot.Contracts.Auth.Application.Abstractions;
using Knot.Contracts.Auth.Application.Auth.DTOs;
using Knot.Modules.Auth.Domain;
using Knot.Shared.Kernel;
using Knot.Contracts.Settings.Application.Abstractions;
using Knot.Contracts.Settings.Application.DTOs;
using BCrypt.Net;
using Knot.Modules.Auth.Domain;
using Knot.Shared.Kernel;
namespace Knot.Modules.Auth.Application.Users.Register;
/// <summary>
/// Êîìàíäà äëÿ ðåãèñòðàöèè íîâîãî ïîëüçîâàòåëÿ.
/// .
/// </summary>
public sealed record RegisterUserCommand(
string Username,
@@ -20,7 +20,7 @@ public sealed record RegisterUserCommand(
string? Bio) : ICommand<AuthResponseDto>;
/// <summary>
/// Îáðàáîò÷èê êîìàíäû ðåãèñòðàöèè.
/// .
/// </summary>
internal sealed class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, AuthResponseDto>
{
@@ -48,16 +48,16 @@ internal sealed class RegisterUserCommandHandler : ICommandHandler<RegisterUserC
return Result.Failure<AuthResponseDto>(AuthErrors.IdentityRegistrationDisabled);
}
// 1. Ïðîâåðêà óíèêàëüíîñòè username
// 1. username
if (!await _userRepository.IsUsernameUniqueAsync(request.Username, cancellationToken))
{
return Result.Failure<AuthResponseDto>(AuthErrors.IdentityUsernameNotUnique);
}
// 2. Õåøèðîâàíèå ïàðîëÿ
// 2.
string passwordHash = BCrypt.Net.BCrypt.HashPassword(request.Password);
// 3. Ñîçäàíèå ñóùíîñòè
// 3.
var user = User.Create(
request.Username,
passwordHash,
@@ -65,10 +65,10 @@ internal sealed class RegisterUserCommandHandler : ICommandHandler<RegisterUserC
request.Email,
request.Bio);
// 4. Ñîõðàíåíèå - èñïîëüçóåì ìåòîä ñ Domain User
// 4. - Domain User
var repoWithDomainUserAdd = _userRepository as Infrastructure.Persistence.UserRepository;
repoWithDomainUserAdd?.Add(user);
await _unitOfWork.SaveChangesAsync(cancellationToken);
string token = _tokenProvider.Generate(user.Id, user.Username, user.DisplayName, user.Avatar);