[API] Add check_auth function with json output

pull/3092/head
Peter Goodhall 2024-05-04 14:00:57 +01:00
rodzic c3f8b7be72
commit b2168badd9
1 zmienionych plików z 23 dodań i 0 usunięć

Wyświetl plik

@ -127,6 +127,29 @@ class API extends CI_Controller {
}
}
function check_auth($key) {
$this->load->model('api_model');
header("Content-type: text/xml");
if($this->api_model->access($key) == "No Key Found" || $this->api_model->access($key) == "Key Disabled") {
// set the content type as json
header("Content-type: application/json");
// set the http response code to 401
http_response_code(401);
// return the json with the status as failed
echo json_encode(['status' => 'failed', 'reason' => "missing or invalid api key"]);
} else {
// set the content type as json
header("Content-type: application/json");
// set the http response code to 200
http_response_code(200);
// return the json
echo json_encode(['status' => 'valid', 'rights' => $this->api_model->access($key)]);
}
}
function station_info($key) {
$this->load->model('api_model');
$this->load->model('stations');