public bool IsValidPasswordForm(ModelState modelState, ChangePasswordFormViewModel passwordForm, string oldPassword = null)
        {
            var prefix        = nameof(passwordForm);
            var passwordField = $"{prefix}.{nameof(passwordForm.Password)}";

            var validationRules = new List <ValidationRuleItem <ChangePasswordFormViewModel> >()
            {
                new ValidationRuleItem <ChangePasswordFormViewModel> {
                    Field = passwordField, Rule = model => !string.IsNullOrEmpty(model.Password), ErrorMessage = "validation.required".AsWebSiteString()
                },
                new ValidationRuleItem <ChangePasswordFormViewModel> {
                    Field = passwordField, Rule = model => oldPassword == null || !model.Password.Equals(oldPassword), ErrorMessage = "changepassword.newpasswordequalstheoldpassword".AsWebSiteString()
                },
                new ValidationRuleItem <ChangePasswordFormViewModel> {
                    Field = passwordField, Rule = model => _userValidationService.IsValidPassword(model.Password), ErrorMessage = "changepassword.invalidpasswordformat".AsWebSiteString()
                },
                new ValidationRuleItem <ChangePasswordFormViewModel> {
                    Field = passwordField, Rule = model => _userValidationService.IsPasswordMatch(model.Password, model.ConfirmPassword), ErrorMessage = "changepassword.passwordconfirmationdoesnotmatch".AsWebSiteString()
                },
                new ValidationRuleItem <ChangePasswordFormViewModel> {
                    Field = passwordField, Rule = model => _userValidationService.IsValidPasswordComplexity(model.Password), ErrorMessage = "changepassword.weakpassword".AsWebSiteString()
                },
            };

            return(passwordForm.IsValid(validationRules, modelState));
        }
 public void TestInitialize()
 {
     this.refService         = new Mock <IRefereeService>();
     this.regionManager      = new Mock <IRegionManager>();
     this.interactionService = new Mock <IInteractionService>();
     this.viewModel          = new ChangePasswordFormViewModel(regionManager.Object, interactionService.Object, refService.Object);
     this.navigationContext  = new NavigationContext(new Mock <IRegionNavigationService>().Object, new Uri("http://www.test.com"));
     this.refService.Setup(x => x.ChangePassword(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true);
 }
        public ActionResult SavePassword(ChangePasswordFormViewModel passwordForm)
        {
            if (_myPagesViewModelService.IsValidPasswordForm(_modelState, passwordForm))
            {
                _myPagesViewModelService.SavePassword(passwordForm.Password);
                return(RedirectToAction(nameof(Index), new { CurrentTab = MyPagesTabConstants.LoginInfo }));
            }

            var model = _myPagesViewModelBuilder.Build();

            model.CurrentTab = MyPagesTabConstants.LoginInfo;
            return(View(nameof(Index), model));
        }
Exemple #4
0
 /// <summary>
 /// Инициализирует форму изменения пароля
 /// </summary>
 /// <param name="model">Модель отображения для формы</param>
 public ChangePasswordForm(ChangePasswordFormViewModel model) : this()
 {
     this.vm = model;
 }