migrare UI in WebAssembly + integrare Serviciu stocare info pe web + WebToken

This commit is contained in:
andrei-mihnea-cerbu
2024-04-10 06:57:48 +03:00
parent 9977a9b5f5
commit adba50e70b
1915 changed files with 16113 additions and 99991 deletions
@@ -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;
}
}