Example #1
0
        public async Task<ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            ViewBag.ManageNavigationKey = "Password";

            if (!ModelState.IsValid)
                return View(model);

            var result = await _userManager.ChangePasswordAsync(_userContext.CurrentUser.Id, model.OldPassword, model.NewPassword);
            if (result.Succeeded)
            {
                var user = await _userManager.FindByIdAsync(User.Identity.GetUserId().ParseGuid());
                if (user != null)
                    await _signInManager.SignInAsync(user, false, false);

                AddSuccessMessage("Your password was successfully changed.");
            }
            else
                foreach (var error in result.Errors)
                    AddErrorMessage(error);

            return View(model);
        }
Example #2
0
 public async Task<ActionResult> ChangePassword(ChangePasswordViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var result = await _userManager.ChangePasswordAsync(User.Identity.GetUserId().ParseGuid(), model.OldPassword, model.NewPassword);
     if (result.Succeeded)
     {
         var user = await _userManager.FindByIdAsync(User.Identity.GetUserId().ParseGuid());
         if (user != null)
         {
             await _signInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
         }
         return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess });
     }
     AddErrors(result);
     return View(model);
 }