kernel pack some fix

This commit is contained in:
Билай Станислав 2024-10-17 16:47:04 +03:00
parent 4355651695
commit bda9b03a9f
24 changed files with 112 additions and 41 deletions

0
kernel/CgRouteCollector.php Executable file → Normal file
View File

0
kernel/Database.php Executable file → Normal file
View File

0
kernel/Header.php Executable file → Normal file
View File

0
kernel/ResponseType.php Executable file → Normal file
View File

0
kernel/console/ConsoleApp.php Executable file → Normal file
View File

0
kernel/console/ConsoleController.php Executable file → Normal file
View File

0
kernel/console/Out.php Executable file → Normal file
View File

View File

@ -69,7 +69,7 @@ class AdminConsoleController extends ConsoleController
$this->optionService->createFromParams( $this->optionService->createFromParams(
key: "active_modules", key: "active_modules",
value: "{\"modules\":[\"admin_themes\", \"secure\"]}", value: "{\"modules\":[\"admin_themes\", \"secure\", \"user\"]}",
label: "Активные модули" label: "Активные модули"
); );
$this->out->r("create option active_modules", "green"); $this->out->r("create option active_modules", "green");

View File

@ -4,7 +4,6 @@ namespace kernel\console\controllers;
use kernel\console\ConsoleController; use kernel\console\ConsoleController;
use kernel\helpers\Files; use kernel\helpers\Files;
use kernel\services\KernelService;
use ZipArchive; use ZipArchive;
class KernelController extends ConsoleController class KernelController extends ConsoleController
@ -33,7 +32,10 @@ class KernelController extends ConsoleController
$fileHelper = new Files(); $fileHelper = new Files();
$fileHelper->copy_folder(KERNEL_DIR, $tmpKernelDirFull); $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); $fileHelper->recursiveRemoveDir($tmpKernelDirFull);
$this->out->r("Ядро заархивировано", 'green'); $this->out->r("Ядро заархивировано", 'green');
@ -61,6 +63,7 @@ class KernelController extends ConsoleController
$tmpKernelDirFull = RESOURCES_DIR . '/tmp/kernel/' . $tmpKernelDir . "/"; $tmpKernelDirFull = RESOURCES_DIR . '/tmp/kernel/' . $tmpKernelDir . "/";
$zip->extractTo($tmpKernelDirFull); $zip->extractTo($tmpKernelDirFull);
$zip->close(); $zip->close();
$this->files->recursiveRemoveKernelDir();
$this->files->copy_folder($tmpKernelDirFull , ROOT_DIR . "/kernel"); $this->files->copy_folder($tmpKernelDirFull , ROOT_DIR . "/kernel");
$this->files->recursiveRemoveDir($tmpKernelDirFull); $this->files->recursiveRemoveDir($tmpKernelDirFull);
$this->out->r('Ядро обновлено.', 'green'); $this->out->r('Ядро обновлено.', 'green');

0
kernel/console/migrations/stubs/blank.stub Executable file → Normal file
View File

0
kernel/console/migrations/stubs/create.stub Executable file → Normal file
View File

0
kernel/console/migrations/stubs/migration.create.stub Executable file → Normal file
View File

0
kernel/console/migrations/stubs/migration.stub Executable file → Normal file
View File

0
kernel/console/migrations/stubs/migration.update.stub Executable file → Normal file
View File

0
kernel/console/migrations/stubs/update.stub Executable file → Normal file
View File

View File

@ -43,6 +43,20 @@ class Files
rmdir($dir); 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 public function pack(string $source, string $destination/*, bool $include_source = true*/): void
{ {
$zip = new ZipArchive(); $zip = new ZipArchive();

View File

@ -5,16 +5,18 @@ use kernel\modules\admin_themes\controllers\AdminThemeController;
use Phroute\Phroute\RouteCollector; use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->group(["prefix" => "settings"], function (RouteCollector $router){ App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "admin-themes"], function (RouteCollector $router){ App::$collector->group(["prefix" => "settings"], function (RouteCollector $router) {
App::$collector->get('/', [AdminThemeController::class, 'actionIndex']); App::$collector->group(["prefix" => "admin-themes"], function (RouteCollector $router) {
App::$collector->get('/activate', [AdminThemeController::class, 'actionActivate']); App::$collector->get('/', [AdminThemeController::class, 'actionIndex']);
// App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']); App::$collector->get('/activate', [AdminThemeController::class, 'actionActivate']);
// App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']); // App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']);
// App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']); // App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']);
// App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']); // App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']);
// App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']); // App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']);
// App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']); // App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']);
// App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']);
});
}); });
}); });
}); });

View File

