public async Task <ActionResult> Login([FromBody] User user)
        {
            var count = usersQuery.GetAll().Where(u => u.UserName.Equals(user.UserName) && u.Password.Equals(user.Password)).ToList().Count;

            if (count == 1)
            {
                var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
                identity.AddClaim(new Claim("Name", user.UserName));
                // *** NOTE: SignInAsync is now on the HttpContext instance! ***
                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), new AuthenticationProperties()
                {
                    IsPersistent = true,
                });

                return(Ok(Task.CompletedTask));
            }
            await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

            return(Unauthorized(Task.CompletedTask));
        }
Example #2
0
        public async Task <IEnumerable <User> > GetAll()
        {
            var result = await _userQuery.GetAll();

            return(result);
        }