Beispiel #1
0
        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = AuthServiceClient.ChangePassword(User.Identity.Name, model.NewPassword);

            if (result)
            {
                return(RedirectToAction("PasswordChanged", "Account"));
            }

            AddErrors(new IdentityResult(new string[] { "The password could not be changed. Please try again." }));
            return(View(model));
        }
        private void btnChangePassword_Click(object sender, RoutedEventArgs e)
        {
            //verify all fields are filled out
            string username = this.txtUsername.Text;
            string oldPassword = this.txtOldPassword.Password;
            string newPassword = this.txtNewPassword.Password;
            string confirmPassword = this.txtConfirmPassword.Password;

            if (String.IsNullOrWhiteSpace(username))
            {
                SetMessageLabel("Username cannot be blank.");
                return;
            }

            if (String.IsNullOrWhiteSpace(oldPassword))
            {
                SetMessageLabel("Current password cannot be blank");
            }

            AuthService.AuthServiceClient client = new AuthServiceClient();

            ChangePasswordResponse response = client.ChangePassword(new ChangePasswordRequest(username, oldPassword, newPassword, confirmPassword));

            //if successfully, go back
            if (response.ChangePasswordResult.success)
            {
                ClearMessageLabel();

                NavigationService.GetNavigationService(this).GoBack();
            }
            else
            {
                SetMessageLabel("Change Password failed");
            }

            //if not, display error message
        }