Exemplo n.º 1
0
        public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await userManager.FindByIdAsync(HttpContext.User.GetUserId());

            if (user != null)
            {
                var result = await userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

                if (result.Succeeded)
                {
                    await signInManager.SignInAsync(user, isPersistent : false);

                    this.AlertSuccess("Your password has been changed.");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    this.AlertDanger("oops something went wrong please try again");
                }
                AddErrors(result);
            }

            return(View(model));
        }