From 959d708daff6c899703b5b61f6b9ac0e7db26f18 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 25 Sep 2024 14:17:36 +0300 Subject: [PATCH] secure module add --- composer.lock | 47 ++++++++++--------- .../controllers/AdminConsoleController.php | 2 +- .../secure}/controllers/SecureController.php | 10 ++-- kernel/modules/secure/manifest.json | 8 ++++ .../secure}/models/forms/LoginForm.php | 2 +- kernel/modules/secure/routs/secure.php | 22 +++++++++ .../secure => modules/secure/views}/login.php | 0 kernel/routs/admin.php | 30 ++++++------ 8 files changed, 75 insertions(+), 46 deletions(-) rename kernel/{ => modules/secure}/controllers/SecureController.php (81%) create mode 100644 kernel/modules/secure/manifest.json rename kernel/{ => modules/secure}/models/forms/LoginForm.php (85%) create mode 100644 kernel/modules/secure/routs/secure.php rename kernel/{views/secure => modules/secure/views}/login.php (100%) diff --git a/composer.lock b/composer.lock index 77f0f40..e58a000 100644 --- a/composer.lock +++ b/composer.lock @@ -337,16 +337,16 @@ }, { "name": "illuminate/collections", - "version": "v11.23.5", + "version": "v11.24.1", "source": { "type": "git", "url": "https://github.com/illuminate/collections.git", - "reference": "cbea9d7a82984bbc1a9376498533cc77513f9a09" + "reference": "f205537e0ad131a1a87cb3cf04924e9edda4f2b1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/collections/zipball/cbea9d7a82984bbc1a9376498533cc77513f9a09", - "reference": "cbea9d7a82984bbc1a9376498533cc77513f9a09", + "url": "https://api.github.com/repos/illuminate/collections/zipball/f205537e0ad131a1a87cb3cf04924e9edda4f2b1", + "reference": "f205537e0ad131a1a87cb3cf04924e9edda4f2b1", "shasum": "" }, "require": { @@ -388,11 +388,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-09-12T14:50:04+00:00" + "time": "2024-09-16T14:32:15+00:00" }, { "name": "illuminate/conditionable", - "version": "v11.23.5", + "version": "v11.24.1", "source": { "type": "git", "url": "https://github.com/illuminate/conditionable.git", @@ -438,16 +438,16 @@ }, { "name": "illuminate/container", - "version": "v11.23.5", + "version": "v11.24.1", "source": { "type": "git", "url": "https://github.com/illuminate/container.git", - "reference": "66d20471c8c55ef056044dc1ff16da90d7b4d649" + "reference": "d6aca7c315d68cb6807c139facd7ea134b4f5104" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/container/zipball/66d20471c8c55ef056044dc1ff16da90d7b4d649", - "reference": "66d20471c8c55ef056044dc1ff16da90d7b4d649", + "url": "https://api.github.com/repos/illuminate/container/zipball/d6aca7c315d68cb6807c139facd7ea134b4f5104", + "reference": "d6aca7c315d68cb6807c139facd7ea134b4f5104", "shasum": "" }, "require": { @@ -485,20 +485,20 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-09-11T20:15:17+00:00" + "time": "2024-09-20T12:51:05+00:00" }, { "name": "illuminate/contracts", - "version": "v11.23.5", + "version": "v11.24.1", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", - "reference": "5a4c6dcf633c1f69e1b70bbea1ef1b7d2186d3da" + "reference": "56312862af937bd6da8e6dc8bbd88188dfb478f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/contracts/zipball/5a4c6dcf633c1f69e1b70bbea1ef1b7d2186d3da", - "reference": "5a4c6dcf633c1f69e1b70bbea1ef1b7d2186d3da", + "url": "https://api.github.com/repos/illuminate/contracts/zipball/56312862af937bd6da8e6dc8bbd88188dfb478f8", + "reference": "56312862af937bd6da8e6dc8bbd88188dfb478f8", "shasum": "" }, "require": { @@ -533,7 +533,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-09-12T15:25:08+00:00" + "time": "2024-09-22T15:08:08+00:00" }, { "name": "illuminate/database", @@ -672,7 +672,7 @@ }, { "name": "illuminate/macroable", - "version": "v11.23.5", + "version": "v11.24.1", "source": { "type": "git", "url": "https://github.com/illuminate/macroable.git", @@ -718,16 +718,16 @@ }, { "name": "illuminate/support", - "version": "v11.23.5", + "version": "v11.24.1", "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "8199097b4e24b05e8a035a6ea2fb5aeba645d71b" + "reference": "f1bcdb2205223a70f01ec1750669689154037444" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/8199097b4e24b05e8a035a6ea2fb5aeba645d71b", - "reference": "8199097b4e24b05e8a035a6ea2fb5aeba645d71b", + "url": "https://api.github.com/repos/illuminate/support/zipball/f1bcdb2205223a70f01ec1750669689154037444", + "reference": "f1bcdb2205223a70f01ec1750669689154037444", "shasum": "" }, "require": { @@ -767,6 +767,7 @@ }, "autoload": { "files": [ + "functions.php", "helpers.php" ], "psr-4": { @@ -789,7 +790,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-09-12T15:25:39+00:00" + "time": "2024-09-17T15:56:18+00:00" }, { "name": "itguild/eloquent-table", @@ -2498,5 +2499,5 @@ "ext-zip": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/kernel/console/controllers/AdminConsoleController.php b/kernel/console/controllers/AdminConsoleController.php index 9cf868a..21e3f8f 100644 --- a/kernel/console/controllers/AdminConsoleController.php +++ b/kernel/console/controllers/AdminConsoleController.php @@ -69,7 +69,7 @@ class AdminConsoleController extends ConsoleController $this->optionService->createFromParams( key: "active_modules", - value: "{\"modules\":[\"admin_themes\"]}", + value: "{\"modules\":[\"admin_themes\", \"secure\"]}", label: "Активные модули" ); $this->out->r("create option active_modules", "green"); diff --git a/kernel/controllers/SecureController.php b/kernel/modules/secure/controllers/SecureController.php similarity index 81% rename from kernel/controllers/SecureController.php rename to kernel/modules/secure/controllers/SecureController.php index 518e3cd..268c262 100644 --- a/kernel/controllers/SecureController.php +++ b/kernel/modules/secure/controllers/SecureController.php @@ -1,11 +1,10 @@ cgView->viewPath = KERNEL_DIR . "/views/secure/"; +// $this->cgView->viewPath = KERNEL_DIR . "/views/secure/"; + $this->cgView->viewPath = KERNEL_MODULES_DIR. "/secure/views/"; $this->cgView->layout = "/login.php"; $this->userService = new UserService(); } @@ -53,7 +53,7 @@ class SecureController extends AdminController #[NoReturn] public function actionLogout(): void { unset($_COOKIE['user_id']); - setcookie('user_id', "", time() - 3600, '/'); + setcookie('user_id', "", -1, '/', $_SERVER['SERVER_NAME'], false); $this->redirect("/"); } diff --git a/kernel/modules/secure/manifest.json b/kernel/modules/secure/manifest.json new file mode 100644 index 0000000..70ec7cd --- /dev/null +++ b/kernel/modules/secure/manifest.json @@ -0,0 +1,8 @@ +{ + "name": "Secure", + "version": "0.1", + "author": "ITGuild", + "slug": "secure", + "description": "Secure module", + "routs": "routs/secure.php" +} \ No newline at end of file diff --git a/kernel/models/forms/LoginForm.php b/kernel/modules/secure/models/forms/LoginForm.php similarity index 85% rename from kernel/models/forms/LoginForm.php rename to kernel/modules/secure/models/forms/LoginForm.php index 902d9ee..1c41d41 100644 --- a/kernel/models/forms/LoginForm.php +++ b/kernel/modules/secure/models/forms/LoginForm.php @@ -1,6 +1,6 @@ filter("auth", function (){ + if(!isset($_COOKIE['user_id'])) + { + header('Location: /admin/login'); + + return false; + } +}); + +App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ + App::$collector->group(["before" => "auth"], function (RouteCollector $router){ + App::$collector->get('/', [\kernel\controllers\ModuleController::class, 'actionIndex']); + }); + App::$collector->get('/login', [\kernel\modules\secure\controllers\SecureController::class, 'actionLogin']); + App::$collector->get('/logout', [\kernel\modules\secure\controllers\SecureController::class, 'actionLogout']); + App::$collector->post('/auth', [\kernel\modules\secure\controllers\SecureController::class, 'actionAuth']); +}); \ No newline at end of file diff --git a/kernel/views/secure/login.php b/kernel/modules/secure/views/login.php similarity index 100% rename from kernel/views/secure/login.php rename to kernel/modules/secure/views/login.php diff --git a/kernel/routs/admin.php b/kernel/routs/admin.php index 86f7abf..b527c8f 100644 --- a/kernel/routs/admin.php +++ b/kernel/routs/admin.php @@ -1,26 +1,24 @@ filter("auth", function (){ - if(!isset($_COOKIE['user_id'])) - { - header('Location: /admin/login'); - - return false; - } -}); +//App::$collector->filter("auth", function (){ +// if(!isset($_COOKIE['user_id'])) +// { +// header('Location: /admin/login'); +// +// return false; +// } +//}); App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ - App::$collector->group(["before" => "auth"], function (RouteCollector $router){ - App::$collector->get('/', [\kernel\controllers\ModuleController::class, 'actionIndex']); - }); - App::$collector->get('/login', [\kernel\controllers\SecureController::class, 'actionLogin']); - App::$collector->get('/logout', [\kernel\controllers\SecureController::class, 'actionLogout']); - App::$collector->post('/auth', [\kernel\controllers\SecureController::class, 'actionAuth']); +// App::$collector->group(["before" => "auth"], function (RouteCollector $router){ +// App::$collector->get('/', [\kernel\controllers\ModuleController::class, 'actionIndex']); +// }); +// App::$collector->get('/login', [\kernel\modules\secure\controllers\SecureController::class, 'actionLogin']); +// App::$collector->get('/logout', [\kernel\modules\secure\controllers\SecureController::class, 'actionLogout']); +// App::$collector->post('/auth', [\kernel\modules\secure\controllers\SecureController::class, 'actionAuth']); App::$collector->group(["before" => "auth"], function (RouteCollector $router){ App::$collector->group(["prefix" => "module"], function (RouteCollector $router){ App::$collector->get('/', [\kernel\controllers\ModuleController::class, 'actionIndex']);