Esempio n. 1
0
        public async Task <IActionResult> AuthenticateUser([FromBody] AuthenticateAdminUserDto dto)
        {
            var isAuthenticated = await _adminUserService.AuthenticateUserAsync(dto);

            if (!isAuthenticated)
            {
                return(new JsonResult(new ErrorDto("Invalid credentials"))
                {
                    StatusCode = StatusCodes.Status401Unauthorized
                });
            }

            var token = _tokenService.GenerateAdminToken(dto.Username);

            return(new JsonResult(new TokenDto(token)));
        }