public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return View(model); } // Require the user to have a confirmed email before they can log on. var user = await UserManager.FindByNameAsync(model.Email); if (user != null) { if (!await UserManager.IsEmailConfirmedAsync(user.Id)) { ViewBag.errorMessage = "You must have a confirmed email to log on."; return View("Error"); } } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); switch (result) { case SignInStatus.Success: var User = UserManager.FindByEmail(model.Email); ViewBag.DisplayName = User.FirstName + User.LastName; if (User.HouseholdId == null) { return RedirectToAction("Create", "Households"); } return RedirectToAction("Index", "Households"); case SignInStatus.LockedOut: return View("Lockout"); case SignInStatus.RequiresVerification: return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return View(model); } }
public async Task<ActionResult> DemoLogin(LoginViewModel model, string returnUrl) { // Require the user to have a confirmed email before they can log on. var user = await UserManager.FindByNameAsync("*****@*****.**"); if (user != null) { if (!await UserManager.IsEmailConfirmedAsync(user.Id)) { ViewBag.errorMessage = "You must have a confirmed email to log on."; return View("Error"); } } var result = await SignInManager.PasswordSignInAsync("*****@*****.**", "Tota11y!", false, shouldLockout: false); switch (result) { case SignInStatus.Success: var User = UserManager.FindByEmail("*****@*****.**"); ViewBag.DisplayName = User.FirstName + User.LastName; if (User.HouseholdId == null) { return RedirectToAction("Create", "Households"); } return RedirectToAction("Index", "Households"); case SignInStatus.LockedOut: return View("Lockout"); case SignInStatus.RequiresVerification: return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return View(model); } }