Example #1
0
        public void InvalidWhenEmailNotProvided(string email)
        {
            // arrange
            var validator = new ForgotPasswordValidator();
            var dto       = new ForgotPasswordDto
            {
                Email = email
            };
            // act
            var result = validator.Validate(dto);

            // assert
            Assert.False(result.IsValid);
        }
Example #2
0
        public void ValidWhenEmailAndPasswordProvided()
        {
            // arrange
            var validator = new ForgotPasswordValidator();
            var login     = new ForgotPasswordDto
            {
                Email = validEmail
            };
            // act
            var result = validator.Validate(login);

            // assert
            Assert.True(result.IsValid);
        }
            public void IsInvalidWhen_IsNull()
            {
                var validated = new ForgotPasswordForm();
                var validator = new ForgotPasswordValidator(null, null);

                var results = validator.Validate(validated);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName);
                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(
                    ForgotPasswordValidator.FailedBecauseEmailAddressWasEmpty);
                // ReSharper restore PossibleNullReferenceException
            }
Example #4
0
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordModel model)
        {
            #region Validate Model

            var userInputValidated = _forgotPasswordValidator.Validate(model);

            if (!userInputValidated.IsValid)
            {
                _infos.Add(_badRequest.ShowError(int.Parse(userInputValidated.Errors[0].ErrorMessage)).Message);

                return(BadRequest(new CustomResponse <string> {
                    Message = _infos
                }));
            }

            #endregion

            var sentResetPassword = await _user.ForgotPassword(model);

            return(Ok(sentResetPassword));
        }
Example #5
0
        private async void SendMyPassword()
        {
            View.HideKeyboard();

            ForgotPasswordValidator validator = new ForgotPasswordValidator();

            string email = ForgotEmail;

            var result = validator.Validate(email);

            if (result.IsValid)
            {
                mPlatformService.ShowNetworkIndicator();
                mProgressDialogService.ShowProgressDialog();

                var response = await mApiService.PostForgotPassword(email);

                mPlatformService.HideNetworkIndicator();
                mProgressDialogService.HideProgressDialog();

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    mMessageboxService.Show("Forgot password", Messages.ForgotPasswordSuccess);
                    View.HidePopupForgotPassword();
                }
                else
                {
                    mMessageboxService.Show("Opps...", Messages.FotgotPasswordFail);
                }
            }
            else if (result.Errors != null)
            {
                var firstError = result.Errors.First();
                mMessageboxService.ShowToast(firstError.ErrorMessage);
            }
        }
            public void IsValidWhen_MatchesPerson_WithNonSamlLocalUser_AndConfirmedEmailAddress()
            {
                var validated = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var person = new Person
                {
                    User = new User
                    {
                        Name = "*****@*****.**",
                    },
                    Emails = new[]
                    {
                        new EmailAddress
                        {
                            Value = validated.EmailAddress,
                            IsConfirmed = true,
                        },
                    },
                };
                var establishment = new Establishment
                {
                    IsMember = true,
                    EmailDomains = new[] { new EstablishmentEmailDomain { Value = "@domain.tld" }, },
                };
                var passwords = new Mock<IStorePasswords>(MockBehavior.Strict);
                passwords.Setup(m => m
                    .Exists(It.Is(IsSignedUpBasedOn(person))))
                    .Returns(true);
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<Establishment>()).Returns(new[] { establishment }.AsQueryable);
                entities.Setup(m => m.Query<Person>()).Returns(new[] { person }.AsQueryable);
                var validator = new ForgotPasswordValidator(entities.Object, passwords.Object);

                var results = validator.Validate(validated);

                var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName);
                error.ShouldBeNull();
            }
            public void IsInvalidWhen_MatchesUnconfirmedEmailAddress()
            {
                var validated = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var person = new Person
                {
                    User = new User
                    {
                        Name = "*****@*****.**",
                    },
                    Emails = new[]
                    {
                        new EmailAddress
                        {
                            Value = validated.EmailAddress,
                        },
                    },
                };
                var establishment = new Establishment
                {
                    IsMember = true,
                    EmailDomains = new[] { new EstablishmentEmailDomain { Value = "@domain.tld" }, },
                };
                var passwords = new Mock<IStorePasswords>(MockBehavior.Strict);
                passwords.Setup(m => m
                    .Exists(It.Is(IsSignedUpBasedOn(person))))
                    .Returns(true);
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<Establishment>()).Returns(new[] { establishment }.AsQueryable);
                entities.Setup(m => m.Query<Person>()).Returns(new[] { person }.AsQueryable);
                var validator = new ForgotPasswordValidator(entities.Object, passwords.Object);

                var results = validator.Validate(validated);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName);
                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                    ValidateEmailAddress.FailedBecauseIsNotConfirmed,
                        validated.EmailAddress));
                // ReSharper restore PossibleNullReferenceException
            }
            public void IsInvalidWhen_MatchesPerson_WithSamlUser()
            {
                var validated = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var person = new Person
                {
                    User = new User
                    {
                        EduPersonTargetedId = "something",
                    },
                    Emails = new[] { new EmailAddress { Value = validated.EmailAddress, }, },
                };
                var establishment = new Establishment
                {
                    IsMember = true,
                    EmailDomains = new[] { new EstablishmentEmailDomain { Value = "@domain.tld" }, },
                };
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<Establishment>()).Returns(new[] { establishment }.AsQueryable);
                entities.Setup(m => m.Query<Person>()).Returns(new[] { person }.AsQueryable);
                var validator = new ForgotPasswordValidator(entities.Object, null);

                var results = validator.Validate(validated);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName);
                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                    ForgotPasswordValidator.FailedBecauseEduPersonTargetedIdWasNotEmpty,
                        validated.EmailAddress.GetEmailDomain()));
                // ReSharper restore PossibleNullReferenceException
            }
            public void IsInvalidWhen_MatchesNoPerson()
            {
                var validated = new ForgotPasswordForm
                {
                    EmailAddress = "*****@*****.**",
                };
                var establishment = new Establishment
                {
                    IsMember = true,
                };
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Query<Establishment>()).Returns(new[] { establishment }.AsQueryable);
                entities.Setup(m => m.Query<Person>()).Returns(new Person[] { }.AsQueryable);
                var validator = new ForgotPasswordValidator(entities.Object, null);

                var results = validator.Validate(validated);

                results.IsValid.ShouldBeFalse();
                results.Errors.Count.ShouldBeInRange(1, int.MaxValue);
                var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName);
                error.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                error.ErrorMessage.ShouldEqual(string.Format(
                    ForgotPasswordValidator.FailedBecauseUserNameMatchedNoLocalMember,
                        validated.EmailAddress));
                // ReSharper restore PossibleNullReferenceException
            }