From d05717c1e6638564a5091d7c067a04d52c9cd007 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Fri, 21 Jun 2019 21:33:21 +0100 Subject: [PATCH] You can now delete API keys via /api/help --- application/controllers/Api.php | 14 ++++++++++++++ application/models/Api_model.php | 2 +- application/views/api/help.php | 12 ++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 126bdfef..c7592110 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -69,6 +69,20 @@ class API extends CI_Controller { redirect('api/help'); } + function delete($key) { + $this->load->model('user_model'); + if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } + + + $this->load->model('api_model'); + + $this->api_model->delete_key($key); + + $this->session->set_flashdata('notice', 'API Key '.$key." has been deleted"); + + redirect('api/help'); + } + // Example of authing function auth($key) { $this->load->model('api_model'); diff --git a/application/models/Api_model.php b/application/models/Api_model.php index 08946a21..4c41b8b2 100644 --- a/application/models/Api_model.php +++ b/application/models/Api_model.php @@ -20,7 +20,7 @@ class API_Model extends CI_Model { } function delete_key($key) { - $this->db->where('id', $key); + $this->db->where('key', $key); $this->db->delete('api'); } // Generate API Key diff --git a/application/views/api/help.php b/application/views/api/help.php index c49c3604..52a6cbde 100644 --- a/application/views/api/help.php +++ b/application/views/api/help.php @@ -2,9 +2,9 @@
session->flashdata('notice')) { ?> -
- session->flashdata('notice'); ?> -
+
@@ -43,7 +43,11 @@ ?> - status); ?> Test + status); ?> + Test + + Delete +