primo commit
This commit is contained in:
41
api/components/com_users/src/Controller/GroupsController.php
Normal file
41
api/components/com_users/src/Controller/GroupsController.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.API
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Users\Api\Controller;
|
||||
|
||||
use Joomla\CMS\MVC\Controller\ApiController;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* The groups controller
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class GroupsController extends ApiController
|
||||
{
|
||||
/**
|
||||
* The content type of the item.
|
||||
*
|
||||
* @var string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $contentType = 'groups';
|
||||
|
||||
/**
|
||||
* The default view for the display method.
|
||||
*
|
||||
* @var string
|
||||
* @since 3.0
|
||||
*/
|
||||
protected $default_view = 'groups';
|
||||
}
|
||||
41
api/components/com_users/src/Controller/LevelsController.php
Normal file
41
api/components/com_users/src/Controller/LevelsController.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.API
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Users\Api\Controller;
|
||||
|
||||
use Joomla\CMS\MVC\Controller\ApiController;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* The levels controller
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class LevelsController extends ApiController
|
||||
{
|
||||
/**
|
||||
* The content type of the item.
|
||||
*
|
||||
* @var string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $contentType = 'levels';
|
||||
|
||||
/**
|
||||
* The default view for the display method.
|
||||
*
|
||||
* @var string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $default_view = 'levels';
|
||||
}
|
||||
181
api/components/com_users/src/Controller/UsersController.php
Normal file
181
api/components/com_users/src/Controller/UsersController.php
Normal file
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.API
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Users\Api\Controller;
|
||||
|
||||
use Joomla\CMS\Date\Date;
|
||||
use Joomla\CMS\Filter\InputFilter;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\ApiController;
|
||||
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
|
||||
use Tobscure\JsonApi\Exception\InvalidParameterException;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* The users controller
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class UsersController extends ApiController
|
||||
{
|
||||
/**
|
||||
* The content type of the item.
|
||||
*
|
||||
* @var string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $contentType = 'users';
|
||||
|
||||
/**
|
||||
* The default view for the display method.
|
||||
*
|
||||
* @var string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $default_view = 'users';
|
||||
|
||||
/**
|
||||
* Method to allow extended classes to manipulate the data to be saved for an extension.
|
||||
*
|
||||
* @param array $data An array of input data.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function preprocessSaveData(array $data): array
|
||||
{
|
||||
foreach (FieldsHelper::getFields('com_users.user') as $field) {
|
||||
if (isset($data[$field->name])) {
|
||||
!isset($data['com_fields']) && $data['com_fields'] = [];
|
||||
|
||||
$data['com_fields'][$field->name] = $data[$field->name];
|
||||
unset($data[$field->name]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->input->getMethod() === 'PATCH') {
|
||||
$body = $this->input->get('data', json_decode($this->input->json->getRaw(), true), 'array');
|
||||
|
||||
if (!\array_key_exists('password', $body)) {
|
||||
unset($data['password']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->input->getMethod() === 'POST') {
|
||||
if (isset($data['password'])) {
|
||||
$data['password2'] = $data['password'];
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* User list view with filtering of data
|
||||
*
|
||||
* @return static A BaseController object to support chaining.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws InvalidParameterException
|
||||
*/
|
||||
public function displayList()
|
||||
{
|
||||
$apiFilterInfo = $this->input->get('filter', [], 'array');
|
||||
$filter = InputFilter::getInstance();
|
||||
|
||||
if (\array_key_exists('state', $apiFilterInfo)) {
|
||||
$this->modelState->set('filter.state', $filter->clean($apiFilterInfo['state'], 'INT'));
|
||||
}
|
||||
|
||||
if (\array_key_exists('active', $apiFilterInfo)) {
|
||||
$this->modelState->set('filter.active', $filter->clean($apiFilterInfo['active'], 'INT'));
|
||||
}
|
||||
|
||||
if (\array_key_exists('groupid', $apiFilterInfo)) {
|
||||
$this->modelState->set('filter.group_id', $filter->clean($apiFilterInfo['groupid'], 'INT'));
|
||||
}
|
||||
|
||||
if (\array_key_exists('search', $apiFilterInfo)) {
|
||||
$this->modelState->set('filter.search', $filter->clean($apiFilterInfo['search'], 'STRING'));
|
||||
}
|
||||
|
||||
if (\array_key_exists('registrationDateStart', $apiFilterInfo)) {
|
||||
$registrationStartInput = $filter->clean($apiFilterInfo['registrationDateStart'], 'STRING');
|
||||
$registrationStartDate = Date::createFromFormat(\DateTimeInterface::RFC3339, $registrationStartInput);
|
||||
|
||||
if (!$registrationStartDate) {
|
||||
// Send the error response
|
||||
$error = Text::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', 'registrationDateStart');
|
||||
|
||||
throw new InvalidParameterException($error, 400, null, 'registrationDateStart');
|
||||
}
|
||||
|
||||
$this->modelState->set('filter.registrationDateStart', $registrationStartDate);
|
||||
}
|
||||
|
||||
if (\array_key_exists('registrationDateEnd', $apiFilterInfo)) {
|
||||
$registrationEndInput = $filter->clean($apiFilterInfo['registrationDateEnd'], 'STRING');
|
||||
$registrationEndDate = Date::createFromFormat(\DateTimeInterface::RFC3339, $registrationEndInput);
|
||||
|
||||
if (!$registrationEndDate) {
|
||||
// Send the error response
|
||||
$error = Text::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', 'registrationDateEnd');
|
||||
throw new InvalidParameterException($error, 400, null, 'registrationDateEnd');
|
||||
}
|
||||
|
||||
$this->modelState->set('filter.registrationDateEnd', $registrationEndDate);
|
||||
} elseif (
|
||||
\array_key_exists('registrationDateStart', $apiFilterInfo)
|
||||
&& !\array_key_exists('registrationDateEnd', $apiFilterInfo)
|
||||
) {
|
||||
// If no end date specified the end date is now
|
||||
$this->modelState->set('filter.registrationDateEnd', new Date());
|
||||
}
|
||||
|
||||
if (\array_key_exists('lastVisitDateStart', $apiFilterInfo)) {
|
||||
$lastVisitStartInput = $filter->clean($apiFilterInfo['lastVisitDateStart'], 'STRING');
|
||||
$lastVisitStartDate = Date::createFromFormat(\DateTimeInterface::RFC3339, $lastVisitStartInput);
|
||||
|
||||
if (!$lastVisitStartDate) {
|
||||
// Send the error response
|
||||
$error = Text::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', 'lastVisitDateStart');
|
||||
throw new InvalidParameterException($error, 400, null, 'lastVisitDateStart');
|
||||
}
|
||||
|
||||
$this->modelState->set('filter.lastVisitStart', $lastVisitStartDate);
|
||||
}
|
||||
|
||||
if (\array_key_exists('lastVisitDateEnd', $apiFilterInfo)) {
|
||||
$lastVisitEndInput = $filter->clean($apiFilterInfo['lastVisitDateEnd'], 'STRING');
|
||||
$lastVisitEndDate = Date::createFromFormat(\DateTimeInterface::RFC3339, $lastVisitEndInput);
|
||||
|
||||
if (!$lastVisitEndDate) {
|
||||
// Send the error response
|
||||
$error = Text::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', 'lastVisitDateEnd');
|
||||
|
||||
throw new InvalidParameterException($error, 400, null, 'lastVisitDateEnd');
|
||||
}
|
||||
|
||||
$this->modelState->set('filter.lastVisitEnd', $lastVisitEndDate);
|
||||
} elseif (
|
||||
\array_key_exists('lastVisitDateStart', $apiFilterInfo)
|
||||
&& !\array_key_exists('lastVisitDateEnd', $apiFilterInfo)
|
||||
) {
|
||||
// If no end date specified the end date is now
|
||||
$this->modelState->set('filter.lastVisitEnd', new Date());
|
||||
}
|
||||
|
||||
return parent::displayList();
|
||||
}
|
||||
}
|
||||
53
api/components/com_users/src/View/Groups/JsonapiView.php
Normal file
53
api/components/com_users/src/View/Groups/JsonapiView.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.API
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Users\Api\View\Groups;
|
||||
|
||||
use Joomla\CMS\MVC\View\JsonApiView as BaseApiView;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* The groups view
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class JsonapiView extends BaseApiView
|
||||
{
|
||||
/**
|
||||
* The fields to render item in the documents
|
||||
*
|
||||
* @var array
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $fieldsToRenderItem = [
|
||||
'id',
|
||||
'parent_id',
|
||||
'lft',
|
||||
'rgt',
|
||||
'title',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fields to render items in the documents
|
||||
*
|
||||
* @var array
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $fieldsToRenderList = [
|
||||
'id',
|
||||
'parent_id',
|
||||
'lft',
|
||||
'rgt',
|
||||
'title',
|
||||
];
|
||||
}
|
||||
49
api/components/com_users/src/View/Levels/JsonapiView.php
Normal file
49
api/components/com_users/src/View/Levels/JsonapiView.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.API
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Users\Api\View\Levels;
|
||||
|
||||
use Joomla\CMS\MVC\View\JsonApiView as BaseApiView;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* The levels view
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class JsonapiView extends BaseApiView
|
||||
{
|
||||
/**
|
||||
* The fields to render item in the documents
|
||||
*
|
||||
* @var array
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $fieldsToRenderItem = [
|
||||
'id',
|
||||
'title',
|
||||
'rules',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fields to render items in the documents
|
||||
*
|
||||
* @var array
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $fieldsToRenderList = [
|
||||
'id',
|
||||
'title',
|
||||
'rules',
|
||||
];
|
||||
}
|
||||
126
api/components/com_users/src/View/Users/JsonapiView.php
Normal file
126
api/components/com_users/src/View/Users/JsonapiView.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.API
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Users\Api\View\Users;
|
||||
|
||||
use Joomla\CMS\MVC\View\JsonApiView as BaseApiView;
|
||||
use Joomla\CMS\Router\Exception\RouteNotFoundException;
|
||||
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* The users view
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class JsonapiView extends BaseApiView
|
||||
{
|
||||
/**
|
||||
* The fields to render item in the documents
|
||||
*
|
||||
* @var array
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $fieldsToRenderItem = [
|
||||
'id',
|
||||
'groups',
|
||||
'name',
|
||||
'username',
|
||||
'email',
|
||||
'registerDate',
|
||||
'lastvisitDate',
|
||||
'lastResetTime',
|
||||
'resetCount',
|
||||
'sendEmail',
|
||||
'block',
|
||||
];
|
||||
|
||||
/**
|
||||
* The fields to render items in the documents
|
||||
*
|
||||
* @var array
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $fieldsToRenderList = [
|
||||
'id',
|
||||
'name',
|
||||
'username',
|
||||
'email',
|
||||
'group_count',
|
||||
'group_names',
|
||||
'registerDate',
|
||||
'lastvisitDate',
|
||||
'lastResetTime',
|
||||
'resetCount',
|
||||
'sendEmail',
|
||||
'block',
|
||||
];
|
||||
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param ?array $items Array of items
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function displayList(?array $items = null)
|
||||
{
|
||||
foreach (FieldsHelper::getFields('com_users.user') as $field) {
|
||||
$this->fieldsToRenderList[] = $field->name;
|
||||
}
|
||||
|
||||
return parent::displayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param object $item Item
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function displayItem($item = null)
|
||||
{
|
||||
foreach (FieldsHelper::getFields('com_users.user') as $field) {
|
||||
$this->fieldsToRenderItem[] = $field->name;
|
||||
}
|
||||
|
||||
return parent::displayItem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare item before render.
|
||||
*
|
||||
* @param object $item The model item
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function prepareItem($item)
|
||||
{
|
||||
if (empty($item->username)) {
|
||||
throw new RouteNotFoundException('Item does not exist');
|
||||
}
|
||||
|
||||
foreach (FieldsHelper::getFields('com_users.user', $item, true) as $field) {
|
||||
$item->{$field->name} = $field->apivalue ?? $field->rawvalue;
|
||||
}
|
||||
|
||||
return parent::prepareItem($item);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user