Skip to content

Commit 8a8657b

Browse files
Merge pull request chriskacerguis#677 from teabrg/master
Check if API KEY submitted is activated
2 parents 5aaef2c + 3f3c0fe commit 8a8657b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

application/libraries/REST_Controller.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,16 @@ protected function _detect_api_key()
999999
// Find the key from server or arguments
10001000
if (($key = isset($this->_args[$api_key_variable]) ? $this->_args[$api_key_variable] : $this->input->server($key_name)))
10011001
{
1002-
if ( ! ($row = $this->rest->db->where($this->config->item('rest_key_column'), $key)->get($this->config->item('rest_keys_table'))->row()))
1002+
//if you have a field to check if the API KEY provided by the user is activated or not
1003+
//(in case you quickly want to deactivate specific users)
1004+
// you can also perform an extra check for this
1005+
1006+
$existsactive = $this->db->query("SELECT api_key_activated FROM api_keys WHERE api_key = '".$key."' ");
1007+
// Using the Query builder method. This will only work if you have a column named activated in the api_key table.
1008+
//If you also want to add this as a config item replace the get('activated') with $this->config->item('rest_key_activated_column').
1009+
$existsactive = $this->rest->db->where($this->config->item('rest_key_column'), $key)->get('activated')->result();
1010+
$isactive = $existsactive->result();
1011+
if ( ! ($row = $this->rest->db->where($this->config->item('rest_key_column'), $key)->get($this->config->item('rest_keys_table'))->row() ) || $isactive[0]->api_key_activated == 'no' )
10031012
{
10041013
return FALSE;
10051014
}

0 commit comments

Comments
 (0)