コード例 #1
0
        public ForgotPasswordValidator(IQueryEntities entities, IStorePasswords passwords)
        {
            CascadeMode = CascadeMode.StopOnFirstFailure;

            Establishment establishment     = null;
            var           loadEstablishment = new Expression <Func <Establishment, object> >[]
            {
                e => e.SamlSignOn,
            };

            Person person     = null;
            var    loadPerson = new Expression <Func <Person, object> >[]
            {
                p => p.Emails,
                p => p.User
            };

            RuleFor(p => p.EmailAddress)

            // cannot be empty
            .NotEmpty()
            .WithMessage(FailedBecauseEmailAddressWasEmpty)

            // must be valid against email address regular expression
            .EmailAddress()
            .WithMessage(FailedBecauseEmailAddressWasNotValidEmailAddress)

            // must match an establishment
            .Must(p => ValidateEstablishment.EmailMatchesEntity(p, entities, loadEstablishment, out establishment))
            .WithMessage(FailedBecauseUserNameMatchedNoLocalMember,
                         p => p.EmailAddress)

            // establishment must be a member
            .Must(p => establishment.IsMember)
            .WithMessage(FailedBecauseUserNameMatchedNoLocalMember,
                         p => p.EmailAddress)

            // establishment cannot have saml integration
            .Must(p => !establishment.HasSamlSignOn())
            .WithMessage(FailedBecauseEduPersonTargetedIdWasNotEmpty,
                         p => p.EmailAddress.GetEmailDomain())

            // must match a person
            .Must(p => ValidateEmailAddress.ValueMatchesPerson(p, entities, loadPerson, out person))
            .WithMessage(FailedBecauseUserNameMatchedNoLocalMember,
                         p => p.EmailAddress)

            // the matched person must have a user
            .Must(p => ValidatePerson.UserIsNotNull(person))
            .WithMessage(FailedBecauseUserNameMatchedNoLocalMember,
                         p => p.EmailAddress)

            // the user must not have a SAML account
            .Must(p => ValidateUser.EduPersonTargetedIdIsEmpty(person.User))
            .WithMessage(FailedBecauseEduPersonTargetedIdWasNotEmpty,
                         p => p.EmailAddress.GetEmailDomain())

            // the email address' person's user's name must match a local member account
            .Must(p => ValidateUser.NameMatchesLocalMember(person.User.Name, passwords))
            .WithMessage(FailedBecauseUserNameMatchedNoLocalMember,
                         p => p.EmailAddress)

            // the email address must be confirmed
            .Must(p => ValidateEmailAddress.IsConfirmed(person.GetEmail(p)))
            .WithMessage(ValidateEmailAddress.FailedBecauseIsNotConfirmed,
                         p => p.EmailAddress)
            ;
        }