@ -4,14 +4,16 @@ use kernel\App;
use Phroute\Phroute\RouteCollector; use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router) { App::$collector->group(["prefix" => "admin"], function (RouteCollector $router) {
App::$collector->group(["prefix" => "option"], callback: function (RouteCollector $router) { App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->get('/', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']); App::$collector->group(["prefix" => "option"], callback: function (RouteCollector $router) {
App::$collector->get('/page/{page_number}', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']); App::$collector->get('/', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\modules\option\controllers\OptionController::class, 'actionCreate']); App::$collector->get('/page/{page_number}', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']);
App::$collector->post("/", [\kernel\modules\option\controllers\OptionController::class, 'actionAdd']); App::$collector->get('/create', [\kernel\modules\option\controllers\OptionController::class, 'actionCreate']);
App::$collector->get('/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionView']); App::$collector->post("/", [\kernel\modules\option\controllers\OptionController::class, 'actionAdd']);
App::$collector->any('/update/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionUpdate']); App::$collector->get('/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionView']);
App::$collector->any("/edit/{id}", [\kernel\modules\option\controllers\OptionController::class, 'actionEdit']); App::$collector->any('/update/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionUpdate']);
App::$collector->get('/delete/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionDelete']); App::$collector->any("/edit/{id}", [\kernel\modules\option\controllers\OptionController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionDelete']);
});
}); });
}); });

View File

@ -6,15 +6,17 @@ use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->group(["prefix" => "post"], function (RouteCollector $router){ App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->get('/', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']); App::$collector->group(["prefix" => "post"], function (RouteCollector $router) {
App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']); App::$collector->get('/', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\modules\post\controllers\PostController::class, 'actionCreate']); App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);
App::$collector->post("/", [\kernel\modules\post\controllers\PostController::class, 'actionAdd']); App::$collector->get('/create', [\kernel\modules\post\controllers\PostController::class, 'actionCreate']);
App::$collector->get('/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']); App::$collector->post("/", [\kernel\modules\post\controllers\PostController::class, 'actionAdd']);
App::$collector->any('/update/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionUpdate']); App::$collector->get('/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']);
App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']); App::$collector->any('/update/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionUpdate']);
App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']); App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']);
});
}); });
}); });

View File

@ -0,0 +1,37 @@
<?php
namespace kernel\modules\secure\controllers;
use JetBrains\PhpStorm\NoReturn;
use kernel\helpers\Debug;
use kernel\modules\user\models\User;
use kernel\Request;
use kernel\RestController;
class SecureRestController extends RestController
{
public function __construct()
{
$this->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());
}
}

View File

@ -4,5 +4,6 @@
"author": "ITGuild", "author": "ITGuild",
"slug": "secure", "slug": "secure",
"description": "Secure module", "description": "Secure module",
"routs": "routs/secure.php" "routs": "routs/secure.php",
"dependence": "user"
} }

View File

@ -1,6 +1,7 @@
<?php <?php
use kernel\App; use kernel\App;
use kernel\CgRouteCollector;
use Phroute\Phroute\RouteCollector; use Phroute\Phroute\RouteCollector;
App::$collector->filter("auth", [\kernel\middlewares\AuthMiddleware::class, "handler"]); App::$collector->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->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']);
});

View File

@ -19,6 +19,8 @@ return new class extends Migration
$table->string('email', 255); $table->string('email', 255);
$table->string('password_hash', 255); $table->string('password_hash', 255);
$table->integer('role')->default(1); $table->integer('role')->default(1);
$table->string('access_token', 255)->nullable(true);
$table->dateTime('access_token_expires_at')->nullable(true);
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -7,14 +7,16 @@ use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->group(["prefix" => "user"], callback: function (RouteCollector $router){ App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
App::$collector->get('/', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']); App::$collector->group(["prefix" => "user"], callback: function (RouteCollector $router) {
App::$collector->get('/page/{page_number}', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']); App::$collector->get('/', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\modules\user\controllers\UserController::class, 'actionCreate']); App::$collector->get('/page/{page_number}', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']);
App::$collector->post("/", [\kernel\modules\user\controllers\UserController::class, 'actionAdd']); App::$collector->get('/create', [\kernel\modules\user\controllers\UserController::class, 'actionCreate']);
App::$collector->get('/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionView']); App::$collector->post("/", [\kernel\modules\user\controllers\UserController::class, 'actionAdd']);
App::$collector->any('/update/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionUpdate']); App::$collector->get('/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionView']);
App::$collector->any("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']); App::$collector->any('/update/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionUpdate']);
App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionDelete']); App::$collector->any("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionDelete']);
});
}); });
}); });