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;
15 use Friendica\Module\Tos;
17 require_once 'include/enotify.php';
19 function register_post(App $a)
21 check_form_security_token_redirectOnErr('/register', 'register');
26 $arr = ['post' => $_POST];
27 Addon::callHooks('register_post', $arr);
29 $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
31 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
32 if ($r && $r[0]['total'] >= $max_dailies) {
37 switch (Config::get('config', 'register_policy')) {
43 case REGISTER_APPROVE:
50 if (empty($_SESSION['authenticated']) && empty($_SESSION['administrator'])) {
51 notice(L10n::t('Permission denied.') . EOL);
59 $netpublish = !empty($_POST['profile_publish_reg']);
63 $arr['blocked'] = $blocked;
64 $arr['verified'] = $verified;
65 $arr['language'] = L10n::getBrowserLanguage();
68 $result = Model\User::create($arr);
69 } catch (Exception $e) {
70 notice($e->getMessage());
74 $user = $result['user'];
76 if ($netpublish && intval(Config::get('config', 'register_policy')) !== REGISTER_APPROVE) {
77 $url = $a->getBaseUrl() . '/profile/' . $user['nickname'];
78 Worker::add(PRIORITY_LOW, "Directory", $url);
81 $using_invites = Config::get('system', 'invitation_only');
82 $num_invites = Config::get('system', 'number_invites');
83 $invite_id = ((x($_POST, 'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
85 if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN) {
86 if ($using_invites && $invite_id) {
87 Model\Register::deleteByHash($invite_id);
88 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
91 // Only send a password mail when the password wasn't manually provided
92 if (!x($_POST, 'password1') || !x($_POST, 'confirm')) {
93 $res = Model\User::sendRegisterOpenEmail(
95 Config::get('config', 'sitename'),
101 info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL);
105 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.',
112 info(L10n::t('Registration successful.') . EOL);
115 } elseif (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE) {
116 if (!strlen(Config::get('config', 'admin_email'))) {
117 notice(L10n::t('Your registration can not be processed.') . EOL);
121 Model\Register::createForApproval($user['uid'], Config::get('system', 'language'), $_POST['permonlybox']);
124 if ($using_invites && $invite_id) {
125 Model\Register::deleteByHash($invite_id);
126 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
129 // send email to admins
130 $admin_mail_list = "'" . implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))))) . "'";
131 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
135 // send notification to admins
136 foreach ($adminlist as $admin) {
138 'type' => NOTIFY_SYSTEM,
139 'event' => 'SYSTEM_REGISTER_REQUEST',
140 'source_name' => $user['username'],
141 'source_mail' => $user['email'],
142 'source_nick' => $user['nickname'],
143 'source_link' => $a->getBaseUrl() . "/admin/users/",
144 'link' => $a->getBaseUrl() . "/admin/users/",
145 'source_photo' => $a->getBaseUrl() . "/photo/avatar/" . $user['uid'] . ".jpg",
146 'to_email' => $admin['email'],
147 'uid' => $admin['uid'],
148 'language' => $admin['language'] ? $admin['language'] : 'en',
149 'show_in_notification_page' => false
152 // send notification to the user, that the registration is pending
153 Model\User::sendRegisterPendingEmail(
155 Config::get('config', 'sitename'),
160 info(L10n::t('Your registration is pending approval by the site owner.') . EOL);
167 function register_content(App $a)
169 // logged in users can register others (people/pages/groups)
170 // even with closed registrations, unless specifically prohibited by site policy.
171 // 'block_extended_register' blocks all registrations, period.
172 $block = Config::get('system', 'block_extended_register');
174 if (local_user() && ($block)) {
175 notice("Permission denied." . EOL);
179 if ((!local_user()) && (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED)) {
180 notice("Permission denied." . EOL);
184 $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
186 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
187 if ($r && $r[0]['total'] >= $max_dailies) {
188 logger('max daily registrations exceeded.');
189 notice(L10n::t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
194 if (x($_SESSION, 'theme')) {
195 unset($_SESSION['theme']);
197 if (x($_SESSION, 'mobile-theme')) {
198 unset($_SESSION['mobile-theme']);
202 $username = x($_REQUEST, 'username') ? $_REQUEST['username'] : '';
203 $email = x($_REQUEST, 'email') ? $_REQUEST['email'] : '';
204 $openid_url = x($_REQUEST, 'openid_url') ? $_REQUEST['openid_url'] : '';
205 $nickname = x($_REQUEST, 'nickname') ? $_REQUEST['nickname'] : '';
206 $photo = x($_REQUEST, 'photo') ? $_REQUEST['photo'] : '';
207 $invite_id = x($_REQUEST, 'invite_id') ? $_REQUEST['invite_id'] : '';
209 $noid = Config::get('system', 'no_openid');
217 $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" >';
218 $fillwith = L10n::t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
219 $fillext = L10n::t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
220 $oidlabel = L10n::t("Your OpenID \x28optional\x29: ");
223 // I set this and got even more fake names than before...
224 $realpeople = ''; // L10n::t('Members of this network prefer to communicate with real people who use their real names.');
226 if (Config::get('system', 'publish_all')) {
227 $profile_publish = '<input type="hidden" name="profile_publish_reg" value="1" />';
229 $publish_tpl = get_markup_template("profile_publish.tpl");
230 $profile_publish = replace_macros($publish_tpl, [
231 '$instance' => 'reg',
232 '$pubdesc' => L10n::t('Include your profile in member directory?'),
233 '$yes_selected' => '',
234 '$no_selected' => ' checked="checked"',
235 '$str_yes' => L10n::t('Yes'),
236 '$str_no' => L10n::t('No'),
240 $r = q("SELECT COUNT(*) AS `contacts` FROM `contact`");
241 $passwords = !$r[0]["contacts"];
245 $tpl = get_markup_template("register.tpl");
247 $arr = ['template' => $tpl];
249 Addon::callHooks('register_form', $arr);
251 $tpl = $arr['template'];
255 $o = replace_macros($tpl, [
256 '$oidhtml' => $oidhtml,
257 '$invitations' => Config::get('system', 'invitation_only'),
258 '$permonly' => intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE,
259 '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')],
260 '$invite_desc' => L10n::t('Membership on this site is by invitation only.'),
261 '$invite_label' => L10n::t('Your invitation code: '),
262 '$invite_id' => $invite_id,
263 '$realpeople' => $realpeople,
264 '$regtitle' => L10n::t('Registration'),
265 '$registertext' => BBCode::convert(Config::get('config', 'register_text', '')),
266 '$fillwith' => $fillwith,
267 '$fillext' => $fillext,
268 '$oidlabel' => $oidlabel,
269 '$openid' => $openid_url,
270 '$namelabel' => L10n::t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
271 '$addrlabel' => L10n::t("Your Email Address: \x28Initial information will be send there, so this has to be an existing address.\x29"),
272 '$passwords' => $passwords,
273 '$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')],
274 '$password2' => ['confirm', L10n::t('Confirm:'), '', ''],
275 '$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->getHostName()),
276 '$nicklabel' => L10n::t('Choose a nickname: '),
278 '$publish' => $profile_publish,
279 '$regbutt' => L10n::t('Register'),
280 '$username' => $username,
282 '$nickname' => $nickname,
283 '$license' => $license,
284 '$sitename' => $a->getHostName(),
285 '$importh' => L10n::t('Import'),
286 '$importt' => L10n::t('Import your profile to this friendica instance'),
287 '$showtoslink' => Config::get('system', 'tosdisplay'),
288 '$tostext' => L10n::t('Terms of Service'),
289 '$showprivstatement' => Config::get('system', 'tosprivstatement'),
290 '$privstatement' => $tos->privacy_complete,
291 '$baseurl' => System::baseurl(),
292 '$form_security_token' => get_form_security_token("register"),
293 '$explicit_content' => Config::get('system', 'explicit_content', false),
294 '$explicit_content_note' => L10n::t('Note: This node explicitly contains adult content')