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(
key: "active_modules",
value: "{\"modules\":[\"admin_themes\", \"secure\"]}",
value: "{\"modules\":[\"admin_themes\", \"secure\", \"user\"]}",
label: "Активные модули"
);
$this->out->r("create option active_modules", "green");

View File

@ -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');

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);
}
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();

View File

@ -5,6 +5,7 @@ use kernel\modules\admin_themes\controllers\AdminThemeController;
use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
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']);
@ -18,3 +19,4 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
});
});
});
});

View File

@ -4,6 +4,7 @@ use kernel\App;
use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router) {
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']);
@ -15,3 +16,4 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router)
App::$collector->get('/delete/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionDelete']);
});
});
});

View File

@ -6,6 +6,7 @@ use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
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']);
@ -17,6 +18,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']);
});
});
});
App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
$router->rest("post", [\kernel\modules\post\controllers\PostRestController::class]);

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",
"slug": "secure",
"description": "Secure module",
"routs": "routs/secure.php"
"routs": "routs/secure.php",
"dependence": "user"
}

View File

@ -1,6 +1,7 @@
<?php
use kernel\App;
use kernel\CgRouteCollector;
use Phroute\Phroute\RouteCollector;
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->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('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();
});
}

View File

@ -7,6 +7,7 @@ use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
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']);
@ -18,3 +19,4 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionDelete']);
});
});
});