From 688642f5eae93a4a000e509f8b20013423b69c01 Mon Sep 17 00:00:00 2001 From: Jaime Jimenez Date: Thu, 27 Apr 2023 21:53:41 +0200 Subject: [PATCH] Estudiando como implementar subfolders --- ci4/app/Config/Routes.php | 2 +- .../Impresion/{Clientes.php => Cliente.php} | 7 +- ci4/app/Controllers/Tarifas.php | 20 ++++ ci4/app/Controllers/Test.php | 110 ++++++++++-------- ci4/app/Filters/LoginAuthFilter.php | 16 ++- ci4/app/Helpers/general_helper.php | 2 + 6 files changed, 100 insertions(+), 57 deletions(-) rename ci4/app/Controllers/Impresion/{Clientes.php => Cliente.php} (71%) create mode 100644 ci4/app/Controllers/Tarifas.php diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index aa1f48d2..294e7bd2 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -28,7 +28,7 @@ $routes->setAutoRoute(true); * Route Definitions * -------------------------------------------------------------------- */ - +// JJO $routes->get('cliente', 'Impresion\Cliente::index'); // We get a performance increase by specifying the default // route since we don't have to scan directories. diff --git a/ci4/app/Controllers/Impresion/Clientes.php b/ci4/app/Controllers/Impresion/Cliente.php similarity index 71% rename from ci4/app/Controllers/Impresion/Clientes.php rename to ci4/app/Controllers/Impresion/Cliente.php index abd7c691..d5d12b64 100644 --- a/ci4/app/Controllers/Impresion/Clientes.php +++ b/ci4/app/Controllers/Impresion/Cliente.php @@ -3,17 +3,18 @@ namespace App\Controllers\Impresion; use App\Controllers\BaseController; -class Clientes extends BaseController + +class Cliente extends BaseController { function __construct() { - + } public function index() { - + echo 'Hola2'; } } diff --git a/ci4/app/Controllers/Tarifas.php b/ci4/app/Controllers/Tarifas.php new file mode 100644 index 00000000..914db980 --- /dev/null +++ b/ci4/app/Controllers/Tarifas.php @@ -0,0 +1,20 @@ +setLocale(session()->lang); + + $getWhiteList = $this->whiteListController(); + + foreach ($getWhiteList as $item){ + if(strtolower($item) == $uri->getSegment(1)){ + return true; } - - if(empty($controller)){ - $map = directory_map(APPPATH.'Controllers'); - foreach ($map as $key=>$item) - { - if(!strpos(strtolower($key),$compatibility)){ - var_dump($key); - $name = str_replace('.php', '', $item); - if(!getIgnoreController($name)){ - $controllers[] = [ - 'name' => $name, - 'path' => '', - 'methods' => get_class_methods('App\Controllers\\'.$name) - ]; - } - }else{ - foreach ($item as $subitem){ - $name = str_replace('.php', '', $subitem); - if(!getIgnoreController($name)) { - $controllers[] = [ - 'name' => $name, - 'path' => $key, - 'methods' => get_class_methods('App\Controllers\\' . str_replace('/', '\\', $key) . $name) - ]; - } - } + } + + $getRules = json_decode(session()->get('rules')??'[]'); + + foreach ($this->whiteListMethod() as $item){ + if(strtolower($item) == $uri->getSegment(2)){ + return true; + } + } + + foreach ($getRules as $key=>$value){ + if(strtolower($key) == $uri->getSegment(1)){ + if($uri->getTotalSegments() <= 1){ + return true; + } + foreach ($value as $item){ + if(strtolower($item) == $uri->getSegment(2)){ + return true; } } - }else{ - $array = explode('/',$controller); - $dir = count($array) > 1 ? $array[0] : ''; - $name = count($array) > 1 ? '\\'.$array[1] : $array[0]; - $controllers[] = [ - 'name' => $name, - 'path' => $dir, - 'methods' => get_class_methods('App\Controllers\\'.str_replace('/','\\',$dir).$name) - ]; } - /*echo '
';
-            var_dump($controllers);
-            echo '
';
-            dd();
-            */
-        } catch (Exception $e) {
-            return [];
         }
+        session()->setFlashdata('sweet', ['error',lang("App.dashboard_alert_rules")]);
+        header('Location: /home');
+        exit();
+           
+        echo '
';
+        var_dump($controllers);
+        echo '
'; + + } + + + /** + * Returns the white list of allowed controllers. + */ + public function whiteListController(){ + return [ + '', + 'BaseController', + 'Home', + 'Login', + 'Oauth', + 'Language', + 'Api', + 'Cron', + 'lang', + 'Ajax', + 'Integration', + 'Migrate', + 'Test', + + ]; + } } diff --git a/ci4/app/Filters/LoginAuthFilter.php b/ci4/app/Filters/LoginAuthFilter.php index 15830195..d189fb22 100644 --- a/ci4/app/Filters/LoginAuthFilter.php +++ b/ci4/app/Filters/LoginAuthFilter.php @@ -66,12 +66,22 @@ class LoginAuthFilter implements FilterInterface if($uri->getTotalSegments() <= 1){ return true; } - foreach ($value as $item){ + echo '
';
+                var_dump($value);
+                /*var_dump($uri->getSegment(0));
+                var_dump($uri->getSegment(1));
+                var_dump($uri->getSegment(2));
+                var_dump($uri->getTotalSegments());*/
+                echo '
'; + + /*foreach ($value as $item){ if(strtolower($item) == $uri->getSegment(2)){ return true; } - } + }*/ + } + dd(); } session()->setFlashdata('sweet', ['error',lang("App.dashboard_alert_rules")]); header('Location: /home'); @@ -84,8 +94,6 @@ class LoginAuthFilter implements FilterInterface public function whiteListController(){ return [ '', - 'Clientes', - 'BaseController', 'Home', 'Login', diff --git a/ci4/app/Helpers/general_helper.php b/ci4/app/Helpers/general_helper.php index c57f99cc..e967b196 100644 --- a/ci4/app/Helpers/general_helper.php +++ b/ci4/app/Helpers/general_helper.php @@ -155,6 +155,8 @@ function getDictionary($word=''){ 'view' => lang("App.group_rules_label_view"), 'oauth_store' => lang("App.group_rules_label_oauth_store"), 'template_store' => lang("App.group_rules_label_template_store"), + 'Tarifas' => 'Tarifas', + 'Cliente' => 'Cliente' ]; return array_key_exists($word,$dictionary)?$dictionary[$word] : $word; } catch (Exception $e) {