public void Should_not_have_error_when_newPassword_equals_confirmationPassword()
 {
     var model = new ChangePasswordModel();
     model.NewPassword = "******";
     model.ConfirmNewPassword = "******";
     _validator.ShouldNotHaveValidationErrorFor(x => x.NewPassword, model);
 }
 public void Should_not_have_error_when_confirmNewPassword_is_specified()
 {
     var model = new ChangePasswordModel();
     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_oldPassword_is_null_or_empty()
 {
     var model = new ChangePasswordModel();
     model.OldPassword = null;
     _validator.ShouldHaveValidationErrorFor(x => x.OldPassword, model);
     model.OldPassword = "";
     _validator.ShouldHaveValidationErrorFor(x => x.OldPassword, model);
 }
 public void Should_have_error_when_newPassword_is_null_or_empty()
 {
     var model = new ChangePasswordModel();
     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 ChangePassword(ChangePasswordModel model)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
                return new HttpUnauthorizedResult();

            var customer = _workContext.CurrentCustomer;

            if (ModelState.IsValid)
            {
                var changePasswordRequest = new ChangePasswordRequest(customer.Email,
                    true, _customerSettings.DefaultPasswordFormat, model.NewPassword, model.OldPassword);
                var changePasswordResult = _customerRegistrationService.ChangePassword(changePasswordRequest);
                if (changePasswordResult.Success)
                {
                    model.Result = _localizationService.GetResource("Account.ChangePassword.Success");
                    return View(model);
                }

                //errors
                foreach (var error in changePasswordResult.Errors)
                    ModelState.AddModelError("", error);
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult ChangePassword()
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
                return new HttpUnauthorizedResult();

            var model = new ChangePasswordModel();
            return View(model);
        }
        public ActionResult ChangePassword()
        {
            if (!IsCurrentUserRegistered())
                return new HttpUnauthorizedResult();

            var customer = _workContext.CurrentCustomer;

            var model = new ChangePasswordModel();
            model.NavigationModel = GetCustomerNavigationModel(customer);
            model.NavigationModel.SelectedTab = CustomerNavigationEnum.ChangePassword;
            return View(model);
        }
        public void Should_validate_newPassword_is_length()
        {
            _customerSettings.PasswordMinLength = 5;
            _validator = new ChangePasswordValidator(_localizationService, _customerSettings);

            var model = new ChangePasswordModel();
            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);
        }
 public void Should_not_have_error_when_oldPassword_is_specified()
 {
     var model = new ChangePasswordModel();
     model.OldPassword = "******";
     _validator.ShouldNotHaveValidationErrorFor(x => x.OldPassword, model);
 }
示例#10
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (!IsCurrentUserRegistered())
                return new HttpUnauthorizedResult();

            var customer = _workContext.CurrentCustomer;

            model.NavigationModel = GetCustomerNavigationModel(customer);
            model.NavigationModel.SelectedTab = CustomerNavigationEnum.ChangePassword;

            if (ModelState.IsValid)
            {
                var changePasswordRequest = new ChangePasswordRequest(customer.Email,
                    true, PasswordFormat.Hashed, model.NewPassword, model.OldPassword);
                var changePasswordResult = _customerRegistrationService.ChangePassword(changePasswordRequest);
                if (changePasswordResult.Success)
                {
                    model.Result = _localizationService.GetResource("Account.ChangePassword.Success");
                    return View(model);
                }
                else
                {
                    foreach (var error in changePasswordResult.Errors)
                        ModelState.AddModelError("", error);
                }
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }