]> git.mxchange.org Git - friendica.git/blob - src/Module/Moderation/Users/Create.php
Merge pull request #12169 from MrPetovan/bug/7574-notifications-deleted-users
[friendica.git] / src / Module / Moderation / Users / Create.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Module\Moderation\Users;
23
24 use Friendica\Core\Renderer;
25 use Friendica\DI;
26 use Friendica\Model\User;
27 use Friendica\Module\Moderation\BaseUsers;
28
29 class Create extends BaseUsers
30 {
31         protected function post(array $request = [])
32         {
33                 $this->checkModerationAccess();
34
35                 self::checkFormSecurityTokenRedirectOnError('moderation/users/create', 'admin_users_create');
36
37                 $nu_name     = $request['new_user_name'] ?? '';
38                 $nu_nickname = $request['new_user_nickname'] ?? '';
39                 $nu_email    = $request['new_user_email'] ?? '';
40                 $nu_language = DI::config()->get('system', 'language');
41
42                 if ($nu_name !== '' && $nu_email !== '' && $nu_nickname !== '') {
43                         try {
44                                 User::createMinimal($nu_name, $nu_email, $nu_nickname, $nu_language);
45                                 $this->baseUrl->redirect('moderation/users');
46                         } catch (\Exception $ex) {
47                                 $this->systemMessages->addNotice($ex->getMessage());
48                         }
49                 }
50
51                 $this->baseUrl->redirect('moderation/users/create');
52         }
53
54         protected function content(array $request = []): string
55         {
56                 parent::content();
57
58                 $t = Renderer::getMarkupTemplate('moderation/users/create.tpl');
59                 return self::getTabsHTML('all') . Renderer::replaceMacros($t, [
60                         // strings //
61                         '$title'  => $this->t('Administration'),
62                         '$page'   => $this->t('New User'),
63                         '$submit' => $this->t('Add User'),
64
65                         '$form_security_token' => self::getFormSecurityToken('admin_users_create'),
66
67                         // values //
68                         '$baseurl'      => $this->baseUrl->get(true),
69                         '$query_string' => $this->args->getQueryString(),
70
71                         '$newusername'     => ['new_user_name', $this->t('Name'), '', $this->t('Name of the new user.')],
72                         '$newusernickname' => ['new_user_nickname', $this->t('Nickname'), '', $this->t('Nickname of the new user.')],
73                         '$newuseremail'    => ['new_user_email', $this->t('Email'), '', $this->t('Email address of the new user.'), '', '', 'email'],
74                 ]);
75         }
76 }