[API] Added userid to the API key.

这个提交包含在:
Andreas 2021-09-20 15:16:53 +02:00
父节点 109683e041
当前提交 30ba927c25
共有 3 个文件被更改,包括 34 次插入10 次删除

查看文件

@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE;
| |
*/ */
$config['migration_version'] = 75; $config['migration_version'] = 78;
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

查看文件

@ -0,0 +1,19 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Migration_add_userid_to_api extends CI_Migration
{
public function up()
{
$fields = array(
'user_id BIGINT(20) DEFAULT NULL',
);
$this->dbforge->add_column('api', $fields);
}
public function down()
{
$this->dbforge->drop_column('api', 'user_id');
}
}

查看文件

@ -16,11 +16,13 @@ class API_Model extends CI_Model {
// GET API Keys // GET API Keys
function keys() { function keys() {
$this->db->where('user_id', $this->session->userdata('user_id'));
return $this->db->get('api'); return $this->db->get('api');
} }
function key_description($key) { function key_description($key) {
$this->db->where('key', $key); $this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->where('key', $key);
$query = $this->db->get('api'); $query = $this->db->get('api');
return $query->result_array()[0]; return $query->result_array()[0];
@ -28,17 +30,17 @@ class API_Model extends CI_Model {
function update_key_description($key, $description) { function update_key_description($key, $description) {
$data = array( $data = array(
'description' => xss_clean($description), 'description' => xss_clean($description),
); );
$this->db->where('key', xss_clean($key)); $this->db->where('key', xss_clean($key));
$this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->update('api', xss_clean($data)); $this->db->update('api', xss_clean($data));
} }
function country_worked($dxcc_num, $band, $mode){ function country_worked($dxcc_num, $band, $mode){
if($band == "all") { if($band == "all") {
@ -93,35 +95,38 @@ 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->where('key', xss_clean($key));
$this->db->delete('api'); $this->db->delete('api');
} }
// Generate API Key // Generate API Key
function generate_key($rights) { function generate_key($rights) {
// Expects either rw (Read, Write) or r (read only) // Expects either rw (Read, Write) or r (read only)
// Generate Unique Key // Generate Unique Key
$data['key'] = uniqid("cl"); $data['key'] = uniqid("cl");
$data['rights'] = $rights; $data['rights'] = $rights;
// Set API key to active // Set API key to active
$data['status'] = "active"; $data['status'] = "active";
$this->db->insert('api', $data); $data['user_id'] = $this->session->userdata('user_id');
$this->db->insert('api', $data);
} }
function access($key) { function access($key) {
// No key = no access, mate // No key = no access, mate
if(!$key) { if(!$key) {
return $status = "No Key Found"; return $status = "No Key Found";
} }
// Check that the key is valid // Check that the key is valid
$this->db->where('key', $key); $this->db->where('key', $key);
$query = $this->db->get('api'); $query = $this->db->get('api');
if ($query->num_rows() > 0) if ($query->num_rows() > 0)
@ -334,7 +339,7 @@ class API_Model extends CI_Model {
$s[12] = '/~([a-zA-Z0-9\-\_\*\(\)\=\~]+)/'; $s[12] = '/~([a-zA-Z0-9\-\_\*\(\)\=\~]+)/';
// *, which becomes '%' // *, which becomes '%'
$s[13] = '/\*/'; $s[13] = '/\*/';
$r[0] = ' AND '; $r[0] = ' AND ';
$r[1] = ' OR '; $r[1] = ' OR ';
$r[2] = ' < '; $r[2] = ' < ';