public IActionResult ChangePassword(string id) { var model = new ChangePasswordViewModel { ClassRoom = id }; return View(model); }
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.SignInAsync(user, isPersistent: false); _logger.LogInformation(3, "User changed their password successfully."); if (string.IsNullOrEmpty(model.ClassRoom)) return RedirectToAction(nameof(Index), new { Message = ManageMessageId.ChangePasswordSuccess }); else { var redirectURL = $"/my#!/app/course/{ model.ClassRoom }/setting"; return Redirect(redirectURL); } } AddErrors(result); return View(model); } return RedirectToAction(nameof(Index), new { Message = ManageMessageId.Error }); }
public async Task<IActionResult> ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { return View(model); } var user = await GetCurrentUserAsync(); var redirectURL = string.Format("/My#/app/course/{0}/setting", model.ClassRoom); if (user != null) { var result = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent: false); _logger.LogInformation(3, "User changed their password successfully."); return Redirect(redirectURL); } AddErrors(result); return View(model); } return Redirect(redirectURL); }