diff --git a/kernel/helpers/Html.php b/kernel/helpers/Html.php index 0b834c7..f85f115 100644 --- a/kernel/helpers/Html.php +++ b/kernel/helpers/Html.php @@ -11,6 +11,12 @@ class Html return ""; } + public static function h(string|int $type = 1, string $title = '', array $params = []) + { + $paramsStr = self::createParams($params); + return "$title"; + } + /** * @param array $data * @return string diff --git a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php index 6e7846b..06e8f55 100644 --- a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php +++ b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php @@ -34,18 +34,30 @@ class ModuleShopClientController extends AdminController */ public function actionIndex(int $page_number = 1): void { - $per_page = 8; - $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); - $modules_info = json_decode($modules_info->getBody()->getContents(), true); - $module_count = count($modules_info); - $modules_info = array_slice($modules_info, $per_page*($page_number-1), $per_page); - $this->cgView->render("index.php", [ - 'modules_info' => $modules_info, - 'moduleService' => $this->moduleService, - 'page_number' => $page_number, - 'module_count' => $module_count, - 'per_page' => $per_page, - ]); + + if ($this->moduleService->issetModuleShopToken()) { + if ($this->moduleService->isServerAvailable()) { + + $per_page = 8; + $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); + $modules_info = json_decode($modules_info->getBody()->getContents(), true); + $module_count = count($modules_info); + $modules_info = array_slice($modules_info, $per_page * ($page_number - 1), $per_page); + + $this->cgView->render("index.php", [ + 'modules_info' => $modules_info, + 'moduleService' => $this->moduleService, + 'page_number' => $page_number, + 'module_count' => $module_count, + 'per_page' => $per_page, + ]); + } else { + $this->cgView->render("module_shop_error_connection.php"); + } + + } else { + $this->cgView->render("login_at_module_shop.php"); + } } public function actionView(int $id): void diff --git a/kernel/modules/module_shop_client/views/login_at_module_shop.php b/kernel/modules/module_shop_client/views/login_at_module_shop.php new file mode 100644 index 0000000..b553f66 --- /dev/null +++ b/kernel/modules/module_shop_client/views/login_at_module_shop.php @@ -0,0 +1,34 @@ +run(); + +echo \kernel\helpers\Html::h(2, "Форма авторизации"); + +$form = new ActiveForm(); +$form->beginForm("/admin/module_shop_client/auth/"); + +$form->field(\itguild\forms\inputs\TextInput::class, 'key', [ + 'class' => "form-control", + 'placeholder' => 'Email', +]) + ->setLabel("Email") + ->render(); +?> + +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ + 'class' => "btn btn-primary ", + 'value' => 'Отправить', + 'typeInput' => 'submit' + ]) + ->render(); + ?> +
+ +
+endForm(); \ No newline at end of file diff --git a/kernel/modules/module_shop_client/views/module_shop_error_connection.php b/kernel/modules/module_shop_client/views/module_shop_error_connection.php new file mode 100644 index 0000000..bf31edd --- /dev/null +++ b/kernel/modules/module_shop_client/views/module_shop_error_connection.php @@ -0,0 +1,6 @@ +run(); +?> + +

Ошибка подключения к сервису

+ diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index c112e2f..50a3603 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -476,6 +476,10 @@ class ModuleService if ($this->isServerAvailable()){ $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); + if (!$this->issetModuleShopToken()){ + return false; + } + $modules_info = json_decode($modules_info->getBody()->getContents(), true); $mod_info = $this->getModuleInfoBySlug($slug); foreach ($modules_info as $mod) { @@ -516,4 +520,13 @@ class ModuleService } } + public function issetModuleShopToken(): bool + { + if (!empty($_ENV['MODULE_SHOP_TOKEN'])){ + return true; + } + + return false; + } + } \ No newline at end of file diff --git a/kernel/views/module/index.php b/kernel/views/module/index.php index 52c6bcb..8cb34f8 100644 --- a/kernel/views/module/index.php +++ b/kernel/views/module/index.php @@ -75,9 +75,11 @@ $table->addAction(function ($row) use ($moduleService){ return false; }); -if ($moduleService->isActive('module_shop_client') && $moduleService->isServerAvailable()) { +if ($moduleService->isActive('module_shop_client')) { ModuleTabsWidget::create()->run(); } + + $table->create(); $table->render();