public async Task<ActionResult> Manage(ManageUserViewModel model) { model.Email = UserManager.FindByName(User.Identity.GetUserName()).Email; bool hasPassword = HasPassword(); ViewBag.HasLocalPassword = hasPassword; ViewBag.ReturnUrl = Url.Action("Manage"); if (hasPassword) { if (ModelState.IsValid) { IdentityResult result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword); if (result.Succeeded) { return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess }); } else { AddErrors(result); } } } else { // User does not have a password so remove any validation errors caused by a missing OldPassword field ModelState state = ModelState["OldPassword"]; if (state != null) { state.Errors.Clear(); } if (ModelState.IsValid) { IdentityResult result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword); if (result.Succeeded) { return RedirectToAction("Manage", new { Message = ManageMessageId.SetPasswordSuccess }); } else { AddErrors(result); } } } // Появление этого сообщения означает наличие ошибки; повторное отображение формы return View(model); }
// // GET: /Account/Manage public ActionResult Manage(ManageMessageId? message) { ManageUserViewModel temp = new ManageUserViewModel(); temp.Email = UserManager.FindByName(User.Identity.GetUserName()).Email; ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess ? "Ваш пароль изменен." : message == ManageMessageId.SetPasswordSuccess ? "Пароль задан." : message == ManageMessageId.RemoveLoginSuccess ? "Внешнее имя входа удалено." : message == ManageMessageId.Error ? "Произошла ошибка." : ""; ViewBag.HasLocalPassword = HasPassword(); ViewBag.ReturnUrl = Url.Action("Manage"); return View(temp); }