public async Task <ActionResult> MigrationNewPassword(ResetPasswordViewModel model) { if (null == Session["PasswordError"]) { return(View("Error")); } if (ModelState.IsValid) { com.GreenThumb.BusinessObjects.User oldUser = (com.GreenThumb.BusinessObjects.User)Session["MigrationNewPassword"]; if (null != oldUser) { var user = new ApplicationUser { UserName = model.UserName, Email = oldUser.EmailAddress, FirstName = oldUser.FirstName, LastName = oldUser.LastName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, user.FirstName)); UserManager.AddClaim(user.Id, new Claim(ClaimTypes.Surname, user.LastName)); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); if (!new UserManager().EditPasssword(user.UserName, RetrievePasswordErrorValue("OldValue"), model.Password)) { ModelState.AddModelError("", "Error changing password in database."); return(View(model)); } Session.Remove("MigrationNewPassword"); Session.Remove("PasswordError"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } else { ModelState.AddModelError("", "Previous information could not be found."); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult MigrationNewPassword() { if (null != Session["MigrationNewPassword"]) { com.GreenThumb.BusinessObjects.User oldUser = (com.GreenThumb.BusinessObjects.User)Session["MigrationNewPassword"]; var model = new ResetPasswordViewModel() { UserName = oldUser.UserName }; ViewBag.PasswordError = RetrievePasswordErrorValue("ErrorMessage"); return(View(model)); } return(View("Error")); }
public async Task <ActionResult> MigrateUser(ReRegisterViewModel model) { if (ModelState.IsValid) { var userManager = new UserManager(); bool flag = userManager.ConfirmUserInfo(model.UserName, model.Email, model.Password); if (flag) { com.GreenThumb.BusinessObjects.User oldUser = null; try { oldUser = userManager.GetUserByUserName(model.UserName); } catch (Exception) { return(View("Error")); } if (null != oldUser) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, FirstName = oldUser.FirstName, LastName = oldUser.LastName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, user.FirstName)); UserManager.AddClaim(user.Id, new Claim(ClaimTypes.Surname, user.LastName)); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); Session.Remove("MigrateUser"); return(RedirectToAction("Index", "Home")); } AddErrors(result); if (result.Errors.Any(c => c.Contains("Passwords")) && 1 == result.Errors.Count()) // If the only error is invalid password, redirect to password change... { Session.Add("MigrationNewPassword", oldUser); Session.Add("PasswordError", new { OldValue = model.Password, ErrorMessage = result.Errors.ElementAt(0) }); Session.Remove("MigrateUser"); return(RedirectToAction("MigrationNewPassword", "Account")); } } else { ModelState.AddModelError("", "Information could not be retrieved."); } } else { ModelState.AddModelError("", "Information was not correct."); } } ViewBag.UserName = model.UserName; // If we got this far, something failed, redisplay form return(View(model)); }