public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var userName = Input.Email; if (IsValidEmail(Input.Email)) { var userCheck = await _userManager.FindByEmailAsync(Input.Email); if (userCheck != null) { userName = userCheck.UserName; } } var user = await _userManager.FindByNameAsync(userName); if (user != null) { if (!user.IsActive) { return(RedirectToPage("./Deactivated")); } else if (!user.EmailConfirmed) { Notify.AddErrorToastMessage("Email Not Confirmed."); ModelState.AddModelError(string.Empty, "Email Not Confirmed."); return(Page()); } else { var result = await _signInManager.PasswordSignInAsync(userName, Input.Password, Input.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { _logger.LogInformation("User logged in."); Notify.AddSuccessToastMessage($"Logged in as {userName}."); return(LocalRedirect(returnUrl)); } if (result.RequiresTwoFactor) { return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe })); } if (result.IsLockedOut) { Notify.AddWarningToastMessage("User account locked out."); _logger.LogWarning("User account locked out."); return(RedirectToPage("./Lockout")); } else { Notify.AddErrorToastMessage("Invalid login attempt."); ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(Page()); } } } else { Notify.AddErrorToastMessage("Email / Username Not Found."); ModelState.AddModelError(string.Empty, "Email / Username Not Found."); } } // If we got this far, something failed, redisplay form return(Page()); }