migrare UI in WebAssembly + integrare Serviciu stocare info pe web + WebToken
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using Application.Services.Database.PostgreSQL;
|
||||
using Application.Services.HashingAlgorithms;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Application.Endpoints.Authorization.Patient;
|
||||
|
||||
public class PatientLoginValidation : AbstractValidator<LoginDto>
|
||||
{
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
private readonly IHashingAlgorithms _hashingAlgorithms;
|
||||
|
||||
public PatientLoginValidation(IPatientRepository patientRepository, IHashingAlgorithms hashingAlgorithms)
|
||||
{
|
||||
_patientRepository = patientRepository;
|
||||
_hashingAlgorithms = hashingAlgorithms;
|
||||
|
||||
RuleFor(x => x.Email)
|
||||
.NotEmpty().WithMessage("Email is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||
.EmailAddress().WithMessage("Invalid email format.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
||||
|
||||
RuleFor(x => x.Password)
|
||||
.NotEmpty().WithMessage("Password is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||
.MinimumLength(8).WithMessage("Password must be at least 8 characters long.")
|
||||
.WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
||||
|
||||
RuleFor(x => x)
|
||||
.MustAsync(CredentialsMatch).WithMessage("Invalid credentials")
|
||||
.WithErrorCode(HttpStatusCodes.Unauthorized.ToString());
|
||||
}
|
||||
|
||||
private async Task<bool> CredentialsMatch(LoginDto dto, CancellationToken cancellationToken)
|
||||
{
|
||||
var code = await _patientRepository.CredentialsMatch(
|
||||
dto.Email, _hashingAlgorithms.SHA256Algorithm(dto.Password));
|
||||
return code;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user