3 * @file mod/register.php
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\Database\DBA;
15 use Friendica\Model\User;
16 use Friendica\Module\Tos;
17 use Friendica\Util\DateTimeFormat;
19 require_once 'include/enotify.php';
21 function register_post(App $a)
23 check_form_security_token_redirectOnErr('/register', 'register');
28 $arr = ['post' => $_POST];
29 Addon::callHooks('register_post', $arr);
31 $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
33 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
34 if ($r && $r[0]['total'] >= $max_dailies) {
39 switch (Config::get('config', 'register_policy')) {
45 case REGISTER_APPROVE:
52 if (empty($_SESSION['authenticated']) && empty($_SESSION['administrator'])) {
53 notice(L10n::t('Permission denied.') . EOL);
61 $netpublish = !empty($_POST['profile_publish_reg']);
65 $arr['blocked'] = $blocked;
66 $arr['verified'] = $verified;
67 $arr['language'] = L10n::getBrowserLanguage();
70 $result = User::create($arr);
71 } catch (Exception $e) {
72 notice($e->getMessage());
76 $user = $result['user'];
78 if ($netpublish && intval(Config::get('config', 'register_policy')) !== REGISTER_APPROVE) {
79 $url = System::baseUrl() . '/profile/' . $user['nickname'];
80 Worker::add(PRIORITY_LOW, "Directory", $url);
83 $using_invites = Config::get('system', 'invitation_only');
84 $num_invites = Config::get('system', 'number_invites');
85 $invite_id = ((x($_POST, 'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
87 if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN) {
88 if ($using_invites && $invite_id) {
89 q("delete * from register where hash = '%s' limit 1", DBA::escape($invite_id));
90 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
93 // Only send a password mail when the password wasn't manually provided
94 if (!x($_POST, 'password1') || !x($_POST, 'confirm')) {
95 $res = User::sendRegisterOpenEmail(
96 $user['email'], Config::get('config', 'sitename'), System::baseUrl(), $user['username'], $result['password'], $user);
99 info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL);
100 goaway(System::baseUrl());
103 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.',
110 info(L10n::t('Registration successful.') . EOL);
111 goaway(System::baseUrl());
113 } elseif (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE) {
114 if (!strlen(Config::get('config', 'admin_email'))) {
115 notice(L10n::t('Your registration can not be processed.') . EOL);
116 goaway(System::baseUrl());
119 $hash = random_string();
120 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
122 DBA::escape(DateTimeFormat::utcNow()),
123 intval($user['uid']),
124 DBA::escape($result['password']),
125 DBA::escape(Config::get('system', 'language')),
126 DBA::escape($_POST['permonlybox'])
130 if ($using_invites && $invite_id) {
131 q("DELETE * FROM `register` WHERE `hash` = '%s' LIMIT 1", DBA::escape($invite_id));
132 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
135 // send email to admins
136 $admin_mail_list = "'" . implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))))) . "'";
137 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
141 // send notification to admins
142 foreach ($adminlist as $admin) {
144 'type' => NOTIFY_SYSTEM,
145 'event' => 'SYSTEM_REGISTER_REQUEST',
146 'source_name' => $user['username'],
147 'source_mail' => $user['email'],
148 'source_nick' => $user['nickname'],
149 'source_link' => System::baseUrl() . "/admin/users/",
150 'link' => System::baseUrl() . "/admin/users/",
151 'source_photo' => System::baseUrl() . "/photo/avatar/" . $user['uid'] . ".jpg",
152 'to_email' => $admin['email'],
153 'uid' => $admin['uid'],
154 'language' => $admin['language'] ? $admin['language'] : 'en',
155 'show_in_notification_page' => false
158 // send notification to the user, that the registration is pending
159 User::sendRegisterPendingEmail(
160 $user['email'], Config::get('config', 'sitename'), $user['username']);
162 info(L10n::t('Your registration is pending approval by the site owner.') . EOL);
163 goaway(System::baseUrl());
169 function register_content(App $a)
171 // logged in users can register others (people/pages/groups)
172 // even with closed registrations, unless specifically prohibited by site policy.
173 // 'block_extended_register' blocks all registrations, period.
174 $block = Config::get('system', 'block_extended_register');
176 if (local_user() && ($block)) {
177 notice("Permission denied." . EOL);
181 if ((!local_user()) && (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED)) {
182 notice("Permission denied." . EOL);
186 $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
188 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
189 if ($r && $r[0]['total'] >= $max_dailies) {
190 logger('max daily registrations exceeded.');
191 notice(L10n::t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
196 if (x($_SESSION, 'theme')) {
197 unset($_SESSION['theme']);
199 if (x($_SESSION, 'mobile-theme')) {
200 unset($_SESSION['mobile-theme']);
204 $username = x($_REQUEST, 'username') ? $_REQUEST['username'] : '';
205 $email = x($_REQUEST, 'email') ? $_REQUEST['email'] : '';
206 $openid_url = x($_REQUEST, 'openid_url') ? $_REQUEST['openid_url'] : '';
207 $nickname = x($_REQUEST, 'nickname') ? $_REQUEST['nickname'] : '';
208 $photo = x($_REQUEST, 'photo') ? $_REQUEST['photo'] : '';
209 $invite_id = x($_REQUEST, 'invite_id') ? $_REQUEST['invite_id'] : '';
211 $noid = Config::get('system', 'no_openid');
219 $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" >';
220 $fillwith = L10n::t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
221 $fillext = L10n::t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
222 $oidlabel = L10n::t("Your OpenID \x28optional\x29: ");
225 // I set this and got even more fake names than before...
226 $realpeople = ''; // L10n::t('Members of this network prefer to communicate with real people who use their real names.');
228 if (Config::get('system', 'publish_all')) {
229 $profile_publish = '<input type="hidden" name="profile_publish_reg" value="1" />';
231 $publish_tpl = get_markup_template("profile_publish.tpl");
232 $profile_publish = replace_macros($publish_tpl, [
233 '$instance' => 'reg',
234 '$pubdesc' => L10n::t('Include your profile in member directory?'),
235 '$yes_selected' => '',
236 '$no_selected' => ' checked="checked"',
237 '$str_yes' => L10n::t('Yes'),
238 '$str_no' => L10n::t('No'),
242 $r = q("SELECT COUNT(*) AS `contacts` FROM `contact`");
243 $passwords = !$r[0]["contacts"];
247 $tpl = get_markup_template("register.tpl");
249 $arr = ['template' => $tpl];
251 Addon::callHooks('register_form', $arr);
253 $tpl = $arr['template'];
257 $o = replace_macros($tpl, [
258 '$oidhtml' => $oidhtml,
259 '$invitations' => Config::get('system', 'invitation_only'),
260 '$permonly' => intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE,
261 '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')],
262 '$invite_desc' => L10n::t('Membership on this site is by invitation only.'),
263 '$invite_label' => L10n::t('Your invitation code: '),
264 '$invite_id' => $invite_id,
265 '$realpeople' => $realpeople,
266 '$regtitle' => L10n::t('Registration'),
267 '$registertext' => BBCode::convert(Config::get('config', 'register_text', '')),
268 '$fillwith' => $fillwith,
269 '$fillext' => $fillext,
270 '$oidlabel' => $oidlabel,
271 '$openid' => $openid_url,
272 '$namelabel' => L10n::t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
273 '$addrlabel' => L10n::t("Your Email Address: \x28Initial information will be send there, so this has to be an existing address.\x29"),
274 '$passwords' => $passwords,
275 '$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')],
276 '$password2' => ['confirm', L10n::t('Confirm:'), '', ''],
277 '$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()),
278 '$nicklabel' => L10n::t('Choose a nickname: '),
280 '$publish' => $profile_publish,
281 '$regbutt' => L10n::t('Register'),
282 '$username' => $username,
284 '$nickname' => $nickname,
285 '$license' => $license,
286 '$sitename' => $a->get_hostname(),
287 '$importh' => L10n::t('Import'),
288 '$importt' => L10n::t('Import your profile to this friendica instance'),
289 '$showtoslink' => Config::get('system', 'tosdisplay'),
290 '$tostext' => L10n::t('Terms of Service'),
291 '$showprivstatement' => Config::get('system', 'tosprivstatement'),
292 '$privstatement' => $tos->privacy_complete,
293 '$baseurl' => System::baseurl(),
294 '$form_security_token' => get_form_security_token("register"),
295 '$explicit_content' => Config::get('system', 'explicit_content', false),
296 '$explicit_content_note' => L10n::t('Note: This node explicitly contains adult content')