mirror of
https://github.com/webmasterskaya/joomla-oauth-server.git
synced 2024-11-23 22:34:50 +03:00
_JEXEC & copyright
This commit is contained in:
parent
16f1f08808
commit
f821c9becb
@ -1,4 +1,11 @@
|
||||
<?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;
|
||||
|
||||
@ -6,6 +13,9 @@ use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Joomla\CMS\MVC\Model\ListModel;
|
||||
use Joomla\Database\ParameterType;
|
||||
use Joomla\Database\QueryInterface;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
class ClientsModel extends ListModel
|
||||
{
|
||||
@ -31,7 +41,8 @@ class ClientsModel extends ListModel
|
||||
public function __construct($config = [], MVCFactoryInterface $factory = null)
|
||||
{
|
||||
// Add the ordering filtering fields whitelist
|
||||
if (empty($config['filter_fields'])) {
|
||||
if (empty($config['filter_fields']))
|
||||
{
|
||||
$config['filter_fields'] = [
|
||||
'id', 'client.id'
|
||||
];
|
||||
@ -55,7 +66,8 @@ class ClientsModel extends ListModel
|
||||
$app = Factory::getApplication();
|
||||
|
||||
// Adjust the context to support modal layouts.
|
||||
if ($layout = $app->input->get('layout')) {
|
||||
if ($layout = $app->input->get('layout'))
|
||||
{
|
||||
$this->context .= '.' . $layout;
|
||||
}
|
||||
|
||||
@ -84,13 +96,13 @@ class ClientsModel extends ListModel
|
||||
/**
|
||||
* 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.
|
||||
* @return QueryInterface A QueryInterface object to retrieve the data set.
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function getListQuery(): \Joomla\Database\QueryInterface
|
||||
protected function getListQuery(): QueryInterface
|
||||
{
|
||||
$db = $this->getDatabase();
|
||||
|
||||
@ -101,7 +113,8 @@ class ClientsModel extends ListModel
|
||||
|
||||
// Filter by search state
|
||||
$search = $this->getState('filter.search');
|
||||
if (!empty($search)) {
|
||||
if (!empty($search))
|
||||
{
|
||||
$query->where('client.name LIKE :search')
|
||||
->bind(':search', $search, ParameterType::STRING);
|
||||
}
|
||||
|
@ -1,30 +1,37 @@
|
||||
<?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;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Object\CMSObject;
|
||||
use Joomla\CMS\Table\Table;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
trait GetItemByIdentifierTrait
|
||||
{
|
||||
abstract public function getState($property = null, $default = null);
|
||||
|
||||
abstract public function getName();
|
||||
|
||||
abstract public function getTable($name = '', $prefix = '', $options = []);
|
||||
|
||||
public function getItemByIdentifier($identifier = null): object
|
||||
{
|
||||
$identifier = (!empty($identifier)) ? $identifier : (int) $this->getState($this->getName() . '.identifier');
|
||||
/** @var \Joomla\CMS\Table\Table $table */
|
||||
/** @var Table $table */
|
||||
$table = $this->getTable();
|
||||
|
||||
if (!empty($identifier)) {
|
||||
if (!empty($identifier))
|
||||
{
|
||||
$return = $table->load(['identifier' => $identifier]);
|
||||
|
||||
if ($return === false) {
|
||||
if (method_exists($table, 'getError') && $table->getError()) {
|
||||
if ($return === false)
|
||||
{
|
||||
if (method_exists($table, 'getError') && $table->getError())
|
||||
{
|
||||
throw new \RuntimeException($table->getError());
|
||||
}
|
||||
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_NOT_EXIST'));
|
||||
@ -35,9 +42,12 @@ trait GetItemByIdentifierTrait
|
||||
$properties = $table->getProperties(true);
|
||||
$all_properties = $table->getProperties(false);
|
||||
|
||||
if (!empty($all_properties['_jsonEncode'])) {
|
||||
foreach ($all_properties['_jsonEncode'] as $prop) {
|
||||
if (array_key_exists($prop, $properties) && is_string($properties[$prop])) {
|
||||
if (!empty($all_properties['_jsonEncode']))
|
||||
{
|
||||
foreach ($all_properties['_jsonEncode'] as $prop)
|
||||
{
|
||||
if (array_key_exists($prop, $properties) && is_string($properties[$prop]))
|
||||
{
|
||||
$properties[$prop] = json_decode($properties[$prop]);
|
||||
}
|
||||
}
|
||||
@ -45,4 +55,10 @@ trait GetItemByIdentifierTrait
|
||||
|
||||
return ArrayHelper::toObject($properties, CMSObject::class, true);
|
||||
}
|
||||
|
||||
abstract public function getState($property = null, $default = null);
|
||||
|
||||
abstract public function getName();
|
||||
|
||||
abstract public function getTable($name = '', $prefix = '', $options = []);
|
||||
}
|
@ -1,10 +1,20 @@
|
||||
<?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;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\MVC\Model\AdminModel;
|
||||
use Webmasterskaya\Component\OauthServer\Administrator\Table\RefreshTokenTable;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
class RefreshTokenModel extends AdminModel implements RevokedModelInterface
|
||||
{
|
||||
@ -15,19 +25,26 @@ class RefreshTokenModel extends AdminModel implements RevokedModelInterface
|
||||
{
|
||||
$form = $this->loadForm('com_oauthserver.refresh_token', 'refresh_token', ['control' => 'jform', 'load_data' => $loadData]);
|
||||
|
||||
if (empty($form)) {
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function getTable($name = 'RefreshToken', $prefix = 'Administrator', $options = [])
|
||||
{
|
||||
return parent::getTable($name, $prefix, $options);
|
||||
}
|
||||
|
||||
protected function loadFormData(): mixed
|
||||
{
|
||||
// Check the session for previously entered form data.
|
||||
$data = Factory::getApplication()->getUserState('com_oauthserver.edit.refresh_token.data', []);
|
||||
|
||||
if (empty($data)) {
|
||||
if (empty($data))
|
||||
{
|
||||
$data = $this->getItem();
|
||||
}
|
||||
|
||||
@ -37,19 +54,16 @@ class RefreshTokenModel extends AdminModel implements RevokedModelInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Webmasterskaya\Component\OauthServer\Administrator\Table\RefreshTokenTable $table
|
||||
* @param RefreshTokenTable $table
|
||||
*
|
||||
* @return void
|
||||
* @since version
|
||||
*/
|
||||
protected function prepareTable($table)
|
||||
{
|
||||
if ($table->expiry instanceof \DateTime || $table->expiry instanceof \DateTimeImmutable) {
|
||||
if ($table->expiry instanceof \DateTime || $table->expiry instanceof \DateTimeImmutable)
|
||||
{
|
||||
$table->expiry = $table->expiry->format($table->getDbo()->getDateFormat());
|
||||
}
|
||||
}
|
||||
|
||||
public function getTable($name = 'RefreshToken', $prefix = 'Administrator', $options = [])
|
||||
{
|
||||
return parent::getTable($name, $prefix, $options);
|
||||
}
|
||||
}
|
@ -1,7 +1,16 @@
|
||||
<?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;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
interface RevokedModelInterface
|
||||
{
|
||||
public function revoke(&$identifiers): bool;
|
||||
|
@ -1,11 +1,21 @@
|
||||
<?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;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Table\Table;
|
||||
use Joomla\CMS\User\User;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
trait RevokedModelTrait
|
||||
{
|
||||
/**
|
||||
@ -43,18 +53,10 @@ trait RevokedModelTrait
|
||||
*/
|
||||
protected $event_change_state;
|
||||
|
||||
abstract public function getTable($name = '', $prefix = '', $options = []);
|
||||
|
||||
abstract protected function getCurrentUser(): User;
|
||||
|
||||
abstract public function setError($error);
|
||||
|
||||
abstract protected function cleanCache($group = null);
|
||||
|
||||
public function revoke(&$identifiers): bool
|
||||
{
|
||||
$user = $this->getCurrentUser();
|
||||
/** @var \Joomla\CMS\Table\Table $table */
|
||||
/** @var Table $table */
|
||||
$table = $this->getTable();
|
||||
$identifiers = (array) $identifiers;
|
||||
$pks = [];
|
||||
@ -64,36 +66,44 @@ trait RevokedModelTrait
|
||||
// Include the plugins for the change of state event.
|
||||
PluginHelper::importPlugin($this->events_map['change_state']);
|
||||
|
||||
foreach ($identifiers as $i => $identifier) {
|
||||
foreach ($identifiers as $i => $identifier)
|
||||
{
|
||||
$table->reset();
|
||||
|
||||
if ($table->load(['identifier' => $identifier])) {
|
||||
if ($table->load(['identifier' => $identifier]))
|
||||
{
|
||||
$revokedColumnName = $table->getColumnAlias('revoked');
|
||||
|
||||
if (property_exists($table, $revokedColumnName) && $table->get($revokedColumnName, 1) == 0) {
|
||||
if (property_exists($table, $revokedColumnName) && $table->get($revokedColumnName, 1) == 0)
|
||||
{
|
||||
unset($identifiers[$i]);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$pks[] = $table->get('id');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if there are items to change
|
||||
if (!\count($pks)) {
|
||||
if (!\count($pks))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Trigger the before change state event.
|
||||
$result = Factory::getApplication()->triggerEvent($this->event_before_change_state, [$context, $pks, 0]);
|
||||
|
||||
if (\in_array(false, $result, true)) {
|
||||
if (\in_array(false, $result, true))
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Attempt to change the state of the records.
|
||||
if (!$table->revoke($pks, $user->id)) {
|
||||
if (!$table->revoke($pks, $user->id))
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
|
||||
return false;
|
||||
@ -102,7 +112,8 @@ trait RevokedModelTrait
|
||||
// Trigger the change state event.
|
||||
$result = Factory::getApplication()->triggerEvent($this->event_change_state, [$context, $pks, 0]);
|
||||
|
||||
if (\in_array(false, $result, true)) {
|
||||
if (\in_array(false, $result, true))
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
|
||||
return false;
|
||||
@ -113,4 +124,12 @@ trait RevokedModelTrait
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
abstract protected function getCurrentUser(): User;
|
||||
|
||||
abstract public function getTable($name = '', $prefix = '', $options = []);
|
||||
|
||||
abstract public function setError($error);
|
||||
|
||||
abstract protected function cleanCache($group = null);
|
||||
}
|
@ -1,4 +1,11 @@
|
||||
<?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;
|
||||
|
||||
@ -6,11 +13,12 @@ use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\MVC\Model\BaseModel;
|
||||
use Joomla\CMS\MVC\Model\ItemModelInterface;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
class ScopeModel extends BaseModel implements ItemModelInterface
|
||||
{
|
||||
private static array $_storage;
|
||||
|
||||
private const PREDEFINED_SCOPES = ['userinfo', 'email'];
|
||||
private static array $_storage;
|
||||
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user