public ActionResult FirstTimeUser() { string username = User.Identity.Name; Student studentInfo = _studentRepo.GetStudent(username); var model = new FirstTimeUserModel() { //EmailAddress = studentInfo.User.Email, ConfirmPassword = string.Empty, NewPassword = string.Empty, OldPassword = string.Empty, }; return(View(model)); }
public async Task <ActionResult> FirstTimeUser(FirstTimeUserModel model, bool?CaptchaValid) { if (CaptchaValid ?? false) { // ViewBag.ReturnUrl = Url.Action("FirstTimeUser"); if (ModelState.IsValid) { IdentityResult result = await UserManager.ChangePasswordAsync(int.Parse(User.Identity.GetUserId()), model.OldPassword, model.NewPassword); if (result.Succeeded) { var user = _coreRepository.Get <User>(int.Parse(User.Identity.GetUserId())); user.IsFirstTimeUser = false; //user.Email = model.EmailAddress; user.LastPasswordChangeDate = DateTime.Now; var update = _coreRepository.SaveOrUpdate(user); TempData[ApplicationConstants.ErrorNotification] = null; TempData[ApplicationConstants.SuccessNotification] = "Password successfully changed"; return(RedirectToAction("Index")); } foreach (string error in result.Errors) { ModelState.AddModelError("", error); } } TempData[ApplicationConstants.ErrorNotification] = "Something went wrong while changing password"; // If we got this far, something failed, redisplay form return(View(model)); } else { ModelState.AddModelError("reCaptcha", "Invalid reCaptcha"); return(View(model)); } }