public async Task <IActionResult> Login([FromServices] AppDbContextFactory factory, AuthModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var context = factory.CreateContext()) { var IsUserValid = model.CheckUser(context, out var user); if (!IsUserValid) { ModelState.AddModelError("form", _localizer["AuthController_LoginOrPasswordNotValid"]); } if (!ModelState.IsValid) { return(View(model)); } await model.AuthAsync(HttpContext, user); } if (!String.IsNullOrWhiteSpace(model.ReturnUrl) && model.ReturnUrl != "/") { return(Redirect(model.ReturnUrl)); } return(RedirectToAction("Index", "Home")); }