Esempio n. 1
0
 public ExistingUsernameValidator(
     ICredentialRequirmentValidator credentialRequirmentValidator,
     IIdentityContext identityContext)
 {
     RuleFor(model => model)
     .MustAsync(async(model, token) => await identityContext.UsernameExists(model))
     .WithMessage((model, value) => $"Username {value} doesn't exists");
 }
Esempio n. 2
0
        public UsernameValidator(ICredentialRequirmentValidator credentialValidator)
        {
            var reason = "Username doesn't meet requirments";

            RuleFor(model => model)
            .Must(model => ValidateUsername(credentialValidator, model, out reason))
            .WithMessage(reason);
        }
Esempio n. 3
0
            public Validator(ICredentialRequirmentValidator validator, IIdentityContext context)
            {
                RuleFor(model => model.NewPassword).Password(validator);

                RuleFor(model => model.Username).ExistingUsername(validator, context);

                RuleFor(model => model.NewUsername).UniqueUsername(validator, context);
            }
Esempio n. 4
0
 public UniqueUsernameValidator(
     ICredentialRequirmentValidator credentialValidator,
     IIdentityContext identityContext)
 {
     RuleFor(model => model)
     .MustAsync(async(model, token) => !await identityContext.UsernameExists(model))
     .WithMessage((model, value) => $"Username: {value} is not available");
 }
Esempio n. 5
0
 public static void Password <TRequest>(
     this IRuleBuilderInitial <TRequest, string> builder,
     ICredentialRequirmentValidator validator)
 {
     builder
     .Cascade(CascadeMode.StopOnFirstFailure)
     .NotEmpty()
     .SetValidator(new PasswordRequirmentValidator(validator));
 }
Esempio n. 6
0
 public static void UniqueUsername <TRequest>(
     this IRuleBuilderInitial <TRequest, string> builder,
     ICredentialRequirmentValidator validator,
     IIdentityContext context)
 {
     builder
     .Cascade(CascadeMode.StopOnFirstFailure)
     .NotEmpty()
     .SetValidator(new UsernameRequirmentValidator(validator))
     .SetValidator(new UniqueUsernameValidator(validator, context));
 }
Esempio n. 7
0
        public PasswordValidator(ICredentialRequirmentValidator credentialValidator)
        {
            _credentialValidator = credentialValidator;

            RuleFor(model => model).NotEmpty();

            var reason = "Password doesn't meet requirments";

            RuleFor(model => model)
            .Must(model => ValidatePassword(model, out reason))
            .WithMessage(reason);
        }
Esempio n. 8
0
        private bool ValidateUsername(ICredentialRequirmentValidator validator, string value, out string reason)
        {
            reason = string.Empty;

            var result = validator
                         .ValidateAsync(CredentialType.Username, value)
                         .Result;

            if (!result.IsValid)
            {
                reason = string.Join(Environment.NewLine, result.ValidationErrors);
                return(false);
            }
            return(true);
        }
Esempio n. 9
0
            public Validator(ICredentialRequirmentValidator validator)
            {
                RuleFor(model => model.Password).Password(validator);

                RuleFor(model => model.Username).Username(validator);
            }
Esempio n. 10
0
 public Validator(ICredentialRequirmentValidator context)
 {
     RuleFor(model => model.Username).Username(context);
 }