public async Task <ActionResult> Login(ValidateUserLogin.Query query) { if (ModelState.IsValid) { if (await _mediator.Send(query)) { var claims = new List <Claim> { new Claim(ClaimTypes.Name, query.UserName), }; var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var authProperties = new AuthenticationProperties { ExpiresUtc = DateTimeOffset.UtcNow.AddDays(30), IsPersistent = true, }; await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties); return(RedirectToAction(nameof(Index))); } else { ModelState.AddModelError("", "نام کاربری یا رمزعبور اشتباه است"); } } return(View(nameof(Index), query)); }
public ActionResult Login() { var model = new ValidateUserLogin.Query { UserName = "******", Password = "******" }; return(View(model)); }