Cleaned up formatting of api model
这个提交包含在:
父节点
1729aaaa69
当前提交
6bffd4a1c1
共有 1 个文件被更改,包括 74 次插入 和 78 次删除
|
|
@ -6,21 +6,25 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class API_Model extends CI_Model {
|
||||
class API_Model extends CI_Model
|
||||
{
|
||||
|
||||
// GET API Keys
|
||||
function keys() {
|
||||
function keys()
|
||||
{
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
return $this->db->get('api');
|
||||
}
|
||||
|
||||
function CountKeysWithNoUserID() {
|
||||
function CountKeysWithNoUserID()
|
||||
{
|
||||
$this->db->where('user_id =', NULL);
|
||||
$query = $this->db->get('api');
|
||||
return $query->num_rows();
|
||||
}
|
||||
|
||||
function ClaimAllAPIKeys($id = NULL) {
|
||||
function ClaimAllAPIKeys($id = NULL)
|
||||
{
|
||||
// if $id is empty then use session user_id
|
||||
if (empty($id)) {
|
||||
// Get the first USER ID from user table in the database
|
||||
|
|
@ -34,7 +38,8 @@ class API_Model extends CI_Model {
|
|||
$this->db->update('api', $data);
|
||||
}
|
||||
|
||||
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 +47,16 @@ 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 update_key_description($key, $description) {
|
||||
function update_key_description($key, $description)
|
||||
{
|
||||
|
||||
$data = array(
|
||||
'description' => xss_clean($description),
|
||||
|
|
@ -58,17 +65,18 @@ class API_Model extends CI_Model {
|
|||
$this->db->where('key', xss_clean($key));
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->update('api', xss_clean($data));
|
||||
|
||||
}
|
||||
|
||||
|
||||
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');
|
||||
}
|
||||
// Generate API Key
|
||||
function generate_key($rights) {
|
||||
function generate_key($rights)
|
||||
{
|
||||
|
||||
// Expects either rw (Read, Write) or r (read only)
|
||||
|
||||
|
|
@ -83,10 +91,10 @@ class API_Model extends CI_Model {
|
|||
$data['user_id'] = $this->session->userdata('user_id');
|
||||
|
||||
$this->db->insert('api', $data);
|
||||
|
||||
}
|
||||
|
||||
function access($key) {
|
||||
function access($key)
|
||||
{
|
||||
// No key = no access
|
||||
if (!$key) {
|
||||
return "No Key Found";
|
||||
|
|
@ -108,18 +116,20 @@ class API_Model extends CI_Model {
|
|||
}
|
||||
}
|
||||
|
||||
function authorize($key) {
|
||||
function authorize($key)
|
||||
{
|
||||
$r = $this->access($key);
|
||||
if($r == "rw") {
|
||||
if ($r == "rw") {
|
||||
return 2;
|
||||
} else if($r == "r") {
|
||||
} else if ($r == "r") {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function update_last_used($key) {
|
||||
function update_last_used($key)
|
||||
{
|
||||
$this->db->set('last_used', 'NOW()', FALSE);
|
||||
$this->db->where('key', xss_clean($key));
|
||||
$this->db->update('api');
|
||||
|
|
@ -129,12 +139,9 @@ class API_Model extends CI_Model {
|
|||
// Converts a MySQL column name to a more friendly name
|
||||
function name($col)
|
||||
{
|
||||
if($this->_columnName[$col])
|
||||
{
|
||||
if ($this->_columnName[$col]) {
|
||||
return $this->_columnName[$col]['Name'];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -143,19 +150,13 @@ class API_Model extends CI_Model {
|
|||
// Returns the description for a MySQL column name
|
||||
function description($col)
|
||||
{
|
||||
if($this->_columnName[$col])
|
||||
{
|
||||
if($this->_columnName[$col]['Description'] != "")
|
||||
{
|
||||
if ($this->_columnName[$col]) {
|
||||
if ($this->_columnName[$col]['Description'] != "") {
|
||||
return $this->_columnName[$col]['Description'];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return "No description available";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -164,10 +165,8 @@ class API_Model extends CI_Model {
|
|||
// Converts a friendly name to a MySQL column name
|
||||
function column($name)
|
||||
{
|
||||
while ($column = current($this->_columnName))
|
||||
{
|
||||
if($this->_columnName[key($this->_columnName)]['Name'] == $name)
|
||||
{
|
||||
while ($column = current($this->_columnName)) {
|
||||
if ($this->_columnName[key($this->_columnName)]['Name'] == $name) {
|
||||
$a = key($this->_columnName);
|
||||
reset($this->_columnName);
|
||||
return $a;
|
||||
|
|
@ -303,7 +302,4 @@ class API_Model extends CI_Model {
|
|||
'COL_CREDIT_GRANTED' => array('Name' => 'UNK_CREDIT_GRANTED', 'Description' => '', 'Type' => ''),
|
||||
'COL_CREDIT_SUBMITTED' => array('Name' => 'UNK_CREDIT_SUBMITTED', 'Description' => '', 'Type' => ''),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
正在加载…
在新工单中引用