_JEXEC & copyright

This commit is contained in:
Artem Vasilev 2024-03-09 18:53:58 +03:00
parent ffc26f48a8
commit 16f1f08808

View File

@ -1,4 +1,11 @@
<?php <?php
/**
* @package Joomla.Administrator
* @subpackage com_oauthserver
*
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
* @license MIT; see LICENSE.txt
**/
namespace Webmasterskaya\Component\OauthServer\Administrator\Model; namespace Webmasterskaya\Component\OauthServer\Administrator\Model;
@ -7,6 +14,8 @@ use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form; use Joomla\CMS\Form\Form;
use Joomla\CMS\MVC\Model\AdminModel; use Joomla\CMS\MVC\Model\AdminModel;
\defined('_JEXEC') or die;
class ClientModel extends AdminModel class ClientModel extends AdminModel
{ {
use GetItemByIdentifierTrait; use GetItemByIdentifierTrait;
@ -20,8 +29,9 @@ class ClientModel extends AdminModel
public $typeAlias = 'com_oauthserver.client'; public $typeAlias = 'com_oauthserver.client';
/** /**
* @param array $data * @param array $data
* @param bool $loadData * @param bool $loadData
*
* @return \Joomla\CMS\Form\Form|bool * @return \Joomla\CMS\Form\Form|bool
* @throws \Exception * @throws \Exception
* @since version * @since version
@ -30,7 +40,8 @@ class ClientModel extends AdminModel
{ {
$form = $this->loadForm('com_oauthserver.client', 'client', ['control' => 'jform', 'load_data' => $loadData]); $form = $this->loadForm('com_oauthserver.client', 'client', ['control' => 'jform', 'load_data' => $loadData]);
if (empty($form)) { if (empty($form))
{
return false; return false;
} }
@ -50,7 +61,8 @@ class ClientModel extends AdminModel
// Check the session for previously entered form data. // Check the session for previously entered form data.
$data = Factory::getApplication()->getUserState('com_oauthserver.edit.client.data', []); $data = Factory::getApplication()->getUserState('com_oauthserver.edit.client.data', []);
if (empty($data)) { if (empty($data))
{
$data = $this->getItem(); $data = $this->getItem();
} }
@ -67,26 +79,32 @@ class ClientModel extends AdminModel
} }
/** /**
* @param \Webmasterskaya\Component\OauthServer\Administrator\Table\ClientTable $table * @param \Webmasterskaya\Component\OauthServer\Administrator\Table\ClientTable $table
*
* @return void * @return void
* @throws \Exception * @throws \Exception
* @since version * @since version
*/ */
protected function prepareTable($table): void protected function prepareTable($table): void
{ {
$app = Factory::getApplication(); $app = Factory::getApplication();
$input = $app->getInput(); $input = $app->getInput();
$task = strtolower($input->getCmd('task', '')); $task = strtolower($input->getCmd('task', ''));
if ($task === 'save2reset' || empty($table->id)) { if ($task === 'save2reset' || empty($table->id))
{
$table->identifier = $this->generateNewIdentifier(); $table->identifier = $this->generateNewIdentifier();
$table->secret = !!$table->public ? '' : $this->generateNewSecret(); $table->secret = !!$table->public ? '' : $this->generateNewSecret();
} }
if (!!$table->public) { if (!!$table->public)
{
$table->secret = ''; $table->secret = '';
} else { }
if (empty($table->secret)) { else
{
if (empty($table->secret))
{
$table->secret = $this->generateNewSecret(); $table->secret = $this->generateNewSecret();
} }
} }
@ -105,4 +123,4 @@ class ClientModel extends AdminModel
{ {
return hash('sha512', Crypt::genRandomBytes(32)); return hash('sha512', Crypt::genRandomBytes(32));
} }
} }