From f4dc0127a93778d74c73fcf8c216e226254debc0 Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Sun, 3 Mar 2024 00:21:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BC=D0=B8=D0=BD=D0=B8=D0=BC=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=D1=8E=D1=89=D0=B0=D1=8F=D1=81=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- com_oauthserver/administrator/access.xml | 13 ++ com_oauthserver/administrator/config.xml | 25 +++ .../administrator/forms/client.xml | 23 +++ .../administrator/forms/filter_clients.xml | 22 +++ .../administrator/forms/index.html | 0 .../language/en-GB/en-GB.com_oauthserver.ini | 0 .../en-GB/en-GB.com_oauthserver.sys.ini | 0 .../language/ru-RU/ru-RU.com_oauthserver.ini | 0 .../ru-RU/ru-RU.com_oauthserver.sys.ini | 0 .../administrator/services/provider.php | 29 +++- .../administrator/sql/install.mysql.utf8.sql | 12 ++ .../sql/uninstall.mysql.utf8.sql | 0 .../sql/updates/mysql/index.html | 0 .../src/Controller/ClientController.php | 17 +++ .../src/Controller/DisplayController.php | 17 +++ .../src/Dispatcher/Dispatcher.php | 10 ++ .../administrator/src/Model/ClientModel.php | 40 +++++ .../administrator/src/Model/ClientsModel.php | 116 ++++++++++++++ .../administrator/src/Table/ClientTable.php | 21 +++ .../src/View/Client/HtmlView.php | 131 ++++++++++++++++ .../src/View/Clients/HtmlView.php | 142 ++++++++++++++++++ .../administrator/tmpl/client/edit.php | 49 ++++++ .../administrator/tmpl/clients/default.php | 2 + .../administrator/tmpl/clients/emptystate.php | 27 ++++ com_oauthserver/oauthserver.xml | 67 +++++++++ com_oauthserver/site/forms/index.html | 0 .../language/en-GB/en-GB.com_oauthserver.ini | 0 .../en-GB/en-GB.com_oauthserver.sys.ini | 0 .../language/ru-RU/ru-RU.com_oauthserver.ini | 0 .../ru-RU/ru-RU.com_oauthserver.sys.ini | 0 com_oauthserver/site/src/index.html | 0 com_oauthserver/site/tmpl/index.html | 0 32 files changed, 761 insertions(+), 2 deletions(-) create mode 100644 com_oauthserver/administrator/access.xml create mode 100644 com_oauthserver/administrator/config.xml create mode 100644 com_oauthserver/administrator/forms/client.xml create mode 100644 com_oauthserver/administrator/forms/filter_clients.xml create mode 100644 com_oauthserver/administrator/forms/index.html create mode 100644 com_oauthserver/administrator/language/en-GB/en-GB.com_oauthserver.ini create mode 100644 com_oauthserver/administrator/language/en-GB/en-GB.com_oauthserver.sys.ini create mode 100644 com_oauthserver/administrator/language/ru-RU/ru-RU.com_oauthserver.ini create mode 100644 com_oauthserver/administrator/language/ru-RU/ru-RU.com_oauthserver.sys.ini create mode 100644 com_oauthserver/administrator/sql/install.mysql.utf8.sql create mode 100644 com_oauthserver/administrator/sql/uninstall.mysql.utf8.sql create mode 100644 com_oauthserver/administrator/sql/updates/mysql/index.html create mode 100644 com_oauthserver/administrator/src/Controller/ClientController.php create mode 100644 com_oauthserver/administrator/src/Controller/DisplayController.php create mode 100644 com_oauthserver/administrator/src/Dispatcher/Dispatcher.php create mode 100644 com_oauthserver/administrator/src/Model/ClientModel.php create mode 100644 com_oauthserver/administrator/src/Model/ClientsModel.php create mode 100644 com_oauthserver/administrator/src/Table/ClientTable.php create mode 100644 com_oauthserver/administrator/src/View/Client/HtmlView.php create mode 100644 com_oauthserver/administrator/src/View/Clients/HtmlView.php create mode 100644 com_oauthserver/administrator/tmpl/client/edit.php create mode 100644 com_oauthserver/administrator/tmpl/clients/default.php create mode 100644 com_oauthserver/administrator/tmpl/clients/emptystate.php create mode 100644 com_oauthserver/oauthserver.xml create mode 100644 com_oauthserver/site/forms/index.html create mode 100644 com_oauthserver/site/language/en-GB/en-GB.com_oauthserver.ini create mode 100644 com_oauthserver/site/language/en-GB/en-GB.com_oauthserver.sys.ini create mode 100644 com_oauthserver/site/language/ru-RU/ru-RU.com_oauthserver.ini create mode 100644 com_oauthserver/site/language/ru-RU/ru-RU.com_oauthserver.sys.ini create mode 100644 com_oauthserver/site/src/index.html create mode 100644 com_oauthserver/site/tmpl/index.html diff --git a/com_oauthserver/administrator/access.xml b/com_oauthserver/administrator/access.xml new file mode 100644 index 0000000..aa62e06 --- /dev/null +++ b/com_oauthserver/administrator/access.xml @@ -0,0 +1,13 @@ + + +
+ + + + + + + + +
+
\ No newline at end of file diff --git a/com_oauthserver/administrator/config.xml b/com_oauthserver/administrator/config.xml new file mode 100644 index 0000000..90b33ab --- /dev/null +++ b/com_oauthserver/administrator/config.xml @@ -0,0 +1,25 @@ + + +
+
+ + + + +
+
+
+ +
+
\ No newline at end of file diff --git a/com_oauthserver/administrator/forms/client.xml b/com_oauthserver/administrator/forms/client.xml new file mode 100644 index 0000000..f904869 --- /dev/null +++ b/com_oauthserver/administrator/forms/client.xml @@ -0,0 +1,23 @@ + +
+ + + +
+ + + +
+
\ No newline at end of file diff --git a/com_oauthserver/administrator/forms/filter_clients.xml b/com_oauthserver/administrator/forms/filter_clients.xml new file mode 100644 index 0000000..6ec0e73 --- /dev/null +++ b/com_oauthserver/administrator/forms/filter_clients.xml @@ -0,0 +1,22 @@ + +
+ + + + + + + + + + + +
\ No newline at end of file diff --git a/com_oauthserver/administrator/forms/index.html b/com_oauthserver/administrator/forms/index.html new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/administrator/language/en-GB/en-GB.com_oauthserver.ini b/com_oauthserver/administrator/language/en-GB/en-GB.com_oauthserver.ini new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/administrator/language/en-GB/en-GB.com_oauthserver.sys.ini b/com_oauthserver/administrator/language/en-GB/en-GB.com_oauthserver.sys.ini new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/administrator/language/ru-RU/ru-RU.com_oauthserver.ini b/com_oauthserver/administrator/language/ru-RU/ru-RU.com_oauthserver.ini new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/administrator/language/ru-RU/ru-RU.com_oauthserver.sys.ini b/com_oauthserver/administrator/language/ru-RU/ru-RU.com_oauthserver.sys.ini new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/administrator/services/provider.php b/com_oauthserver/administrator/services/provider.php index d9b5dd4..d3aa6c5 100644 --- a/com_oauthserver/administrator/services/provider.php +++ b/com_oauthserver/administrator/services/provider.php @@ -1,13 +1,38 @@ registerServiceProvider(new MVCFactory('\\Webmasterskaya\\Component\\OauthServer')); + $container->registerServiceProvider(new ComponentDispatcherFactory('\\Webmasterskaya\\Component\\OauthServer')); + $container->registerServiceProvider(new RouterFactory('\\Webmasterskaya\\Component\\OauthServer')); + + $container->set( + ComponentInterface::class, + function (Container $container) { + $component = new Component($container->get(ComponentDispatcherFactoryInterface::class)); + + $component->setRegistry($container->get(Registry::class)); + $component->setMVCFactory($container->get(MVCFactoryInterface::class)); + $component->setRouterFactory($container->get(RouterFactoryInterface::class)); + + return $component; + } + ); } }; \ No newline at end of file diff --git a/com_oauthserver/administrator/sql/install.mysql.utf8.sql b/com_oauthserver/administrator/sql/install.mysql.utf8.sql new file mode 100644 index 0000000..e78785e --- /dev/null +++ b/com_oauthserver/administrator/sql/install.mysql.utf8.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS `#__webmasterskaya_oauthserver_clients` +( + `id` int unsigned NOT NULL AUTO_INCREMENT, + `client_name` varchar(150) NOT NULL, + `client_token` varchar(255) NOT NULL, + `client_id` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `client_token` (`client_token`), + UNIQUE KEY `client_id` (`client_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + DEFAULT COLLATE = utf8mb4_unicode_ci; \ No newline at end of file diff --git a/com_oauthserver/administrator/sql/uninstall.mysql.utf8.sql b/com_oauthserver/administrator/sql/uninstall.mysql.utf8.sql new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/administrator/sql/updates/mysql/index.html b/com_oauthserver/administrator/sql/updates/mysql/index.html new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/administrator/src/Controller/ClientController.php b/com_oauthserver/administrator/src/Controller/ClientController.php new file mode 100644 index 0000000..9bd94d5 --- /dev/null +++ b/com_oauthserver/administrator/src/Controller/ClientController.php @@ -0,0 +1,17 @@ +loadForm('com_oauthserver.client', 'client', + ['control' => 'jform', 'load_data' => $loadData]); + } +} \ No newline at end of file diff --git a/com_oauthserver/administrator/src/Model/ClientsModel.php b/com_oauthserver/administrator/src/Model/ClientsModel.php new file mode 100644 index 0000000..b857a80 --- /dev/null +++ b/com_oauthserver/administrator/src/Model/ClientsModel.php @@ -0,0 +1,116 @@ +input->get('layout')) { + $this->context .= '.' . $layout; + } + + // List state information + $ordering = empty($ordering) ? 'client.id' : $ordering; + + parent::populateState($ordering, $direction); + } + + /** + * Method to get a store id based on model configuration state. + * + * @param string $id A prefix for the store id. + * + * @return string A store id. + * + * @since 1.0.0 + */ + protected function getStoreId($id = ''): string + { + $id .= ':' . $this->getState('filter.search'); + + return parent::getStoreId($id); + } + + /** + * Method to get a DatabaseQuery object for retrieving the data set from a database. + * + * @return \Joomla\Database\QueryInterface A QueryInterface object to retrieve the data set. + * + * @throws \Exception + * + * @since 1.0.0 + */ + protected function getListQuery(): \Joomla\Database\QueryInterface + { + $db = $this->getDatabase(); + + $query = $db->getQuery(true); + + $query->select(['client.id', 'client.client_name', 'client.client_token', 'client.client_id',]) + ->from($db->qn('#__webmasterskaya_oauthserver_clients', 'client')); + + // Filter by search state + $search = $this->getState('filter.search'); + if (!empty($search)) { + $query->where('client.name LIKE :search') + ->bind(':search', $search, ParameterType::STRING); + } + + // Add the list ordering clause + $ordering = $this->state->get('list.ordering', 'client.id'); + $direction = $this->state->get('list.direction', 'desc'); + $query->order($db->escape($ordering) . ' ' . $db->escape($direction)); + + return $query; + } +} \ No newline at end of file diff --git a/com_oauthserver/administrator/src/Table/ClientTable.php b/com_oauthserver/administrator/src/Table/ClientTable.php new file mode 100644 index 0000000..bcd04a0 --- /dev/null +++ b/com_oauthserver/administrator/src/Table/ClientTable.php @@ -0,0 +1,21 @@ +state = $this->get('State'); + $this->form = $this->get('Form'); + $this->item = $this->get('Item'); + + // Check for errors + if (count($errors = $this->get('Errors'))) { + throw new GenericDataException(implode('\n', $errors), 500); + } + + // Hard set layout + $this->setLayout('edit'); + + // Add title and toolbar + $this->addToolbar(); + + parent::display($tpl); + } + + /** + * Add title and toolbar. + * + * @throws \Exception + * @since 1.0.0 + */ + protected function addToolbar(): void + { + // Hide main menu + Factory::getApplication()->input->set('hidemainmenu', true); + + $canDo = ContentHelper::getActions('com_oauthserver', 'client'); + + $user = $this->getCurrentUser(); + $toolbar = Toolbar::getInstance('toolbar'); + + // Set page title + $isNew = ($this->item->id == 0); + $title = ($isNew) ? Text::_('COM_OAUTHSERVER_CLIENT_ADD') : Text::_('COM_OAUTHSERVER_CLIENT_EDIT'); + ToolbarHelper::title(Text::_('COM_OAUTHSERVER') . ': ' . $title, 'edit'); + + if ($isNew && (count($user->getAuthorisedCategories('com_oauthserver', 'core.create')) > 0)) { + $toolbar->apply('client.apply'); + + $dropdown = $toolbar->dropdownButton('save-group'); + $dropdown->configure( + function (Toolbar $actions) use ($user) { + $actions->save('client.save'); + $actions->save2new('client.save2new'); + } + ); + } else { + $itemEditable = $canDo->get('core.edit'); + if ($itemEditable) { + $toolbar->apply('client.apply'); + } + + $dropdown = $toolbar->dropdownButton('save-group'); + $dropdown->configure( + function (Toolbar $childBar) use ($itemEditable, $canDo) { + if ($itemEditable) { + $childBar->save('client.save'); + if ($canDo->get('core.create')) { + $childBar->save2new('client.save2new'); + } + $childBar + ->standardButton('save-reset', 'COM_OAUTHSERVER_CLIENT_SAVE_AND_RESET') + ->task('client.save2reset') + ->formValidation(true); + } + } + ); + } + + $toolbar->cancel('client.cancel'); + + ToolbarHelper::inlinehelp(); + } +} \ No newline at end of file diff --git a/com_oauthserver/administrator/src/View/Clients/HtmlView.php b/com_oauthserver/administrator/src/View/Clients/HtmlView.php new file mode 100644 index 0000000..6bd8052 --- /dev/null +++ b/com_oauthserver/administrator/src/View/Clients/HtmlView.php @@ -0,0 +1,142 @@ +state = $this->get('State'); + $this->items = $this->get('Items'); + $this->pagination = $this->get('Pagination'); + $this->filterForm = $this->get('FilterForm'); + $this->activeFilters = $this->get('ActiveFilters'); + + // Set empty state + if (empty($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) { + $this->setLayout('emptystate'); + } + + // Check for errors + if (count($errors = $this->get('Errors'))) { + throw new GenericDataException(implode('\n', $errors), 500); + } + + if ($this->getLayout() !== 'modal') { + // Add title and toolbar + $this->addToolbar(); + } + + // Set status field value + $this->filterForm->setValue('status', null, $this->state->get('filter.status')); + + parent::display($tpl); + } + + /** + * Add title and toolbar. + * + * @since 1.0.0 + */ + protected function addToolbar(): void + { + $canDo = ContentHelper::getActions('com_oauthserver', 'clients'); + + $user = $this->getCurrentUser(); + $toolbar = Factory::getContainer()->get(ToolbarFactoryInterface::class)->createToolbar('toolbar'); + + // Set page title + ToolbarHelper::title(Text::_('COM_OAUTHSERVER') . ': ' . Text::_('COM_OAUTHSERVER_CLIENTS')); + + // Add create button + if ($canDo->get('core.create') + || \count($user->getAuthorisedCategories('com_oauthserver', 'core.create')) > 0) { + $toolbar->addNew('client.add'); + } + + // Add actions dropdown + if (!$this->isEmptyState) { + // TODO: Что мы тут в дропдаун пихаем? + } + + // Add preferences button + if ($user->authorise('core.admin', 'com_oauthserver') + || $user->authorise('core.options', 'com_oauthserver')) { + $toolbar->preferences('com_oauthserver'); + } + } +} \ No newline at end of file diff --git a/com_oauthserver/administrator/tmpl/client/edit.php b/com_oauthserver/administrator/tmpl/client/edit.php new file mode 100644 index 0000000..2700610 --- /dev/null +++ b/com_oauthserver/administrator/tmpl/client/edit.php @@ -0,0 +1,49 @@ +document->getWebAssetManager(); +$wa->useScript('keepalive') + ->useScript('form.validate'); + +?> + +
+ + + +
+ 'details', 'recall' => true, 'breakpoint' => 768]); ?> + + + +
+
+
+ +
+ form->renderFieldset('global');?> +
+
+
+
+ + + + + +
+ + + +
+ diff --git a/com_oauthserver/administrator/tmpl/clients/default.php b/com_oauthserver/administrator/tmpl/clients/default.php new file mode 100644 index 0000000..a4abe2d --- /dev/null +++ b/com_oauthserver/administrator/tmpl/clients/default.php @@ -0,0 +1,2 @@ + 'COM_OAUTHSERVER_ORDERS', + 'icon' => 'icon-copy', +]; + +$user = $this->getCurrentUser(); + +if ($user->authorise('core.create', 'com_oauthserver') + || count($user->getAuthorisedCategories('com_oauthserver', 'core.create')) > 0 + || $user->authorise('product.create', 'com_oauthserver') + || count($user->getAuthorisedCategories('com_oauthserver', 'client.create')) > 0 +) { + $displayData['createURL'] = 'index.php?option=com_oauthserver&task=client.add'; +} + +echo LayoutHelper::render('joomla.content.emptystate', $displayData); \ No newline at end of file diff --git a/com_oauthserver/oauthserver.xml b/com_oauthserver/oauthserver.xml new file mode 100644 index 0000000..7410851 --- /dev/null +++ b/com_oauthserver/oauthserver.xml @@ -0,0 +1,67 @@ + + + COM_OAUTHSERVER + COM_OAUTHSERVER_DESCRIPTION + Artem Vasilev + kern.usr@gmial.com + https://webmasterskaya.xyz + March 2024 + Copyright (C) 2024 Webmasterskaya. All rights reserved. + MIT; see LICENSE.txt + RELEASE_VERSION + Webmasterskaya\Component\OauthServer + + + sql/install.mysql.utf8.sql + + + + + sql/uninstall.mysql.utf8.sql + + + + + sql/updates/mysql + + + + forms + src + tmpl + + + language/en-GB/en-GB.com_oauthserver.ini + language/en-GB/en-GB.com_oauthserver.sys.ini + language/ru-RU/ru-RU.com_oauthserver.ini + language/ru-RU/ru-RU.com_oauthserver.sys.ini + + + COM_OAUTHSERVER + + + com_oauthserver_clients + + + + forms + services + sql + src + tmpl + access.xml + config.xml + + + language/en-GB/en-GB.com_oauthserver.ini + language/en-GB/en-GB.com_oauthserver.sys.ini + language/ru-RU/ru-RU.com_oauthserver.ini + language/ru-RU/ru-RU.com_oauthserver.sys.ini + + + \ No newline at end of file diff --git a/com_oauthserver/site/forms/index.html b/com_oauthserver/site/forms/index.html new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/site/language/en-GB/en-GB.com_oauthserver.ini b/com_oauthserver/site/language/en-GB/en-GB.com_oauthserver.ini new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/site/language/en-GB/en-GB.com_oauthserver.sys.ini b/com_oauthserver/site/language/en-GB/en-GB.com_oauthserver.sys.ini new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/site/language/ru-RU/ru-RU.com_oauthserver.ini b/com_oauthserver/site/language/ru-RU/ru-RU.com_oauthserver.ini new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/site/language/ru-RU/ru-RU.com_oauthserver.sys.ini b/com_oauthserver/site/language/ru-RU/ru-RU.com_oauthserver.sys.ini new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/site/src/index.html b/com_oauthserver/site/src/index.html new file mode 100644 index 0000000..e69de29 diff --git a/com_oauthserver/site/tmpl/index.html b/com_oauthserver/site/tmpl/index.html new file mode 100644 index 0000000..e69de29