示例#1
0
        public async Task <IActionResult> Login([FromBody] ManagerLoginRequest login)
        {
            try
            {
                // Pull IP address from X-Forwarded-For.
                string ipAddress = HttpContext.Connection.RemoteIpAddress.ToString();

                // Attempt to perform a login, returning a ManagerLoginResponse on success
                return(Ok(await _managerService.Login(login, ipAddress)));
            }
            catch (BadLoginException)
            {
                // Error: Login credentials are invalid
                return(BadRequest(APIError.BadLogin()));
            }
            catch (Exception e)
            {
                // Error: Unknown error.
                _logger.LogError(e, "Failed to perform login for {username}", login.Username);

                return(BadRequest(APIError.UnknownError()));
            }
        }