[API] Added userid to the API key.

pull/1189/head
Andreas 2021-09-20 15:16:53 +02:00
rodzic 109683e041
commit 30ba927c25
3 zmienionych plików z 34 dodań i 10 usunięć

Wyświetl plik

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

Wyświetl plik

@ -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');
}
}

Wyświetl plik

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