From 22e96cbeb2f76a82591613af56ab5f779bee9707 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Thu, 29 May 2025 10:09:38 +0200 Subject: [PATCH] Add key check --- application/controllers/Api.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 4ba1fc3b7..a6211207e 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -141,6 +141,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)]); + } + } + /* *