Esempio n. 1
0
        public ViewResult ChangePassword(UserEditSecurity userEdit)
        {
            string errorMessage;
            var    user = _userRetrievalShim.GetUser(HttpContext);

            if (user == null)
            {
                return(View("EditAccountNoUser"));
            }
            if (!_userService.VerifyPassword(user, userEdit.OldPassword))
            {
                ViewBag.PasswordResult = Resources.OldPasswordIncorrect;
            }
            else if (!userEdit.NewPasswordsMatch())
            {
                ViewBag.PasswordResult = Resources.RetypePasswordMustMatch;
            }
            else if (!_userService.IsPasswordValid(userEdit.NewPassword, out errorMessage))
            {
                ViewBag.PasswordResult = errorMessage;
            }
            else
            {
                _userService.SetPassword(user, userEdit.NewPassword, HttpContext.Connection.RemoteIpAddress.ToString(), user);
                ViewBag.PasswordResult = Resources.NewPasswordSaved;
            }
            return(View("Security", new UserEditSecurity {
                NewEmail = String.Empty, NewEmailRetype = String.Empty, IsNewUserApproved = _settingsManager.Current.IsNewUserApproved
            }));
        }
Esempio n. 2
0
        public ViewResult ChangePassword(UserEditSecurity userEdit)
        {
            var modelState = new ModelStateDictionary();
            var user       = this.CurrentUser();

            if (user == null)
            {
                return(View("EditAccountNoUser"));
            }
            if (!_userService.VerifyPassword(user, userEdit.OldPassword))
            {
                ViewBag.PasswordResult = Resources.OldPasswordIncorrect;
            }
            else if (!userEdit.NewPasswordsMatch())
            {
                ViewBag.PasswordResult = Resources.RetypePasswordMustMatch;
            }
            else if (!_userService.IsPasswordValid(userEdit.NewPassword, modelState))
            {
                ViewBag.PasswordResult = modelState["Password"];
            }
            else
            {
                _userService.SetPassword(user, userEdit.NewPassword, HttpContext.Request.UserHostAddress, user);
                ViewBag.PasswordResult = Resources.NewPasswordSaved;
            }
            return(View("Security"));
        }
Esempio n. 3
0
        public void PasswordsNoMatch()
        {
            var edit = new UserEditSecurity();

            edit.NewPassword       = "******";
            edit.NewPasswordRetype = "blah";
            Assert.IsFalse(edit.NewPasswordsMatch());
        }
Esempio n. 4
0
        public void PasswordsMatch()
        {
            var edit = new UserEditSecurity();

            edit.NewPassword       = "******";
            edit.NewPasswordRetype = "blah";
            Assert.IsTrue(edit.NewPasswordsMatch());
        }