コード例 #1
0
        public async Task <IActionResult> Login(LoginInputModel loginModel)
        {
            if (await _userQuery.CanUserLogin(loginModel.UserName, loginModel.Password))
            {
                var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
                identity.AddClaim(new Claim(ClaimTypes.Name, loginModel.UserName));

                ClaimsPrincipal principal = new ClaimsPrincipal(identity);
                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

                //Just redirect to our index after logging in.
                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }