public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { //check to see if the account exists var user = await _userManager.FindAsync(model.Email.TrimEnd(), model.Password); if (user != null) { //Check if the account has already had its email confirmed. In this example, the account will always be confirmed, but this is here for demonstration purposes. if (!user.IsConfirmed) { //Check to see if the token is greater than 24 hours old if ((DateTime.UtcNow - user.CreatedDate).TotalDays > 1) { //If it's expired we can send a new confirmation token. Otherwise if you prefer some other approach or logic feel free to experiment! await ResendConfirmationToken(user); ModelState.AddModelError("", "Email address has not been confirmed and has expired. A new confirmation token has been generated and sent to you."); return View(model); } //account hasn't been confirmed but it also hasn't been 24 hours, inform the user. This is also a great place to present some way the user can request a new confirmation token //or provide an update email address so that they can receive a new token if they had made a mistake. ModelState.AddModelError("", "Email address has not been confirmed. Please check your e-mail!"); return View(model); } //we're good, sign the user in await SignInAsync(user, model.RememberMe); return RedirectToLocal(returnUrl); } ModelState.AddModelError("", "Invalid UserName of Password."); } return View(model); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { //check to see if the account exists var user = await _userManager.FindAsync(model.Email.TrimEnd(), model.Password); if (user != null) { //Check if the account has already had its email confirmed. // In this example, the account will always be confirmed, but this is here for demonstration purposes. if (!user.IsConfirmed) { //Check to see if the token is greater than 24 hours old if ((DateTime.UtcNow - user.CreatedDate).TotalDays > 1) { //If it's expired we can send a new confirmation token. Otherwise if you prefer some other approach or logic feel free to experiment! await ResendConfirmationToken(user); ModelState.AddModelError("", "Email address has not been confirmed and has expired. A new confirmation token has been generated and sent to you."); return(View(model)); } //account hasn't been confirmed but it also hasn't been 24 hours, inform the user. This is also a great place to present some way the user can request a new confirmation token //or provide an update email address so that they can receive a new token if they had made a mistake. ModelState.AddModelError("", "Email address has not been confirmed. Please check your e-mail!"); return(View(model)); } //we're good, sign the user in await SignInAsync(user, model.RememberMe); return(RedirectToLocal(returnUrl)); } ModelState.AddModelError("", "Invalid UserName of Password."); } return(View(model)); }