3 * @file mod/register.php
7 use Friendica\BaseModule;
8 use Friendica\Content\Text\BBCode;
9 use Friendica\Core\Addon;
10 use Friendica\Core\Config;
11 use Friendica\Core\L10n;
12 use Friendica\Core\Logger;
13 use Friendica\Core\PConfig;
14 use Friendica\Core\Renderer;
15 use Friendica\Core\System;
16 use Friendica\Core\Worker;
18 use Friendica\Module\Tos;
19 use Friendica\Util\Strings;
21 require_once 'include/enotify.php';
23 function register_post(App $a)
25 BaseModule::checkFormSecurityTokenRedirectOnError('/register', 'register');
30 $arr = ['post' => $_POST];
31 Addon::callHooks('register_post', $arr);
33 $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
35 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
36 if ($r && $r[0]['total'] >= $max_dailies) {
41 switch (Config::get('config', 'register_policy')) {
47 case REGISTER_APPROVE:
54 if (empty($_SESSION['authenticated']) && empty($_SESSION['administrator'])) {
55 notice(L10n::t('Permission denied.') . EOL);
63 $netpublish = !empty($_POST['profile_publish_reg']);
67 $arr['blocked'] = $blocked;
68 $arr['verified'] = $verified;
69 $arr['language'] = L10n::detectLanguage();
72 $result = Model\User::create($arr);
73 } catch (Exception $e) {
74 notice($e->getMessage());
78 $user = $result['user'];
80 if ($netpublish && intval(Config::get('config', 'register_policy')) !== REGISTER_APPROVE) {
81 $url = $a->getBaseUrl() . '/profile/' . $user['nickname'];
82 Worker::add(PRIORITY_LOW, "Directory", $url);
85 $using_invites = Config::get('system', 'invitation_only');
86 $num_invites = Config::get('system', 'number_invites');
87 $invite_id = ((x($_POST, 'invite_id')) ? Strings::escapeTags(trim($_POST['invite_id'])) : '');
89 if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN) {
90 if ($using_invites && $invite_id) {
91 Model\Register::deleteByHash($invite_id);
92 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
95 // Only send a password mail when the password wasn't manually provided
96 if (!x($_POST, 'password1') || !x($_POST, 'confirm')) {
97 $res = Model\User::sendRegisterOpenEmail(
99 Config::get('config', 'sitename'),
105 info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL);
106 $a->internalRedirect();
109 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.',
116 info(L10n::t('Registration successful.') . EOL);
117 $a->internalRedirect();
119 } elseif (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE) {
120 if (!strlen(Config::get('config', 'admin_email'))) {
121 notice(L10n::t('Your registration can not be processed.') . EOL);
122 $a->internalRedirect();
125 Model\Register::createForApproval($user['uid'], Config::get('system', 'language'), $_POST['permonlybox']);
128 if ($using_invites && $invite_id) {
129 Model\Register::deleteByHash($invite_id);
130 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
133 // send email to admins
134 $admin_mail_list = "'" . implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))))) . "'";
135 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
139 // send notification to admins
140 foreach ($adminlist as $admin) {
142 'type' => NOTIFY_SYSTEM,
143 'event' => 'SYSTEM_REGISTER_REQUEST',
144 'source_name' => $user['username'],
145 'source_mail' => $user['email'],
146 'source_nick' => $user['nickname'],
147 'source_link' => $a->getBaseUrl() . "/admin/users/",
148 'link' => $a->getBaseUrl() . "/admin/users/",
149 'source_photo' => $a->getBaseUrl() . "/photo/avatar/" . $user['uid'] . ".jpg",
150 'to_email' => $admin['email'],
151 'uid' => $admin['uid'],
152 'language' => $admin['language'] ? $admin['language'] : 'en',
153 'show_in_notification_page' => false
156 // send notification to the user, that the registration is pending
157 Model\User::sendRegisterPendingEmail(
159 Config::get('config', 'sitename'),
164 info(L10n::t('Your registration is pending approval by the site owner.') . EOL);
165 $a->internalRedirect();
171 function register_content(App $a)
173 // logged in users can register others (people/pages/groups)
174 // even with closed registrations, unless specifically prohibited by site policy.
175 // 'block_extended_register' blocks all registrations, period.
176 $block = Config::get('system', 'block_extended_register');
178 if (local_user() && ($block)) {
179 notice("Permission denied." . EOL);
183 if ((!local_user()) && (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED)) {
184 notice("Permission denied." . EOL);
188 $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
190 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
191 if ($r && $r[0]['total'] >= $max_dailies) {
192 Logger::log('max daily registrations exceeded.');
193 notice(L10n::t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
198 if (x($_SESSION, 'theme')) {
199 unset($_SESSION['theme']);
201 if (x($_SESSION, 'mobile-theme')) {
202 unset($_SESSION['mobile-theme']);
206 $username = x($_REQUEST, 'username') ? $_REQUEST['username'] : '';
207 $email = x($_REQUEST, 'email') ? $_REQUEST['email'] : '';
208 $openid_url = x($_REQUEST, 'openid_url') ? $_REQUEST['openid_url'] : '';
209 $nickname = x($_REQUEST, 'nickname') ? $_REQUEST['nickname'] : '';
210 $photo = x($_REQUEST, 'photo') ? $_REQUEST['photo'] : '';
211 $invite_id = x($_REQUEST, 'invite_id') ? $_REQUEST['invite_id'] : '';
213 $noid = Config::get('system', 'no_openid');
221 $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" >';
222 $fillwith = L10n::t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
223 $fillext = L10n::t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
224 $oidlabel = L10n::t("Your OpenID \x28optional\x29: ");
227 // I set this and got even more fake names than before...
228 $realpeople = ''; // L10n::t('Members of this network prefer to communicate with real people who use their real names.');
230 if (Config::get('system', 'publish_all')) {
231 $profile_publish = '<input type="hidden" name="profile_publish_reg" value="1" />';
233 $publish_tpl = Renderer::getMarkupTemplate("profile_publish.tpl");
234 $profile_publish = Renderer::replaceMacros($publish_tpl, [
235 '$instance' => 'reg',
236 '$pubdesc' => L10n::t('Include your profile in member directory?'),
237 '$yes_selected' => '',
238 '$no_selected' => ' checked="checked"',
239 '$str_yes' => L10n::t('Yes'),
240 '$str_no' => L10n::t('No'),
244 $r = q("SELECT COUNT(*) AS `contacts` FROM `contact`");
245 $passwords = !$r[0]["contacts"];
249 $tpl = Renderer::getMarkupTemplate("register.tpl");
251 $arr = ['template' => $tpl];
253 Addon::callHooks('register_form', $arr);
255 $tpl = $arr['template'];
259 $o = Renderer::replaceMacros($tpl, [
260 '$oidhtml' => $oidhtml,
261 '$invitations' => Config::get('system', 'invitation_only'),
262 '$permonly' => intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE,
263 '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')],
264 '$invite_desc' => L10n::t('Membership on this site is by invitation only.'),
265 '$invite_label' => L10n::t('Your invitation code: '),
266 '$invite_id' => $invite_id,
267 '$realpeople' => $realpeople,
268 '$regtitle' => L10n::t('Registration'),
269 '$registertext' => BBCode::convert(Config::get('config', 'register_text', '')),
270 '$fillwith' => $fillwith,
271 '$fillext' => $fillext,
272 '$oidlabel' => $oidlabel,
273 '$openid' => $openid_url,
274 '$namelabel' => L10n::t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
275 '$addrlabel' => L10n::t("Your Email Address: \x28Initial information will be send there, so this has to be an existing address.\x29"),
276 '$passwords' => $passwords,
277 '$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')],
278 '$password2' => ['confirm', L10n::t('Confirm:'), '', ''],
279 '$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()),
280 '$nicklabel' => L10n::t('Choose a nickname: '),
282 '$publish' => $profile_publish,
283 '$regbutt' => L10n::t('Register'),
284 '$username' => $username,
286 '$nickname' => $nickname,
287 '$license' => $license,
288 '$sitename' => $a->getHostName(),
289 '$importh' => L10n::t('Import'),
290 '$importt' => L10n::t('Import your profile to this friendica instance'),
291 '$showtoslink' => Config::get('system', 'tosdisplay'),
292 '$tostext' => L10n::t('Terms of Service'),
293 '$showprivstatement' => Config::get('system', 'tosprivstatement'),
294 '$privstatement' => $tos->privacy_complete,
295 '$baseurl' => System::baseurl(),
296 '$form_security_token' => BaseModule::getFormSecurityToken("register"),
297 '$explicit_content' => Config::get('system', 'explicit_content', false),
298 '$explicit_content_note' => L10n::t('Note: This node explicitly contains adult content')