Пример #1
0
        public async Task <IActionResult> Login([FromBody] LoginCredentials creds)
        {
            if (!ValidateLogin(creds))
            {
                return(Json(new
                {
                    error = "Login failed"
                }));
            }

            var principal = GetPrincipal(creds, Startup.CookieAuthScheme);

            await HttpContext.SignInAsync(Startup.CookieAuthScheme, principal);

            return(Json(new
            {
                name = principal.Identity.Name,
                email = principal.FindFirstValue(ClaimTypes.Email),
                role = principal.FindFirstValue(ClaimTypes.Role)
            }));
        }