From 1729aaaa69aa363aa66bb28c1e038f64bf9af617 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Thu, 21 Nov 2024 16:29:42 +0000 Subject: [PATCH] [API] Access function improved to speed function up --- application/models/Api_model.php | 42 +++++++++++++++----------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/application/models/Api_model.php b/application/models/Api_model.php index f470c713..94b2928b 100644 --- a/application/models/Api_model.php +++ b/application/models/Api_model.php @@ -86,31 +86,27 @@ class API_Model extends CI_Model { } - function access($key) { + function access($key) { + // No key = no access + if (!$key) { + return "No Key Found"; + } - // No key = no access, mate - if(!$key) { - return $status = "No Key Found"; - } + // Check that the key is valid + $this->db->where('key', $key); + $query = $this->db->get('api', 1); // Limit to 1 row for performance - // Check that the key is valid - $this->db->where('key', $key); - $query = $this->db->get('api'); - - if ($query->num_rows() > 0) - { - foreach ($query->result() as $row) - { - if($row->status == "active") { - return $status = $row->rights; - } else { - return $status = "Key Disabled"; - } - } - } else { - return $status = "No Key Found"; - } - } + if ($query->num_rows() > 0) { + $row = $query->row(); + if ($row->status == "active") { + return $row->rights; + } else { + return "Key Disabled"; + } + } else { + return "No Key Found"; + } + } function authorize($key) { $r = $this->access($key);