public SignUpByEmailCommandValidator(IAccountRepository repository, IPasswordValidator validator, IForbiddenService forbiddenService) { CascadeMode = CascadeMode.Stop; RuleFor(x => x.Password) .NotEmpty() .CustomAsync(async(password, context, token) => { var(isSuccess, error) = await validator.ValidateAsync(password, token); if (!isSuccess) { context.AddFailure( new ValidationFailure(nameof(SignUpByEmailCommand.Password), "Incorrect password") { ErrorCode = error } ); } }); RuleFor(x => x.Email) .ChildRules(x => x.RuleFor(t => t.Value) .NotEmpty() .EmailAddress() .WithErrorCode(ElwarkExceptionCodes.EmailIncorrectFormat) ) .MustAsync(async(email, ct) => !await repository.IsExists(email, ct)) .WithErrorCode(ElwarkExceptionCodes.EmailAlreadyExists) .MustAsync(async(email, ct) => { var host = email.GetMailAddress().Host; return(!await forbiddenService.IsEmailHostDenied(host, ct)); }) .WithErrorCode(ElwarkExceptionCodes.EmailHostDenied); }
private async Task <bool> IsAvailableToAttach(EmailIdentity email, CancellationToken ct) { if (await _repository.IsExists(email, ct)) { return(false); } if (await _forbidden.IsEmailHostDenied(email.GetMailAddress().Host, ct)) { return(false); } return(true); }
public SignUpByGoogleCommandValidator(IAccountRepository repository, IForbiddenService forbiddenService) { CascadeMode = CascadeMode.Stop; RuleFor(x => x.Google) .NotNull() .MustAsync(async(google, ct) => !await repository.IsExists(google, ct)) .WithErrorCode(ElwarkExceptionCodes.ProviderAlreadyExists); RuleFor(x => x.Email) .ChildRules(x => x.RuleFor(t => t.Value) .NotEmpty() .EmailAddress() .WithErrorCode(ElwarkExceptionCodes.EmailIncorrectFormat) ) .MustAsync(async(email, ct) => { var host = email.GetMailAddress().Host; return(!await forbiddenService.IsEmailHostDenied(host, ct)); }) .WithErrorCode(ElwarkExceptionCodes.EmailHostDenied) .MustAsync(async(email, ct) => !await repository.IsExists(email, ct)) .WithErrorCode(ElwarkExceptionCodes.EmailAlreadyExists); }