Ejemplo 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
            }));
        }
Ejemplo 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"));
        }
Ejemplo n.º 3
0
        public void PasswordsNoMatch()
        {
            var edit = new UserEditSecurity();

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

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