Пример #1
0
        private ActionResult ChangePassword(bool mustChange, ChangePasswordModel changePassword)
        {
            changePassword.MustChange      = mustChange;
            changePassword.IsAdministrator = CurrentRegisteredUser.UserType == UserType.Administrator;

            try
            {
                // Make sure everything is in order.

                changePassword.Validate();

                // Check the current credentials.

                var userId      = CurrentRegisteredUser.Id;
                var loginId     = _loginCredentialsQuery.GetLoginId(userId);
                var credentials = new LoginCredentials {
                    LoginId = loginId, Password = changePassword.Password
                };

                var result = _loginAuthenticationCommand.AuthenticateUser(credentials);
                switch (result.Status)
                {
                case AuthenticationStatus.Failed:
                    throw new AuthenticationFailedException();
                }

                // Check that the password has been changed.

                if (changePassword.Password == changePassword.NewPassword)
                {
                    throw new ValidationErrorsException(new NotChangedValidationError("Password", ""));
                }

                // Change it.

                _loginCredentialsCommand.ChangePassword(userId, credentials, changePassword.NewPassword);

                // Redirect.

                return(RedirectToUrlWithConfirmation(HttpContext.GetReturnUrl(), "Your password has been changed."));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(View("ChangePassword", changePassword));
        }
Пример #2
0
        public ActionResult ChangePassword(ChangePasswordModel changePassword)
        {
            try
            {
                // Make sure everything is in order.

                changePassword.Validate();

                // Check the passed-in credentials.

                var credentials = new LoginCredentials {
                    LoginId = changePassword.LoginId, Password = changePassword.Password
                };

                var result = _loginAuthenticationCommand.AuthenticateUser(credentials);
                if (result.Status == AuthenticationStatus.Failed)
                {
                    throw new AuthenticationFailedException();
                }

                // Check that the password has been changed.

                if (changePassword.Password == changePassword.NewPassword)
                {
                    throw new ValidationErrorsException(new NotChangedValidationError("Password", ""));
                }

                // Change it.

                _loginCredentialsCommand.ChangePassword(result.User.Id, credentials, changePassword.NewPassword);
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(Json(new JsonResponseModel()));
        }