Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Nov 8, 2023
1 parent 0974857 commit 6db9886
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions www/controllers/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct()
*/
if ($_SERVER['REQUEST_METHOD'] != 'GET' and $_SERVER['REQUEST_METHOD'] != 'POST' and $_SERVER['REQUEST_METHOD'] != 'PUT' and $_SERVER['REQUEST_METHOD'] != 'DELETE') {
http_response_code(405);
echo json_encode(["return" => "405", "message_error" => array('Method not allowed.')]);
echo json_encode(["return" => "405", "message_error" => array('Method not allowed')]);
exit;
}

Expand All @@ -38,9 +38,17 @@ public function __construct()
$this->method = $_SERVER['REQUEST_METHOD'];

/**
* Retrieve JSON data if any
* Retrieve data if any
*/
$this->data = json_decode(file_get_contents("php://input"));
$this->data = file_get_contents("php://input");

if (!empty($this->data)) {
$this->data = json_decode($this->data);

if ($this->data == null) {
self::returnError(400, 'Invalid JSON data');
}
}

/**
* Retrieve authentication header if any
Expand Down Expand Up @@ -107,7 +115,7 @@ public function __construct()
* Check if authentication is valid
* It can be an API key authentication or a host authId+token authentication
*/
public function authenticate(string $authHeader = null, object $data = null)
public function authenticate(string $authHeader = null, string|object $data = null)
{
/**
* New authentication method
Expand Down

0 comments on commit 6db9886

Please sign in to comment.