Prevent 500s when trying to access api with key=null

This commit is contained in:
int2001
2026-01-04 15:48:44 +00:00
parent 99c813bc7b
commit f00ba98865
2 changed files with 9 additions and 9 deletions

View File

@@ -204,9 +204,9 @@ class API extends CI_Controller {
}
}
function check_auth($key) {
function check_auth($key = '') {
$this->load->model('api_model');
if($this->api_model->access($key) == "No Key Found" || $this->api_model->access($key) == "Key Disabled") {
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");
@@ -222,7 +222,7 @@ class API extends CI_Controller {
// 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)]);
echo json_encode(['status' => 'valid', 'rights' => $this->api_model->access($key ?? '')]);
}
}

View File

@@ -34,7 +34,7 @@ class API_Model extends CI_Model {
return $this->db->query($sql, $binding);
}
function key_description($key) {
function key_description($key = '') {
$this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->where('key', $key);
$query = $this->db->get('api');
@@ -42,14 +42,14 @@ class API_Model extends CI_Model {
return $query->result_array()[0];
}
function key_userid($key) {
function key_userid($key = '') {
$this->db->where('key', $key);
$query = $this->db->get('api');
return $query->result_array()[0]['user_id'];
}
function key_created_by($key) {
function key_created_by($key = '') {
$this->db->where('key', $key);
$query = $this->db->get('api');
@@ -68,7 +68,7 @@ class API_Model extends CI_Model {
}
function delete_key($key) {
function delete_key($key = '') {
$this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->where('key', xss_clean($key));
$this->db->delete('api');
@@ -95,7 +95,7 @@ class API_Model extends CI_Model {
}
}
function access($key) {
function access($key = '') {
// No key = no access, mate
if (!$key) {
@@ -119,7 +119,7 @@ class API_Model extends CI_Model {
}
}
function authorize($key) {
function authorize($key = '') {
$r = $this->access($key);
if ($r == "rw") {
return 2;