@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param string $apiKey [description] |
96 | 96 | * @return array [description] |
97 | 97 | */ |
98 | - public function getAPIKeyData(string $apiKey):?object { |
|
98 | + public function getAPIKeyData(string $apiKey): ?object { |
|
99 | 99 | // Preliminary Check. |
100 | 100 | if ($this->api_key_table == null || $this->api_key_column == null) return null; |
101 | 101 | // Query. |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param string $group [description] |
120 | 120 | * @return [type] [description] |
121 | 121 | */ |
122 | - public function getLimitData(string $client, string $group):?array { |
|
122 | + public function getLimitData(string $client, string $group): ?array { |
|
123 | 123 | $sql = 'SELECT count, start, (`start` + INTERVAL (1 - TIMESTAMPDIFF(HOUR, UTC_TIMESTAMP(), NOW())) HOUR) AS reset_epoch FROM rest_api_rate_limit WHERE client = ? AND _group = ?'; |
124 | 124 | $query = $this->db->query($sql, [$client, $group]); |
125 | 125 | if (!is_scalar($query) && $query->num_rows() > 0) return $query->result_array()[0]; |
@@ -81,10 +81,14 @@ discard block |
||
81 | 81 | $this->db->or_where($this->users_username_column, $username); |
82 | 82 | } |
83 | 83 | $query = $this->db->get(); |
84 | - if ($query->num_rows() == 0) return false; |
|
84 | + if ($query->num_rows() == 0) { |
|
85 | + return false; |
|
86 | + } |
|
85 | 87 | // Authenticate. |
86 | 88 | if (password_verify($password, $query->result()[0]->{$this->users_password_column})) { |
87 | - if ($this->users_id_column != null) $context->userId = $query->result()[0]->{$this->users_id_column}; |
|
89 | + if ($this->users_id_column != null) { |
|
90 | + $context->userId = $query->result()[0]->{$this->users_id_column}; |
|
91 | + } |
|
88 | 92 | return true; |
89 | 93 | } |
90 | 94 | return false; |
@@ -97,7 +101,9 @@ discard block |
||
97 | 101 | */ |
98 | 102 | public function getAPIKeyData(string $apiKey):?object { |
99 | 103 | // Preliminary Check. |
100 | - if ($this->api_key_table == null || $this->api_key_column == null) return null; |
|
104 | + if ($this->api_key_table == null || $this->api_key_column == null) { |
|
105 | + return null; |
|
106 | + } |
|
101 | 107 | // Query. |
102 | 108 | $this->db->from($this->api_key_table); |
103 | 109 | $this->db->where($this->api_key_column, $apiKey); |
@@ -122,7 +128,9 @@ discard block |
||
122 | 128 | public function getLimitData(string $client, string $group):?array { |
123 | 129 | $sql = 'SELECT count, start, (`start` + INTERVAL (1 - TIMESTAMPDIFF(HOUR, UTC_TIMESTAMP(), NOW())) HOUR) AS reset_epoch FROM rest_api_rate_limit WHERE client = ? AND _group = ?'; |
124 | 130 | $query = $this->db->query($sql, [$client, $group]); |
125 | - if (!is_scalar($query) && $query->num_rows() > 0) return $query->result_array()[0]; |
|
131 | + if (!is_scalar($query) && $query->num_rows() > 0) { |
|
132 | + return $query->result_array()[0]; |
|
133 | + } |
|
126 | 134 | return null; |
127 | 135 | } |
128 | 136 | /** |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | * @param array|null $params Initialization parameters from the Slint system. |
118 | 118 | * There's no use for this arg yet. |
119 | 119 | */ |
120 | - function __construct(?array $params=null) |
|
120 | + function __construct(?array $params = null) |
|
121 | 121 | { |
122 | - $this->ci =& get_instance(); |
|
122 | + $this->ci = & get_instance(); |
|
123 | 123 | |
124 | 124 | if ($this->ci->input->is_cli_request()) return; |
125 | 125 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | |
138 | 138 | // Load Model. |
139 | 139 | $this->ci->load->splint(self::PACKAGE, '*RESTModel', 'rest_model'); |
140 | - $this->rest_model =& $this->ci->rest_model; |
|
140 | + $this->rest_model = & $this->ci->rest_model; |
|
141 | 141 | |
142 | 142 | $config = [ |
143 | 143 | 'users_table' => $this->ci->config->item('rest')['basic_auth']['users_table'] ?? null, |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | /** |
264 | 264 | * [bearer_auth description] |
265 | 265 | */ |
266 | - private function bearer_auth($auth=RESTAuth::BEARER):void { |
|
266 | + private function bearer_auth($auth = RESTAuth::BEARER):void { |
|
267 | 267 | $authorization = $this->get_authorization_header(); |
268 | 268 | if ($authorization == null || substr_count($authorization, " ") != 1) { |
269 | 269 | $this->handle_response(RESTResponse::BAD_REQUEST, $auth); // Exits. |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | } |
326 | 326 | // Should we acyually Limit? |
327 | 327 | if ($this->per_hour > 0) { |
328 | - $client = hash('md5', $this->ci->input->ip_address() . "%" . $apiKey->{$this->api_key_column}); |
|
328 | + $client = hash('md5', $this->ci->input->ip_address()."%".$apiKey->{$this->api_key_column}); |
|
329 | 329 | $limitData = $this->rest_model->getLimitData($client, '_api_keyed_user'); |
330 | 330 | if ($limitData == null) { |
331 | 331 | $limitData = []; |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | * [get_authorization_header description] |
410 | 410 | * @return [type] [description] |
411 | 411 | */ |
412 | - private function get_authorization_header():?string |
|
412 | + private function get_authorization_header(): ?string |
|
413 | 413 | { |
414 | 414 | if (isset($_SERVER['Authorization'])) { |
415 | 415 | return trim($_SERVER["Authorization"]); |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * [handle_response description] |
433 | 433 | * @param int $code [description] |
434 | 434 | */ |
435 | - private function handle_response(int $code, $auth=null):void |
|
435 | + private function handle_response(int $code, $auth = null):void |
|
436 | 436 | { |
437 | 437 | http_response_code($code); |
438 | 438 | header("Content-Type: application/json"); |