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); }
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); }
public PasswordValidator(IOptions <PasswordValidationOptions> settings, IForbiddenService forbidden) { _forbidden = forbidden; _options = settings.Value ?? throw new ArgumentNullException(nameof(settings)); }
public AttachMicrosoftCommandHandler(IAccountRepository repository, IForbiddenService forbidden) { _repository = repository; _forbidden = forbidden; }