From 0551fa03cb08f8e386d02fba76244351d7ffb948 Mon Sep 17 00:00:00 2001 From: David Connelly Date: Tue, 15 Jun 2021 11:22:53 +0100 Subject: [PATCH] I totally know what I'm doing. --- config/config.php | 2 +- config/database.php | 3 +- engine/Api.php | 4 - engine/tg_helpers/form_helper.php | 10 +- modules/books/api/controllers/Api.php | 22 --- modules/books/assets/api.json | 117 ------------- modules/books/authors/assets/api.json | 104 ------------ modules/books/authors/controllers/Authors.php | 13 -- modules/books/controllers/Books.php | 25 --- modules/books/views/create.php | 5 - modules/comments/controllers/Comments.php | 155 ------------------ 11 files changed, 3 insertions(+), 457 deletions(-) delete mode 100644 modules/books/api/controllers/Api.php delete mode 100644 modules/books/assets/api.json delete mode 100644 modules/books/authors/assets/api.json delete mode 100644 modules/books/authors/controllers/Authors.php delete mode 100644 modules/books/controllers/Books.php delete mode 100644 modules/books/views/create.php delete mode 100644 modules/comments/controllers/Comments.php diff --git a/config/config.php b/config/config.php index 097efddb..e1a15822 100644 --- a/config/config.php +++ b/config/config.php @@ -15,7 +15,7 @@ */ //The main config file -define('BASE_URL', 'http://localhost/trongate-framework/'); +define('BASE_URL', ''); define('ENV', 'dev'); define('DEFAULT_MODULE', 'welcome'); define('DEFAULT_CONTROLLER', 'Welcome'); diff --git a/config/database.php b/config/database.php index 277e2b62..f7441d63 100644 --- a/config/database.php +++ b/config/database.php @@ -3,5 +3,4 @@ define('HOST', 'localhost'); define('USER', 'root'); define('PASSWORD', ''); -define('DATABASE', 'aaadelete'); -define('DEBUG', false); \ No newline at end of file +define('DATABASE', ''); \ No newline at end of file diff --git a/engine/Api.php b/engine/Api.php index 5781308c..31008ced 100644 --- a/engine/Api.php +++ b/engine/Api.php @@ -491,11 +491,7 @@ function explorer() { die(); } -<<<<<<< HEAD $this->module('trongate_security'); -======= - $this->module('security'); ->>>>>>> 83c72b472e98e44f2274d084f5e5919e6b4656b2 $target_module = segment(3); $this->_make_sure_table_exists($target_module); $this->module('trongate_tokens'); diff --git a/engine/tg_helpers/form_helper.php b/engine/tg_helpers/form_helper.php index 4119dc25..3a7c83dd 100644 --- a/engine/tg_helpers/form_helper.php +++ b/engine/tg_helpers/form_helper.php @@ -223,11 +223,7 @@ function form_file_select($name, $attributes=NULL, $additional_code=NULL) { return $html; } -<<<<<<< HEAD function post($field_name, $clean_up=NULL) { -======= -function input($field_name, $clean_up=NULL) { ->>>>>>> 83c72b472e98e44f2274d084f5e5919e6b4656b2 if (!isset($_POST[$field_name])) { $value = ''; } else { @@ -240,8 +236,4 @@ function input($field_name, $clean_up=NULL) { } return $value; -<<<<<<< HEAD -} -======= -} ->>>>>>> 83c72b472e98e44f2274d084f5e5919e6b4656b2 +} \ No newline at end of file diff --git a/modules/books/api/controllers/Api.php b/modules/books/api/controllers/Api.php deleted file mode 100644 index 498e74b0..00000000 --- a/modules/books/api/controllers/Api.php +++ /dev/null @@ -1,22 +0,0 @@ -parent_module = 'books'; - $this->child_module = 'api'; - } - - function hello() { - echo 'hello from api'; - } - - function goodbye($output) { - echo 'goodbye from API'; - } - - function __destruct() { - $this->parent_module = ''; - $this->child_module = ''; - } - -} \ No newline at end of file diff --git a/modules/books/assets/api.json b/modules/books/assets/api.json deleted file mode 100644 index 59a85264..00000000 --- a/modules/books/assets/api.json +++ /dev/null @@ -1,117 +0,0 @@ -{ - "Custom": { - "url_segments": "books-api/hello", - "request_type": "GET", - "description": "Fetch rows from table", - "enableParams": true, - "authorization":{ - "roles": [ - "admin" - ] - }, - "afterHook":"books/goodbye" - }, - "Get": { - "url_segments": "books-api/hello", - "request_type": "GET", - "description": "Fetch rows from table", - "enableParams": true, - "authorization":{ - "roles": [ - "admin" - ] - }, - "afterHook":"goodbye" - }, - "Get By Post": { - "url_segments": "api/get/books", - "request_type": "POST", - "description": "Fetch rows from table using POST request.", - "enableParams": true, - "authorization":{ - "roles": [ - "admin" - ] - } - }, - "Find One": { - "url_segments": "api/get/books/{id}", - "request_type": "GET", - "description": "Fetch one row", - "required_fields": [ - { - "name": "id", - "label": "ID" - } - ] - }, - "Exists": { - "url_segments": "api/exists/books/{id}", - "request_type": "GET", - "description": "Check if instance exists", - "required_fields": [ - { - "name": "id", - "label": "ID" - } - ] - }, - "Count": { - "url_segments": "api/count/books", - "request_type": "GET", - "description": "Count number of records", - "enableParams": true - }, - "Count By Post": { - "url_segments": "api/count/books", - "request_type": "POST", - "description": "Count number of records using POST request", - "enableParams": true, - "authorization":{ - "roles": [ - "admin" - ] - } - }, - "Create": { - "url_segments": "api/create/books", - "request_type": "POST", - "description": "Insert database record", - "enableParams": true - }, - "Insert Batch": { - "url_segments": "api/batch/books", - "request_type": "POST", - "description": "Insert multiple records", - "enableParams": true - }, - "Update": { - "url_segments": "api/update/books/{id}", - "request_type": "PUT", - "description": "Update a database record", - "enableParams": true, - "required_fields": [ - { - "name": "id", - "label": "ID" - } - ] - }, - "Destroy": { - "url_segments": "api/destroy/books", - "request_type": "DELETE", - "description": "Delete row or rows", - "enableParams": true - }, - "Delete One": { - "url_segments": "api/delete/books/{id}", - "request_type": "DELETE", - "description": "Delete one row", - "required_fields": [ - { - "name": "id", - "label": "ID" - } - ] - } -} \ No newline at end of file diff --git a/modules/books/authors/assets/api.json b/modules/books/authors/assets/api.json deleted file mode 100644 index e2691aa5..00000000 --- a/modules/books/authors/assets/api.json +++ /dev/null @@ -1,104 +0,0 @@ -{ - "Get": { - "url_segments": "api/get/authors", - "request_type": "GET", - "description": "Fetch rows from table", - "enableParams": true, - "authorization":{ - "roles": [ - "admin" - ] - } - }, - "Get By Post": { - "url_segments": "api/get/authors", - "request_type": "POST", - "description": "Fetch rows from table using POST request.", - "enableParams": true, - "authorization":{ - "roles": [ - "admin" - ] - } - }, - "Find One": { - "url_segments": "api/get/authors/{id}", - "request_type": "GET", - "description": "Fetch one row", - "required_fields": [ - { - "name": "id", - "label": "ID" - } - ] - }, - "Exists": { - "url_segments": "api/exists/authors/{id}", - "request_type": "GET", - "description": "Check if instance exists", - "required_fields": [ - { - "name": "id", - "label": "ID" - } - ] - }, - "Count": { - "url_segments": "api/count/authors", - "request_type": "GET", - "description": "Count number of records", - "enableParams": true - }, - "Count By Post": { - "url_segments": "api/count/authors", - "request_type": "POST", - "description": "Count number of records using POST request", - "enableParams": true, - "authorization":{ - "roles": [ - "admin" - ] - } - }, - "Create": { - "url_segments": "api/create/authors", - "request_type": "POST", - "description": "Insert database record", - "enableParams": true - }, - "Insert Batch": { - "url_segments": "api/batch/authors", - "request_type": "POST", - "description": "Insert multiple records", - "enableParams": true - }, - "Update": { - "url_segments": "api/update/authors/{id}", - "request_type": "PUT", - "description": "Update a database record", - "enableParams": true, - "required_fields": [ - { - "name": "id", - "label": "ID" - } - ] - }, - "Destroy": { - "url_segments": "api/destroy/authors", - "request_type": "DELETE", - "description": "Delete row or rows", - "enableParams": true - }, - "Delete One": { - "url_segments": "api/delete/authors/{id}", - "request_type": "DELETE", - "description": "Delete one row", - "required_fields": [ - { - "name": "id", - "label": "ID" - } - ] - } -} \ No newline at end of file diff --git a/modules/books/authors/controllers/Authors.php b/modules/books/authors/controllers/Authors.php deleted file mode 100644 index 0b1b505e..00000000 --- a/modules/books/authors/controllers/Authors.php +++ /dev/null @@ -1,13 +0,0 @@ -parent_module = 'books'; - $this->child_module = 'authors'; - } - - function hello() { - echo 'hello from authors'; - } - -} \ No newline at end of file diff --git a/modules/books/controllers/Books.php b/modules/books/controllers/Books.php deleted file mode 100644 index 73cfb705..00000000 --- a/modules/books/controllers/Books.php +++ /dev/null @@ -1,25 +0,0 @@ -model->get('id'); - //var_dump($rows); - } - - function goodbye($output) { - echo 'goodbye from books'; - return $output; - } - - function create() { - $this->view('create'); - } - - function submit() { - $username = input('username', true); - $username = str_replace(' ', '[SPACE]', $username); - echo $username; - } - -} \ No newline at end of file diff --git a/modules/books/views/create.php b/modules/books/views/create.php deleted file mode 100644 index 8276e5eb..00000000 --- a/modules/books/views/create.php +++ /dev/null @@ -1,5 +0,0 @@ -module('trongate_tokens'); - $token = $input['token']; - $user = $this->trongate_tokens->_fetch_token_obj($token); - - $input['params']['user_id'] = $user->user_id; - $input['params']['date_created'] = time(); - $input['params']['code'] = make_rand_str(6); - - return $input; - } - - function _prep_comments($output) { - //return comments with nicely formatted date - $body = $output['body']; - - $comments = json_decode($body); - $data = []; - foreach ($comments as $key=>$value) { - - $row_data['comment'] = nl2br($value->comment); - $row_data['date_created'] = date('l jS \of F Y \a\t h:i:s A', $value->date_created); - $row_data['user_id'] = $value->user_id; - $row_data['target_table'] = $value->target_table; - $row_data['update_id'] = $value->update_id; - $row_data['code'] = $value->code; - $data[] = $row_data; - - } - - $output['body'] = json_encode($data); - return $output; - } - - function _display_comments_block($token) { - $target_table = segment(1); - $update_id = segment(3); - $data['target_table'] = $target_table; - $data['update_id'] = $update_id; - $data['token'] = $token; - $this->view('comments_block', $data); - } - - function submit() { - - $post = file_get_contents('php://input'); - $decoded = json_decode($post, true); - - $token = $decoded['token']; - $data['comment'] = $decoded['comment']; - $data['target_table'] = $decoded['target_table']; - $data['update_id'] = $decoded['update_id']; - $data['date_created'] = time(); - - $this->module('trongate_tokens'); - $token_obj = $this->trongate_tokens->_fetch_token_obj($token); - - if ($token_obj == false) { - die(); //invalid token - } else { - - $data['code'] = make_rand_str(6); - $information = json_decode($token_obj->information); - $data['user_id'] = $token_obj->user_id; - - if (isset($information->tables)) { - $tables = get_object_vars($information->tables); - - if (isset($tables['comments'])) { - $table_permissions = $tables['comments']; - - if (($table_permissions == '*') || ($table_permissions == 'w')) { - //we have permission to insert this comment - let's do it! - $this->model->insert($data, 'comments'); - - //let's now refresh the token so that it cannot be reused - $new_token = $this->_refresh_token($token_obj->token); - echo $new_token; - - } - } - - } - - } - - } - - function _refresh_token($old_token) { - //generate a new token string - $this->module('trongate_tokens'); - $data['old_token'] = $old_token; - $data['token'] = $this->trongate_tokens->_generate_rand_str(); - $data['expiry_date'] = $this->_calc_expiry_date(); - $sql = 'update trongate_tokens set token = :token, expiry_date = :expiry_date where token = :old_token'; - $this->model->query_bind($sql, $data); - return $data['token']; - } - - function _calc_expiry_date() { - $expiry_date = time()+3600; //token expires in one hour - return $expiry_date; - } - - function _insert_comment($comment) { - $data['comment'] = $comment; - $data['date_created'] = time(); - $this->model->insert($data, 'comments'); - echo 'Finished.'; - } - - function get() { - $post = file_get_contents('php://input'); - $decoded = json_decode($post, true); - $token = $decoded['token']; - - $this->module('trongate_tokens'); - $token_obj = $this->trongate_tokens->_fetch_token_obj($token); - - if ($token_obj == false) { - die(); //invalid token - } else { - - $information = json_decode($token_obj->information); - - if (isset($information->tables)) { - $tables = get_object_vars($information->tables); - - if (isset($tables['comments'])) { - $table_permissions = $tables['comments']; - - $sql = 'select * from comments where target_table = :target_table and update_id = :update_id order by date_created'; - $query_data['target_table'] = $decoded['target_table']; - $query_data['update_id'] = $decoded['update_id']; - $comments = $this->model->query_bind($sql, $query_data, 'object'); - - foreach ($comments as $comment) { - $row_data['comment'] = $comment->comment; - $row_data['date_created'] = date('l jS \of F Y \a\t h:i:s A', $comment->date_created); - $data[] = $row_data; - } - - echo json_encode($data); - } - - } - - } - } - -} \ No newline at end of file