public async void Test_GivenAUser_WhenChangePassword_ThenResponseIsNotAltered()
        {
            userStoreMock.Setup(mock => mock.ChangePasswordAsync(It.IsAny <CognitoUser>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable();
            var output = await userManager.ChangePasswordAsync(GetCognitoUser(), "old", "new").ConfigureAwait(false);

            Assert.Equal(IdentityResult.Success, output);
            userStoreMock.Verify();
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            returnUrl = returnUrl ?? Url.Content("~/");

            var user = await _userManager.FindByEmailAsync(Input.Email);

            if (user == null)
            {
                throw new InvalidOperationException($"Unable to retrieve user.");
            }

            var result = await _userManager.ChangePasswordAsync(user, Input.CurrentPassword, Input.NewPassword);

            if (result.Succeeded)
            {
                _logger.LogInformation("Changed password for user with ID '{UserId}'.", user.UserID);
                return(LocalRedirect(returnUrl));
            }
            else
            {
                _logger.LogInformation("Unable to change password for user with ID '{UserId}'.", user.UserID);
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError(item.Code, item.Description);
                }
                return(Page());
            }
        }
        public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            IActionResult result = View(model);

            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user != null)
                {
                    var changePasswordResult = await _userManager.ChangePasswordAsync(user, model.CurrentPassword, model.NewPassword);

                    if (changePasswordResult.Succeeded)
                    {
                        TempData.Put("Dialog", new AlertViewModel(AlertType.Success, "Password changed", "Your password has been changed successfully!"));
                        result = RedirectToAction(nameof(ChangePassword));
                    }
                    else
                    {
                        foreach (var error in changePasswordResult.Errors)
                        {
                            ModelState.AddModelError(error.Code, error.Description);
                        }
                    }
                }
            }
            return(result);
        }
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess }));
            }
            AddErrors(result);
            return(View(model));
        }