public void Should_not_have_error_when_newPassword_equals_confirmationPassword()
 {
     var model = new PasswordRecoveryConfirmModel();
     model.NewPassword = "******";
     model.ConfirmNewPassword = "******";
     _validator.ShouldNotHaveValidationErrorFor(x => x.NewPassword, model);
 }
 public void Should_not_have_error_when_confirmNewPassword_is_specified()
 {
     var model = new PasswordRecoveryConfirmModel();
     model.ConfirmNewPassword = "******";
     //we know that new password should equal confirmation password
     model.NewPassword = model.ConfirmNewPassword;
     _validator.ShouldNotHaveValidationErrorFor(x => x.ConfirmNewPassword, model);
 }
 public void Should_have_error_when_confirmNewPassword_is_null_or_empty()
 {
     var model = new PasswordRecoveryConfirmModel();
     model.ConfirmNewPassword = null;
     _validator.ShouldHaveValidationErrorFor(x => x.ConfirmNewPassword, model);
     model.ConfirmNewPassword = "";
     _validator.ShouldHaveValidationErrorFor(x => x.ConfirmNewPassword, model);
 }
 public void Should_have_error_when_newPassword_is_null_or_empty()
 {
     var model = new PasswordRecoveryConfirmModel();
     model.NewPassword = null;
     //we know that new password should equal confirmation password
     model.ConfirmNewPassword = model.NewPassword;
     _validator.ShouldHaveValidationErrorFor(x => x.NewPassword, model);
     model.NewPassword = "";
     //we know that new password should equal confirmation password
     model.ConfirmNewPassword = model.NewPassword;
     _validator.ShouldHaveValidationErrorFor(x => x.NewPassword, model);
 }
        public ActionResult PasswordRecoveryConfirm(string token, string email)
        {
            var customer = _customerService.GetCustomerByEmail(email);
            if (customer == null )
                return RedirectToHomePageWithError("Email");

            var cPrt = customer.GetAttribute<string>(SystemCustomerAttributeNames.PasswordRecoveryToken);
            if (String.IsNullOrEmpty(cPrt))
                return RedirectToHomePageWithError("Token");

            if (!cPrt.Equals(token, StringComparison.InvariantCultureIgnoreCase))
                return RedirectToHomePageWithError("Token");

            var model = new PasswordRecoveryConfirmModel();
            return View(model);
        }
        public ActionResult PasswordRecoveryConfirmPOST(string token, string email, PasswordRecoveryConfirmModel model)
        {
            var customer = _customerService.GetCustomerByEmail(email);
            if (customer == null)
                return RedirectToHomePageWithError("Email");

            var cPrt = customer.GetAttribute<string>(SystemCustomerAttributeNames.PasswordRecoveryToken);
            if (String.IsNullOrEmpty(cPrt))
                return RedirectToHomePageWithError("Token");

            if (!cPrt.Equals(token, StringComparison.InvariantCultureIgnoreCase))
                return RedirectToHomePageWithError("Token");

            if (ModelState.IsValid)
            {
                var response = _customerRegistrationService.ChangePassword(new ChangePasswordRequest(email,
                    false, _customerSettings.DefaultPasswordFormat, model.NewPassword));
                if (response.Success)
                {
                    _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.PasswordRecoveryToken, "");

                    model.SuccessfullyChanged = true;
                    model.Result = _localizationService.GetResource("Account.PasswordRecovery.PasswordHasBeenChanged");
                }
                else
                {
                    model.Result = response.Errors.FirstOrDefault();
                }

                return View(model);
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
        public void Should_validate_newPassword_is_length()
        {
            _customerSettings.PasswordMinLength = 5;
            _validator = new PasswordRecoveryConfirmValidator(_localizationService, _customerSettings);

            var model = new PasswordRecoveryConfirmModel();
            model.NewPassword = "******";
            //we know that new password should equal confirmation password
            model.ConfirmNewPassword = model.NewPassword;
            _validator.ShouldHaveValidationErrorFor(x => x.NewPassword, model);
            model.NewPassword = "******";
            //we know that new password should equal confirmation password
            model.ConfirmNewPassword = model.NewPassword;
            _validator.ShouldNotHaveValidationErrorFor(x => x.NewPassword, model);
        }