Fixes
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
using AipsCore.Domain.Models.User;
|
||||
using AipsCore.Domain.Models.User.External;
|
||||
|
||||
namespace AipsCore.Application.Abstract.UserContext;
|
||||
|
||||
public interface ITokenProvider
|
||||
{
|
||||
string Generate(User user, IList<string> roles);
|
||||
string Generate(User user, IList<UserRole> roles);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
namespace AipsCore.Application.Authentication;
|
||||
|
||||
public record Token(string Value);
|
||||
@@ -0,0 +1,9 @@
|
||||
using AipsCore.Domain.Models.User;
|
||||
|
||||
namespace AipsCore.Application.Common.Authentication;
|
||||
|
||||
public interface IAuthService
|
||||
{
|
||||
Task SignUpWithPasswordAsync(User user, string password, CancellationToken cancellationToken = default);
|
||||
Task<LoginResult> LoginWithEmailAndPasswordAsync(string email, string password, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
using AipsCore.Domain.Models.User;
|
||||
using AipsCore.Domain.Models.User.External;
|
||||
|
||||
namespace AipsCore.Application.Common.Authentication;
|
||||
|
||||
public record LoginResult(User User, IList<UserRole> Roles);
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace AipsCore.Application.Common.Authentication;
|
||||
|
||||
public record Token(string Value);
|
||||
@@ -1,5 +1,5 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
using AipsCore.Application.Authentication;
|
||||
using AipsCore.Application.Common.Authentication;
|
||||
|
||||
namespace AipsCore.Application.Models.User.Command.LogIn;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
using AipsCore.Application.Abstract.UserContext;
|
||||
using AipsCore.Application.Authentication;
|
||||
using AipsCore.Application.Common.Authentication;
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Models.User.External;
|
||||
|
||||
@@ -10,18 +10,18 @@ public class LogInUserCommandHandler : ICommandHandler<LogInUserCommand, Token>
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly ITokenProvider _tokenProvider;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public LogInUserCommandHandler(IUserRepository userRepository, ITokenProvider tokenProvider, IUnitOfWork unitOfWork)
|
||||
private readonly IAuthService _authService;
|
||||
|
||||
public LogInUserCommandHandler(IUserRepository userRepository, ITokenProvider tokenProvider, IAuthService authService)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
_tokenProvider = tokenProvider;
|
||||
_unitOfWork = unitOfWork;
|
||||
_authService = authService;
|
||||
}
|
||||
|
||||
public async Task<Token> Handle(LogInUserCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var loginResult = await _userRepository.LoginWithEmailAndPasswordAsync(command.Email, command.Password, cancellationToken);
|
||||
var loginResult = await _authService.LoginWithEmailAndPasswordAsync(command.Email, command.Password, cancellationToken);
|
||||
|
||||
return new Token(_tokenProvider.Generate(loginResult.User, loginResult.Roles));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AipsCore.Application.Abstract.Command;
|
||||
using AipsCore.Application.Common.Authentication;
|
||||
using AipsCore.Domain.Abstract;
|
||||
using AipsCore.Domain.Models.User.External;
|
||||
using AipsCore.Domain.Models.User.ValueObjects;
|
||||
@@ -8,19 +9,19 @@ namespace AipsCore.Application.Models.User.Command.SignUp;
|
||||
public class SignUpUserCommandHandler : ICommandHandler<SignUpUserCommand, UserId>
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public SignUpUserCommandHandler(IUserRepository userRepository, IUnitOfWork unitOfWork)
|
||||
private readonly IAuthService _authService;
|
||||
|
||||
public SignUpUserCommandHandler(IUserRepository userRepository, IAuthService authService)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_authService = authService;
|
||||
}
|
||||
|
||||
public async Task<UserId> Handle(SignUpUserCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var user = Domain.Models.User.User.Create(command.Email, command.Username);
|
||||
|
||||
await _userRepository.SignUpWithPasswordAsync(user, command.Password, cancellationToken);
|
||||
await _authService.SignUpWithPasswordAsync(user, command.Password, cancellationToken);
|
||||
|
||||
return user.Id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user