]> git.mxchange.org Git - friendica.git/blob - mod/register.php
Improve Console/Config display for array values
[friendica.git] / mod / register.php
1 <?php
2 /**
3  * @file mod/register.php
4  */
5
6 use Friendica\App;
7 use Friendica\Content\Text\BBCode;
8 use Friendica\Core\Addon;
9 use Friendica\Core\Config;
10 use Friendica\Core\L10n;
11 use Friendica\Core\PConfig;
12 use Friendica\Core\System;
13 use Friendica\Core\Worker;
14 use Friendica\Model\User;
15 use Friendica\Module\Tos;
16 use Friendica\Util\DateTimeFormat;
17
18 require_once 'include/enotify.php';
19
20 function register_post(App $a)
21 {
22         check_form_security_token_redirectOnErr('/register', 'register');
23
24         $verified = 0;
25         $blocked  = 1;
26
27         $arr = ['post' => $_POST];
28         Addon::callHooks('register_post', $arr);
29
30         $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
31         if ($max_dailies) {
32                 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
33                 if ($r && $r[0]['total'] >= $max_dailies) {
34                         return;
35                 }
36         }
37
38         switch (Config::get('config', 'register_policy')) {
39                 case REGISTER_OPEN:
40                         $blocked = 0;
41                         $verified = 1;
42                         break;
43
44                 case REGISTER_APPROVE:
45                         $blocked = 1;
46                         $verified = 0;
47                         break;
48
49                 default:
50                 case REGISTER_CLOSED:
51                         if (empty($_SESSION['authenticated']) && empty($_SESSION['administrator'])) {
52                                 notice(L10n::t('Permission denied.') . EOL);
53                                 return;
54                         }
55                         $blocked = 1;
56                         $verified = 0;
57                         break;
58         }
59
60         $netpublish = !empty($_POST['profile_publish_reg']);
61
62         $arr = $_POST;
63
64         $arr['blocked'] = $blocked;
65         $arr['verified'] = $verified;
66         $arr['language'] = L10n::getBrowserLanguage();
67
68         try {
69                 $result = User::create($arr);
70         } catch (Exception $e) {
71                 notice($e->getMessage());
72                 return;
73         }
74
75         $user = $result['user'];
76
77         if ($netpublish && intval(Config::get('config', 'register_policy')) !== REGISTER_APPROVE) {
78                 $url = System::baseUrl() . '/profile/' . $user['nickname'];
79                 Worker::add(PRIORITY_LOW, "Directory", $url);
80         }
81
82         $using_invites = Config::get('system', 'invitation_only');
83         $num_invites   = Config::get('system', 'number_invites');
84         $invite_id = ((x($_POST, 'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
85
86         if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN) {
87                 if ($using_invites && $invite_id) {
88                         q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
89                         PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
90                 }
91
92                 // Only send a password mail when the password wasn't manually provided
93                 if (!x($_POST, 'password1') || !x($_POST, 'confirm')) {
94                         $res = User::sendRegisterOpenEmail(
95                                         $user['email'], Config::get('config', 'sitename'), System::baseUrl(), $user['username'], $result['password']);
96
97                         if ($res) {
98                                 info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL);
99                                 goaway(System::baseUrl());
100                         } else {
101                                 notice(
102                                         L10n::t('Failed to send email message. Here your accout details:<br> login: %s<br> password: %s<br><br>You can change your password after login.',
103                                                 $user['email'],
104                                                 $result['password'])
105                                         . EOL
106                                 );
107                         }
108                 } else {
109                         info(L10n::t('Registration successful.') . EOL);
110                         goaway(System::baseUrl());
111                 }
112         } elseif (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE) {
113                 if (!strlen(Config::get('config', 'admin_email'))) {
114                         notice(L10n::t('Your registration can not be processed.') . EOL);
115                         goaway(System::baseUrl());
116                 }
117
118                 $hash = random_string();
119                 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
120                         dbesc($hash),
121                         dbesc(DateTimeFormat::utcNow()),
122                         intval($user['uid']),
123                         dbesc($result['password']),
124                         dbesc(Config::get('system', 'language')),
125                         dbesc($_POST['permonlybox'])
126                 );
127
128                 // invite system
129                 if ($using_invites && $invite_id) {
130                         q("DELETE * FROM `register` WHERE `hash` = '%s' LIMIT 1", dbesc($invite_id));
131                         PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
132                 }
133
134                 // send email to admins
135                 $admin_mail_list = "'" . implode("','", array_map("dbesc", explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))))) . "'";
136                 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
137                         $admin_mail_list
138                 );
139
140                 // send notification to admins
141                 foreach ($adminlist as $admin) {
142                         notification([
143                                 'type'         => NOTIFY_SYSTEM,
144                                 'event'        => 'SYSTEM_REGISTER_REQUEST',
145                                 'source_name'  => $user['username'],
146                                 'source_mail'  => $user['email'],
147                                 'source_nick'  => $user['nickname'],
148                                 'source_link'  => System::baseUrl() . "/admin/users/",
149                                 'link'         => System::baseUrl() . "/admin/users/",
150                                 'source_photo' => System::baseUrl() . "/photo/avatar/" . $user['uid'] . ".jpg",
151                                 'to_email'     => $admin['email'],
152                                 'uid'          => $admin['uid'],
153                                 'language'     => $admin['language'] ? $admin['language'] : 'en',
154                                 'show_in_notification_page' => false
155                         ]);
156                 }
157                 // send notification to the user, that the registration is pending
158                 User::sendRegisterPendingEmail(
159                         $user['email'], Config::get('config', 'sitename'), $user['username']);
160
161                 info(L10n::t('Your registration is pending approval by the site owner.') . EOL);
162                 goaway(System::baseUrl());
163         }
164
165         return;
166 }
167
168 function register_content(App $a)
169 {
170         // logged in users can register others (people/pages/groups)
171         // even with closed registrations, unless specifically prohibited by site policy.
172         // 'block_extended_register' blocks all registrations, period.
173         $block = Config::get('system', 'block_extended_register');
174
175         if (local_user() && ($block)) {
176                 notice("Permission denied." . EOL);
177                 return;
178         }
179
180         if ((!local_user()) && (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED)) {
181                 notice("Permission denied." . EOL);
182                 return;
183         }
184
185         $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
186         if ($max_dailies) {
187                 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
188                 if ($r && $r[0]['total'] >= $max_dailies) {
189                         logger('max daily registrations exceeded.');
190                         notice(L10n::t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
191                         return;
192                 }
193         }
194
195         if (x($_SESSION, 'theme')) {
196                 unset($_SESSION['theme']);
197         }
198         if (x($_SESSION, 'mobile-theme')) {
199                 unset($_SESSION['mobile-theme']);
200         }
201
202
203         $username   = x($_REQUEST, 'username')   ? $_REQUEST['username']   : '';
204         $email      = x($_REQUEST, 'email')      ? $_REQUEST['email']      : '';
205         $openid_url = x($_REQUEST, 'openid_url') ? $_REQUEST['openid_url'] : '';
206         $nickname   = x($_REQUEST, 'nickname')   ? $_REQUEST['nickname']   : '';
207         $photo      = x($_REQUEST, 'photo')      ? $_REQUEST['photo']      : '';
208         $invite_id  = x($_REQUEST, 'invite_id')  ? $_REQUEST['invite_id']  : '';
209
210         $noid = Config::get('system', 'no_openid');
211
212         if ($noid) {
213                 $oidhtml  = '';
214                 $fillwith = '';
215                 $fillext  = '';
216                 $oidlabel = '';
217         } else {
218                 $oidhtml  = '<label for="register-openid" id="label-register-openid" >$oidlabel</label><input type="text" maxlength="60" size="32" name="openid_url" class="openid" id="register-openid" value="$openid" >';
219                 $fillwith = L10n::t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
220                 $fillext  = L10n::t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
221                 $oidlabel = L10n::t("Your OpenID \x28optional\x29: ");
222         }
223
224         // I set this and got even more fake names than before...
225         $realpeople = ''; // L10n::t('Members of this network prefer to communicate with real people who use their real names.');
226
227         if (Config::get('system', 'publish_all')) {
228                 $profile_publish = '<input type="hidden" name="profile_publish_reg" value="1" />';
229         } else {
230                 $publish_tpl = get_markup_template("profile_publish.tpl");
231                 $profile_publish = replace_macros($publish_tpl, [
232                         '$instance' => 'reg',
233                         '$pubdesc' => L10n::t('Include your profile in member directory?'),
234                         '$yes_selected' => '',
235                         '$no_selected' => ' checked="checked"',
236                         '$str_yes' => L10n::t('Yes'),
237                         '$str_no' => L10n::t('No'),
238                 ]);
239         }
240
241         $r = q("SELECT COUNT(*) AS `contacts` FROM `contact`");
242         $passwords = !$r[0]["contacts"];
243
244         $license = '';
245
246         $tpl = get_markup_template("register.tpl");
247
248         $arr = ['template' => $tpl];
249
250         Addon::callHooks('register_form', $arr);
251
252         $tpl = $arr['template'];
253
254         $tos = new Tos();
255
256         $o = replace_macros($tpl, [
257                 '$oidhtml' => $oidhtml,
258                 '$invitations' => Config::get('system', 'invitation_only'),
259                 '$permonly'    => intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE,
260                 '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')],
261                 '$invite_desc' => L10n::t('Membership on this site is by invitation only.'),
262                 '$invite_label' => L10n::t('Your invitation code: '),
263                 '$invite_id'  => $invite_id,
264                 '$realpeople' => $realpeople,
265                 '$regtitle'  => L10n::t('Registration'),
266                 '$registertext' => BBCode::convert(Config::get('config', 'register_text', '')),
267                 '$fillwith'  => $fillwith,
268                 '$fillext'   => $fillext,
269                 '$oidlabel'  => $oidlabel,
270                 '$openid'    => $openid_url,
271                 '$namelabel' => L10n::t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
272                 '$addrlabel' => L10n::t("Your Email Address: \x28Initial information will be send there, so this has to be an existing address.\x29"),
273                 '$passwords' => $passwords,
274                 '$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')],
275                 '$password2' => ['confirm', L10n::t('Confirm:'), '', ''],
276                 '$nickdesc'  => L10n::t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be \'<strong>nickname@%s</strong>\'.', $a->get_hostname()),
277                 '$nicklabel' => L10n::t('Choose a nickname: '),
278                 '$photo'     => $photo,
279                 '$publish'   => $profile_publish,
280                 '$regbutt'   => L10n::t('Register'),
281                 '$username'  => $username,
282                 '$email'     => $email,
283                 '$nickname'  => $nickname,
284                 '$license'   => $license,
285                 '$sitename'  => $a->get_hostname(),
286                 '$importh'   => L10n::t('Import'),
287                 '$importt'   => L10n::t('Import your profile to this friendica instance'),
288                 '$showtoslink' => Config::get('system', 'tosdisplay'),
289                 '$tostext'   => L10n::t('Terms of Service'),
290                 '$showprivstatement' => Config::get('system', 'tosprivstatement'),
291                 '$privstatement' => $tos->privacy_complete,
292                 '$baseurl'   => System::baseurl(),
293                 '$form_security_token' => get_form_security_token("register"),
294                 '$explicit_content' => Config::get('system', 'explicit_content', false),
295                 '$explicit_content_note' => L10n::t('Note: This node explicitly contains adult content')
296         ]);
297         return $o;
298 }