public async Task<ActionResult> ChangePassword(ChangePasswordViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId<int>(), model.OldPassword, model.NewPassword);
     if (result.Succeeded)
     {
         var user = await UserManager.FindByIdAsync(User.Identity.GetUserId<int>());
         if (user != null)
         {
             await SignInAsync(user, isPersistent: false);
         }
         return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess });
     }
     AddErrors(result);
     return View(model);
 }
예제 #2
0
 public async Task<ActionResult> ChangePassword(ChangePasswordViewModel model)
 {
     if (ModelState.IsValid)
     {
         IdentityResult 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 SignInAsync(user, isPersistent: false);
             }
             return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess });
         }
         AddErrors(result);
     }
     // If we got this far, something failed, redisplay form
     return View(model);
 }
예제 #3
0
 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)
         {
             HttpContext.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);
             HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties { IsPersistent = false }, await user.GenerateUserIdentityAsync(UserManager));
         }
         return RedirectToAction("ChangePersonalData", new { Message = "Password changed successfully." });
     }
     ModelState.AddModelError("", result.Errors.First());
     return View(model);
 }
예제 #4
0
 public async Task<IActionResult> ChangePassword(ChangePasswordViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var user = await GetCurrentUserAsync();
     if (user != null)
     {
         var result = await UserManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);
         if (result.Succeeded)
         {
             await SignInManager.RefreshSignInAsync(user);
             return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess });
         }
         AddErrors(result);
         return View(model);
     }
     return RedirectToAction("Index", new { Message = ManageMessageId.Error });
 }