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 = (!empty($_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 (empty($_POST['password1']) || empty($_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 (!empty($_SESSION['theme'])) {
199 unset($_SESSION['theme']);
201 if (!empty($_SESSION['mobile-theme'])) {
202 unset($_SESSION['mobile-theme']);
206 $username = defaults($_REQUEST, 'username' , '');
207 $email = defaults($_REQUEST, 'email' , '');
208 $openid_url = defaults($_REQUEST, 'openid_url', '');
209 $nickname = defaults($_REQUEST, 'nickname' , '');
210 $photo = defaults($_REQUEST, 'photo' , '');
211 $invite_id = defaults($_REQUEST, 'invite_id' , '');
213 $noid = Config::get('system', 'no_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 if (Config::get('system', 'publish_all')) {
226 $profile_publish = '<input type="hidden" name="profile_publish_reg" value="1" />';
228 $publish_tpl = Renderer::getMarkupTemplate("profile_publish.tpl");
229 $profile_publish = Renderer::replaceMacros($publish_tpl, [
230 '$instance' => 'reg',
231 '$pubdesc' => L10n::t('Include your profile in member directory?'),
232 '$yes_selected' => '',
233 '$no_selected' => ' checked="checked"',
234 '$str_yes' => L10n::t('Yes'),
235 '$str_no' => L10n::t('No'),
239 $r = q("SELECT COUNT(*) AS `contacts` FROM `contact`");
240 $passwords = !$r[0]["contacts"];
242 $tpl = Renderer::getMarkupTemplate("register.tpl");
244 $arr = ['template' => $tpl];
246 Addon::callHooks('register_form', $arr);
248 $tpl = $arr['template'];
252 $o = Renderer::replaceMacros($tpl, [
253 '$invitations' => Config::get('system', 'invitation_only'),
254 '$permonly' => intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE,
255 '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')],
256 '$invite_desc' => L10n::t('Membership on this site is by invitation only.'),
257 '$invite_label' => L10n::t('Your invitation code: '),
258 '$invite_id' => $invite_id,
259 '$regtitle' => L10n::t('Registration'),
260 '$registertext' => BBCode::convert(Config::get('config', 'register_text', '')),
261 '$fillwith' => $fillwith,
262 '$fillext' => $fillext,
263 '$oidlabel' => $oidlabel,
264 '$openid' => $openid_url,
265 '$namelabel' => L10n::t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
266 '$addrlabel' => L10n::t("Your Email Address: \x28Initial information will be send there, so this has to be an existing address.\x29"),
267 '$passwords' => $passwords,
268 '$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')],
269 '$password2' => ['confirm', L10n::t('Confirm:'), '', ''],
270 '$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()),
271 '$nicklabel' => L10n::t('Choose a nickname: '),
273 '$publish' => $profile_publish,
274 '$regbutt' => L10n::t('Register'),
275 '$username' => $username,
277 '$nickname' => $nickname,
278 '$sitename' => $a->getHostName(),
279 '$importh' => L10n::t('Import'),
280 '$importt' => L10n::t('Import your profile to this friendica instance'),
281 '$showtoslink' => Config::get('system', 'tosdisplay'),
282 '$tostext' => L10n::t('Terms of Service'),
283 '$showprivstatement' => Config::get('system', 'tosprivstatement'),
284 '$privstatement' => $tos->privacy_complete,
285 '$baseurl' => System::baseurl(),
286 '$form_security_token' => BaseModule::getFormSecurityToken("register"),
287 '$explicit_content' => Config::get('system', 'explicit_content', false),
288 '$explicit_content_note' => L10n::t('Note: This node explicitly contains adult content')