]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Users/Create.php
Merge pull request #10309 from fabrixxm/feature/advanced-logsview
[friendica.git] / src / Module / Admin / Users / Create.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, 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\Admin\Users;
23
24 use Friendica\Core\Renderer;
25 use Friendica\DI;
26 use Friendica\Model\User;
27 use Friendica\Module\Admin\BaseUsers;
28
29 class Create extends BaseUsers
30 {
31         public static function post(array $parameters = [])
32         {
33                 self::checkAdminAccess();
34
35                 self::checkFormSecurityTokenRedirectOnError('/admin/users/create', 'admin_users_create');
36
37                 $nu_name     = $_POST['new_user_name']     ?? '';
38                 $nu_nickname = $_POST['new_user_nickname'] ?? '';
39                 $nu_email    = $_POST['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                                 DI::baseUrl()->redirect('admin/users');
46                         } catch (\Exception $ex) {
47                                 notice($ex->getMessage());
48                         }
49                 }
50
51                 DI::baseUrl()->redirect('admin/users/create');
52         }
53
54         public static function content(array $parameters = [])
55         {
56                 parent::content($parameters);
57
58                 $t = Renderer::getMarkupTemplate('admin/users/create.tpl');
59                 return self::getTabsHTML('all') . Renderer::replaceMacros($t, [
60                         // strings //
61                         '$title' => DI::l10n()->t('Administration'),
62                         '$page' => DI::l10n()->t('New User'),
63                         '$submit' => DI::l10n()->t('Add User'),
64
65                         '$form_security_token' => self::getFormSecurityToken('admin_users_create'),
66
67                         // values //
68                         '$baseurl' => DI::baseUrl()->get(true),
69                         '$query_string' => DI::args()->getQueryString(),
70
71                         '$newusername' => ['new_user_name', DI::l10n()->t('Name'), '', DI::l10n()->t('Name of the new user.')],
72                         '$newusernickname' => ['new_user_nickname', DI::l10n()->t('Nickname'), '', DI::l10n()->t('Nickname of the new user.')],
73                         '$newuseremail' => ['new_user_email', DI::l10n()->t('Email'), '', DI::l10n()->t('Email address of the new user.'), '', '', 'email'],
74                 ]);
75         }
76 }