public IActionResult Login(string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; var model = new LoginViewDto() { ReturnUrl = returnUrl }; return(View(model)); }
public async Task <IActionResult> Login(LoginViewDto model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = await _userManager.FindByNameAsync(model.UserName); // User is cancelled -> Go to home page. if (user != null && user.IsCancelled) { return(RedirectToAction("Index", "Home")); } // 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(model.UserName, model.Password, model.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { _logger.LogInformation(1, "User logged in."); return(RedirectToLocal(returnUrl)); } if (result.RequiresTwoFactor) { return(RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning(2, "User account locked out."); return(View("Lockout")); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View(model)); } } // If we got this far, something failed, redisplay form return(View(model)); }