From bda9b03a9f2693edac757b3c58482c9fb3eff2f8 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Thu, 17 Oct 2024 16:47:04 +0300 Subject: [PATCH] kernel pack some fix --- kernel/CgRouteCollector.php | 0 kernel/Database.php | 0 kernel/Header.php | 0 kernel/ResponseType.php | 0 kernel/console/ConsoleApp.php | 0 kernel/console/ConsoleController.php | 0 kernel/console/Out.php | 0 .../controllers/AdminConsoleController.php | 2 +- .../console/controllers/KernelController.php | 7 +++- kernel/console/migrations/stubs/blank.stub | 0 kernel/console/migrations/stubs/create.stub | 0 .../migrations/stubs/migration.create.stub | 0 .../console/migrations/stubs/migration.stub | 0 .../migrations/stubs/migration.update.stub | 0 kernel/console/migrations/stubs/update.stub | 0 kernel/helpers/Files.php | 14 +++++++ .../admin_themes/routs/adminThemes.php | 22 ++++++----- kernel/modules/option/routs/option.php | 20 +++++----- kernel/modules/post/routs/post.php | 20 +++++----- .../controllers/SecureRestController.php | 37 +++++++++++++++++++ kernel/modules/secure/manifest.json | 3 +- kernel/modules/secure/routs/secure.php | 6 +++ .../2024_09_23_125827_create_user_table.php | 2 + kernel/modules/user/routs/user.php | 20 +++++----- 24 files changed, 112 insertions(+), 41 deletions(-) mode change 100755 => 100644 kernel/CgRouteCollector.php mode change 100755 => 100644 kernel/Database.php mode change 100755 => 100644 kernel/Header.php mode change 100755 => 100644 kernel/ResponseType.php mode change 100755 => 100644 kernel/console/ConsoleApp.php mode change 100755 => 100644 kernel/console/ConsoleController.php mode change 100755 => 100644 kernel/console/Out.php mode change 100755 => 100644 kernel/console/migrations/stubs/blank.stub mode change 100755 => 100644 kernel/console/migrations/stubs/create.stub mode change 100755 => 100644 kernel/console/migrations/stubs/migration.create.stub mode change 100755 => 100644 kernel/console/migrations/stubs/migration.stub mode change 100755 => 100644 kernel/console/migrations/stubs/migration.update.stub mode change 100755 => 100644 kernel/console/migrations/stubs/update.stub create mode 100644 kernel/modules/secure/controllers/SecureRestController.php diff --git a/kernel/CgRouteCollector.php b/kernel/CgRouteCollector.php old mode 100755 new mode 100644 diff --git a/kernel/Database.php b/kernel/Database.php old mode 100755 new mode 100644 diff --git a/kernel/Header.php b/kernel/Header.php old mode 100755 new mode 100644 diff --git a/kernel/ResponseType.php b/kernel/ResponseType.php old mode 100755 new mode 100644 diff --git a/kernel/console/ConsoleApp.php b/kernel/console/ConsoleApp.php old mode 100755 new mode 100644 diff --git a/kernel/console/ConsoleController.php b/kernel/console/ConsoleController.php old mode 100755 new mode 100644 diff --git a/kernel/console/Out.php b/kernel/console/Out.php old mode 100755 new mode 100644 diff --git a/kernel/console/controllers/AdminConsoleController.php b/kernel/console/controllers/AdminConsoleController.php index e1c3bfe..83e33ee 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\", \"secure\"]}", + value: "{\"modules\":[\"admin_themes\", \"secure\", \"user\"]}", label: "Активные модули" ); $this->out->r("create option active_modules", "green"); diff --git a/kernel/console/controllers/KernelController.php b/kernel/console/controllers/KernelController.php index 0486071..92342db 100644 --- a/kernel/console/controllers/KernelController.php +++ b/kernel/console/controllers/KernelController.php @@ -4,7 +4,6 @@ namespace kernel\console\controllers; use kernel\console\ConsoleController; use kernel\helpers\Files; -use kernel\services\KernelService; use ZipArchive; class KernelController extends ConsoleController @@ -33,7 +32,10 @@ class KernelController extends ConsoleController $fileHelper = new Files(); $fileHelper->copy_folder(KERNEL_DIR, $tmpKernelDirFull); - $fileHelper->pack($tmpKernelDirFull, RESOURCES_DIR . '/tmp/kernel/kernel.itguild'); + if (!is_dir(RESOURCES_DIR . '/tmp/kernel')) { + mkdir(RESOURCES_DIR . '/tmp/kernel'); + } + $fileHelper->pack($tmpKernelDirFull, RESOURCES_DIR . '/tmp/kernel/kernel.igk'); $fileHelper->recursiveRemoveDir($tmpKernelDirFull); $this->out->r("Ядро заархивировано", 'green'); @@ -61,6 +63,7 @@ class KernelController extends ConsoleController $tmpKernelDirFull = RESOURCES_DIR . '/tmp/kernel/' . $tmpKernelDir . "/"; $zip->extractTo($tmpKernelDirFull); $zip->close(); + $this->files->recursiveRemoveKernelDir(); $this->files->copy_folder($tmpKernelDirFull , ROOT_DIR . "/kernel"); $this->files->recursiveRemoveDir($tmpKernelDirFull); $this->out->r('Ядро обновлено.', 'green'); diff --git a/kernel/console/migrations/stubs/blank.stub b/kernel/console/migrations/stubs/blank.stub old mode 100755 new mode 100644 diff --git a/kernel/console/migrations/stubs/create.stub b/kernel/console/migrations/stubs/create.stub old mode 100755 new mode 100644 diff --git a/kernel/console/migrations/stubs/migration.create.stub b/kernel/console/migrations/stubs/migration.create.stub old mode 100755 new mode 100644 diff --git a/kernel/console/migrations/stubs/migration.stub b/kernel/console/migrations/stubs/migration.stub old mode 100755 new mode 100644 diff --git a/kernel/console/migrations/stubs/migration.update.stub b/kernel/console/migrations/stubs/migration.update.stub old mode 100755 new mode 100644 diff --git a/kernel/console/migrations/stubs/update.stub b/kernel/console/migrations/stubs/update.stub old mode 100755 new mode 100644 diff --git a/kernel/helpers/Files.php b/kernel/helpers/Files.php index 0027357..3ec89e2 100644 --- a/kernel/helpers/Files.php +++ b/kernel/helpers/Files.php @@ -43,6 +43,20 @@ class Files rmdir($dir); } + public function recursiveRemoveKernelDir(): void + { + $includes = new FilesystemIterator(KERNEL_DIR); + foreach ($includes as $include) { + if(is_dir($include) && !is_link($include) && $include->getFilename() !== 'app_modules') { + $this->recursiveRemoveDir($include); + } + else { + unlink($include); + } + } + rmdir(KERNEL_DIR); + } + public function pack(string $source, string $destination/*, bool $include_source = true*/): void { $zip = new ZipArchive(); diff --git a/kernel/modules/admin_themes/routs/adminThemes.php b/kernel/modules/admin_themes/routs/adminThemes.php index 44e1110..e13f0a2 100644 --- a/kernel/modules/admin_themes/routs/adminThemes.php +++ b/kernel/modules/admin_themes/routs/adminThemes.php @@ -5,16 +5,18 @@ use kernel\modules\admin_themes\controllers\AdminThemeController; use Phroute\Phroute\RouteCollector; App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ - App::$collector->group(["prefix" => "settings"], function (RouteCollector $router){ - App::$collector->group(["prefix" => "admin-themes"], function (RouteCollector $router){ - App::$collector->get('/', [AdminThemeController::class, 'actionIndex']); - App::$collector->get('/activate', [AdminThemeController::class, 'actionActivate']); - // App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']); - // App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']); - // App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']); - // App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']); - // App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']); - // App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']); + App::$collector->group(["before" => "auth"], function (RouteCollector $router) { + App::$collector->group(["prefix" => "settings"], function (RouteCollector $router) { + App::$collector->group(["prefix" => "admin-themes"], function (RouteCollector $router) { + App::$collector->get('/', [AdminThemeController::class, 'actionIndex']); + App::$collector->get('/activate', [AdminThemeController::class, 'actionActivate']); + // App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']); + // App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']); + // App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']); + // App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']); + // App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']); + // App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']); + }); }); }); }); \ No newline at end of file diff --git a/kernel/modules/option/routs/option.php b/kernel/modules/option/routs/option.php index 259d2b0..639becf 100644 --- a/kernel/modules/option/routs/option.php +++ b/kernel/modules/option/routs/option.php @@ -4,14 +4,16 @@ use kernel\App; use Phroute\Phroute\RouteCollector; App::$collector->group(["prefix" => "admin"], function (RouteCollector $router) { - App::$collector->group(["prefix" => "option"], callback: function (RouteCollector $router) { - App::$collector->get('/', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']); - App::$collector->get('/page/{page_number}', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']); - App::$collector->get('/create', [\kernel\modules\option\controllers\OptionController::class, 'actionCreate']); - App::$collector->post("/", [\kernel\modules\option\controllers\OptionController::class, 'actionAdd']); - App::$collector->get('/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionView']); - App::$collector->any('/update/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionUpdate']); - App::$collector->any("/edit/{id}", [\kernel\modules\option\controllers\OptionController::class, 'actionEdit']); - App::$collector->get('/delete/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionDelete']); + App::$collector->group(["before" => "auth"], function (RouteCollector $router) { + App::$collector->group(["prefix" => "option"], callback: function (RouteCollector $router) { + App::$collector->get('/', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']); + App::$collector->get('/create', [\kernel\modules\option\controllers\OptionController::class, 'actionCreate']); + App::$collector->post("/", [\kernel\modules\option\controllers\OptionController::class, 'actionAdd']); + App::$collector->get('/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionView']); + App::$collector->any('/update/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionUpdate']); + App::$collector->any("/edit/{id}", [\kernel\modules\option\controllers\OptionController::class, 'actionEdit']); + App::$collector->get('/delete/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionDelete']); + }); }); }); \ No newline at end of file diff --git a/kernel/modules/post/routs/post.php b/kernel/modules/post/routs/post.php index 8d4755a..3bba27d 100644 --- a/kernel/modules/post/routs/post.php +++ b/kernel/modules/post/routs/post.php @@ -6,15 +6,17 @@ use Phroute\Phroute\RouteCollector; App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ - App::$collector->group(["prefix" => "post"], function (RouteCollector $router){ - App::$collector->get('/', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']); - App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']); - App::$collector->get('/create', [\kernel\modules\post\controllers\PostController::class, 'actionCreate']); - App::$collector->post("/", [\kernel\modules\post\controllers\PostController::class, 'actionAdd']); - App::$collector->get('/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']); - App::$collector->any('/update/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionUpdate']); - App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']); - App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']); + App::$collector->group(["before" => "auth"], function (RouteCollector $router) { + App::$collector->group(["prefix" => "post"], function (RouteCollector $router) { + App::$collector->get('/', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']); + App::$collector->get('/create', [\kernel\modules\post\controllers\PostController::class, 'actionCreate']); + App::$collector->post("/", [\kernel\modules\post\controllers\PostController::class, 'actionAdd']); + App::$collector->get('/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']); + App::$collector->any('/update/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionUpdate']); + App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']); + App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']); + }); }); }); diff --git a/kernel/modules/secure/controllers/SecureRestController.php b/kernel/modules/secure/controllers/SecureRestController.php new file mode 100644 index 0000000..1762dc7 --- /dev/null +++ b/kernel/modules/secure/controllers/SecureRestController.php @@ -0,0 +1,37 @@ +model = new User(); + } + + #[NoReturn] public function actionAuth(): void + { + $request = new Request(); + $data = $request->post(); + $model = $this->model->where(['username', $data['username']])->first(); + + $access_token = 123124312313; + $access_token_expires_at = time() + 3600; + + $model->{'access_token'} = $access_token; + $model->{'access_token_expires_at'} = $access_token_expires_at; + foreach ($model->getFillable() as $item){ + $model->{$item} = $data[$item] ?? null; + } + + $model->save(); + + $this->renderApi($this->model->toArray()); + } +} \ No newline at end of file diff --git a/kernel/modules/secure/manifest.json b/kernel/modules/secure/manifest.json index 70ec7cd..e0ccf6e 100644 --- a/kernel/modules/secure/manifest.json +++ b/kernel/modules/secure/manifest.json @@ -4,5 +4,6 @@ "author": "ITGuild", "slug": "secure", "description": "Secure module", - "routs": "routs/secure.php" + "routs": "routs/secure.php", + "dependence": "user" } \ No newline at end of file diff --git a/kernel/modules/secure/routs/secure.php b/kernel/modules/secure/routs/secure.php index c7c8acf..072e84c 100644 --- a/kernel/modules/secure/routs/secure.php +++ b/kernel/modules/secure/routs/secure.php @@ -1,6 +1,7 @@ filter("auth", [\kernel\middlewares\AuthMiddleware::class, "handler"]); @@ -14,3 +15,8 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ App::$collector->post('/auth', [\kernel\modules\secure\controllers\SecureController::class, 'actionAuth']); }); +App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){ + $router->rest("secure", [\kernel\modules\secure\controllers\SecureRestController::class]); + App::$collector->post('/auth', [\kernel\modules\secure\controllers\SecureRestController::class, 'actionAuth']); +}); + diff --git a/kernel/modules/user/migrations/2024_09_23_125827_create_user_table.php b/kernel/modules/user/migrations/2024_09_23_125827_create_user_table.php index 8f53302..774213a 100644 --- a/kernel/modules/user/migrations/2024_09_23_125827_create_user_table.php +++ b/kernel/modules/user/migrations/2024_09_23_125827_create_user_table.php @@ -19,6 +19,8 @@ return new class extends Migration $table->string('email', 255); $table->string('password_hash', 255); $table->integer('role')->default(1); + $table->string('access_token', 255)->nullable(true); + $table->dateTime('access_token_expires_at')->nullable(true); $table->timestamps(); }); } diff --git a/kernel/modules/user/routs/user.php b/kernel/modules/user/routs/user.php index 5f5c74c..d7214fd 100644 --- a/kernel/modules/user/routs/user.php +++ b/kernel/modules/user/routs/user.php @@ -7,14 +7,16 @@ use Phroute\Phroute\RouteCollector; App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ - App::$collector->group(["prefix" => "user"], callback: function (RouteCollector $router){ - App::$collector->get('/', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']); - App::$collector->get('/page/{page_number}', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']); - App::$collector->get('/create', [\kernel\modules\user\controllers\UserController::class, 'actionCreate']); - App::$collector->post("/", [\kernel\modules\user\controllers\UserController::class, 'actionAdd']); - App::$collector->get('/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionView']); - App::$collector->any('/update/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionUpdate']); - App::$collector->any("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']); - App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionDelete']); + App::$collector->group(["before" => "auth"], function (RouteCollector $router) { + App::$collector->group(["prefix" => "user"], callback: function (RouteCollector $router) { + App::$collector->get('/', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']); + App::$collector->get('/create', [\kernel\modules\user\controllers\UserController::class, 'actionCreate']); + App::$collector->post("/", [\kernel\modules\user\controllers\UserController::class, 'actionAdd']); + App::$collector->get('/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionView']); + App::$collector->any('/update/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionUpdate']); + App::$collector->any("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']); + App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionDelete']); + }); }); }); \ No newline at end of file