3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Admin\Users;
24 use Friendica\Content\Pager;
25 use Friendica\Core\Renderer;
26 use Friendica\Database\DBA;
28 use Friendica\Model\Register;
29 use Friendica\Model\User;
30 use Friendica\Module\Admin\BaseUsers;
31 use Friendica\Module\BaseAdmin;
32 use Friendica\Util\Temporal;
34 class Pending extends BaseUsers
36 public static function post(array $parameters = [])
38 self::checkAdminAccess();
40 self::checkFormSecurityTokenRedirectOnError('/admin/users/pending', 'admin_users_pending');
42 $pending = $_POST['pending'] ?? [];
44 if (!empty($_POST['page_users_approve'])) {
45 foreach ($pending as $hash) {
48 info(DI::l10n()->tt('%s user approved', '%s users approved', count($pending)));
51 if (!empty($_POST['page_users_deny'])) {
52 foreach ($pending as $hash) {
55 info(DI::l10n()->tt('%s registration revoked', '%s registrations revoked', count($pending)));
58 DI::baseUrl()->redirect('admin/users/pending');
61 public static function content(array $parameters = [])
63 parent::content($parameters);
65 $action = $parameters['action'] ?? '';
66 $uid = $parameters['uid'] ?? 0;
69 $user = User::getById($uid, ['username', 'blocked']);
70 if (!DBA::isResult($user)) {
71 notice(DI::l10n()->t('User not found'));
72 DI::baseUrl()->redirect('admin/users');
73 return ''; // NOTREACHED
79 self::checkFormSecurityTokenRedirectOnError('/admin/users/pending', 'admin_users_pending', 't');
80 User::allow(Register::getPendingForUser($uid)['hash'] ?? '');
81 notice(DI::l10n()->t('Account approved.'));
82 DI::baseUrl()->redirect('admin/users/pending');
85 self::checkFormSecurityTokenRedirectOnError('/admin/users/pending', 'admin_users_pending', 't');
86 User::deny(Register::getPendingForUser($uid)['hash'] ?? '');
87 notice(DI::l10n()->t('Registration revoked'));
88 DI::baseUrl()->redirect('admin/users/pending');
92 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 100);
94 $pending = Register::getPending($pager->getStart(), $pager->getItemsPerPage());
96 $count = Register::getPendingCount();
98 $t = Renderer::getMarkupTemplate('admin/users/pending.tpl');
99 return self::getTabsHTML('pending') . Renderer::replaceMacros($t, [
101 '$title' => DI::l10n()->t('Administration'),
102 '$page' => DI::l10n()->t('User registrations awaiting review'),
103 '$select_all' => DI::l10n()->t('select all'),
104 '$th_pending' => [DI::l10n()->t('Request date'), DI::l10n()->t('Name'), DI::l10n()->t('Email')],
105 '$no_pending' => DI::l10n()->t('No registrations.'),
106 '$pendingnotetext' => DI::l10n()->t('Note from the user'),
107 '$approve' => DI::l10n()->t('Approve'),
108 '$deny' => DI::l10n()->t('Deny'),
110 '$form_security_token' => self::getFormSecurityToken('admin_users_pending'),
113 '$baseurl' => DI::baseUrl()->get(true),
114 '$query_string' => DI::args()->getQueryString(),
116 '$pending' => $pending,
118 '$pager' => $pager->renderFull($count),