public async Task <IActionResult> Index(LoginRequest request) { if (!ModelState.IsValid) { return(View(ModelState)); } var token = await _userApi.Authenticate(request); if (token.ResultObj == null) { ModelState.AddModelError("", token.Message); return(View()); } var userPrincipal = this.ValidateToken(token.ResultObj); var authProperties = new AuthenticationProperties { ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(10), IsPersistent = false }; HttpContext.Session.SetString(SystemConstants.AppSettings.Token, token.ResultObj); await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal, authProperties); return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> Login(loginRequest request) { if (!ModelState.IsValid) { return(View(ModelState)); } var token = await _userApi.Authenticate(request); var userPrincipal = this.ValidateToken(token); var authProperties = new AuthenticationProperties { ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(10), IsPersistent = true }; await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal, authProperties); return(RedirectToAction("Login", "Home")); }