public async Task <IActionResult> OnPostAsync(string returnUrl = null) { var ban = await _banServices.CheckIfUserIsBanned(Input.UserName); if (ban != null) { var expDate = ban.ExpirationDate; if (expDate != null) { if (expDate > DateTime.UtcNow) { ModelState.AddModelError(string.Empty, $" !!!Your account is banned till: {expDate}{Environment.NewLine} Ban description: \"{ban.Description}\""); return(Page()); } } } var cancelation = await _userServices.CheckIfUserIsCanceled(Input.UserName); if (cancelation != null) { if (cancelation.IsCancelled == true) { ModelState.AddModelError(string.Empty, $"Your account was canceled... "); return(Page()); } } 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 result = await _signInManager.PasswordSignInAsync(Input.UserName, Input.Password, Input.RememberMe, lockoutOnFailure : true); if (result.Succeeded) { _logger.LogInformation("User logged in."); return(LocalRedirect(returnUrl)); } if (result.RequiresTwoFactor) { return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning("User account locked out."); return(RedirectToPage("./Lockout")); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(Page()); } } // If we got this far, something failed, redisplay form return(Page()); }