2020-11-08 02:28:33 -05:00
|
|
|
<?php
|
|
|
|
/**
|
2023-01-01 09:36:24 -05:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2020-11-08 02:28:33 -05:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-11-05 21:01:06 -04:00
|
|
|
namespace Friendica\Module\Moderation\Users;
|
2020-11-08 02:28:33 -05:00
|
|
|
|
|
|
|
use Friendica\Content\Pager;
|
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\Model\Register;
|
|
|
|
use Friendica\Model\User;
|
2022-11-05 21:01:06 -04:00
|
|
|
use Friendica\Module\Moderation\BaseUsers;
|
2020-11-08 02:28:33 -05:00
|
|
|
|
|
|
|
class Pending extends BaseUsers
|
|
|
|
{
|
2021-11-28 13:44:42 +01:00
|
|
|
protected function post(array $request = [])
|
2020-11-08 02:28:33 -05:00
|
|
|
{
|
2022-11-05 21:01:06 -04:00
|
|
|
$this->checkModerationAccess();
|
2020-11-08 02:28:33 -05:00
|
|
|
|
2022-11-08 04:26:11 -05:00
|
|
|
self::checkFormSecurityTokenRedirectOnError('moderation/users/pending', 'admin_users_pending');
|
2020-11-08 02:28:33 -05:00
|
|
|
|
2022-11-05 21:01:06 -04:00
|
|
|
$pending = $request['pending'] ?? [];
|
2020-11-08 02:28:33 -05:00
|
|
|
|
2022-11-05 21:01:06 -04:00
|
|
|
if (!empty($request['page_users_approve'])) {
|
2020-11-08 02:28:33 -05:00
|
|
|
foreach ($pending as $hash) {
|
|
|
|
User::allow($hash);
|
|
|
|
}
|
2022-11-05 21:01:06 -04:00
|
|
|
$this->systemMessages->addInfo($this->tt('%s user approved', '%s users approved', count($pending)));
|
2020-11-08 02:28:33 -05:00
|
|
|
}
|
|
|
|
|
2022-11-05 21:01:06 -04:00
|
|
|
if (!empty($request['page_users_deny'])) {
|
2020-11-08 02:28:33 -05:00
|
|
|
foreach ($pending as $hash) {
|
|
|
|
User::deny($hash);
|
|
|
|
}
|
2022-11-05 21:01:06 -04:00
|
|
|
$this->systemMessages->addInfo($this->tt('%s registration revoked', '%s registrations revoked', count($pending)));
|
2020-11-08 02:28:33 -05:00
|
|
|
}
|
|
|
|
|
2022-11-08 04:26:11 -05:00
|
|
|
$this->baseUrl->redirect('moderation/users/pending');
|
2020-11-08 02:28:33 -05:00
|
|
|
}
|
|
|
|
|
2021-11-20 15:38:03 +01:00
|
|
|
protected function content(array $request = []): string
|
2020-11-08 02:28:33 -05:00
|
|
|
{
|
2021-11-14 20:46:25 +01:00
|
|
|
parent::content();
|
2020-11-08 02:28:33 -05:00
|
|
|
|
2021-11-14 23:19:25 +01:00
|
|
|
$action = $this->parameters['action'] ?? '';
|
2022-11-05 21:01:06 -04:00
|
|
|
$uid = $this->parameters['uid'] ?? 0;
|
2020-11-08 02:28:33 -05:00
|
|
|
|
|
|
|
if ($uid) {
|
|
|
|
$user = User::getById($uid, ['username', 'blocked']);
|
2022-11-05 21:01:06 -04:00
|
|
|
if (!$user) {
|
|
|
|
$this->systemMessages->addNotice($this->t('User not found'));
|
2022-11-08 04:26:11 -05:00
|
|
|
$this->baseUrl->redirect('moderation/users');
|
2020-11-08 02:28:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
case 'allow':
|
2022-11-08 04:26:11 -05:00
|
|
|
self::checkFormSecurityTokenRedirectOnError('moderation/users/pending', 'admin_users_pending', 't');
|
2020-11-08 02:28:33 -05:00
|
|
|
User::allow(Register::getPendingForUser($uid)['hash'] ?? '');
|
2022-11-05 21:01:06 -04:00
|
|
|
$this->systemMessages->addNotice($this->t('Account approved.'));
|
2022-11-08 04:26:11 -05:00
|
|
|
$this->baseUrl->redirect('moderation/users/pending');
|
2020-11-08 02:28:33 -05:00
|
|
|
break;
|
|
|
|
case 'deny':
|
2022-11-08 04:26:11 -05:00
|
|
|
self::checkFormSecurityTokenRedirectOnError('moderation/users/pending', 'admin_users_pending', 't');
|
2020-11-08 02:28:33 -05:00
|
|
|
User::deny(Register::getPendingForUser($uid)['hash'] ?? '');
|
2022-11-05 21:01:06 -04:00
|
|
|
$this->systemMessages->addNotice($this->t('Registration revoked'));
|
2022-11-08 04:26:11 -05:00
|
|
|
$this->baseUrl->redirect('moderation/users/pending');
|
2020-11-08 02:28:33 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-11-05 21:01:06 -04:00
|
|
|
$pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
|
2020-11-08 02:28:33 -05:00
|
|
|
|
|
|
|
$pending = Register::getPending($pager->getStart(), $pager->getItemsPerPage());
|
|
|
|
|
|
|
|
$count = Register::getPendingCount();
|
|
|
|
|
2022-11-08 04:26:11 -05:00
|
|
|
$t = Renderer::getMarkupTemplate('moderation/users/pending.tpl');
|
2020-11-08 02:28:33 -05:00
|
|
|
return self::getTabsHTML('pending') . Renderer::replaceMacros($t, [
|
|
|
|
// strings //
|
2022-11-05 21:01:06 -04:00
|
|
|
'$title' => $this->t('Administration'),
|
|
|
|
'$page' => $this->t('User registrations awaiting review'),
|
|
|
|
'$select_all' => $this->t('select all'),
|
|
|
|
'$th_pending' => [$this->t('Request date'), $this->t('Name'), $this->t('Email')],
|
|
|
|
'$no_pending' => $this->t('No registrations.'),
|
|
|
|
'$pendingnotetext' => $this->t('Note from the user'),
|
|
|
|
'$approve' => $this->t('Approve'),
|
|
|
|
'$deny' => $this->t('Deny'),
|
2020-11-08 02:28:33 -05:00
|
|
|
|
|
|
|
'$form_security_token' => self::getFormSecurityToken('admin_users_pending'),
|
|
|
|
|
|
|
|
// values //
|
2023-02-18 20:57:30 +01:00
|
|
|
'$baseurl' => $this->baseUrl,
|
2022-11-05 21:01:06 -04:00
|
|
|
'$query_string' => $this->args->getQueryString(),
|
2020-11-08 02:28:33 -05:00
|
|
|
|
|
|
|
'$pending' => $pending,
|
|
|
|
'$count' => $count,
|
|
|
|
'$pager' => $pager->renderFull($count),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|