3 * @file mod/register.php
7 use Friendica\BaseModule;
8 use Friendica\Content\Text\BBCode;
9 use Friendica\Core\Config;
10 use Friendica\Core\Hook;
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 function register_post(App $a)
23 BaseModule::checkFormSecurityTokenRedirectOnError('/register', 'register');
25 $arr = ['post' => $_POST];
26 Hook::callAll('register_post', $arr);
28 $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
30 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
31 if ($r && $r[0]['total'] >= $max_dailies) {
36 switch (Config::get('config', 'register_policy')) {
42 case REGISTER_APPROVE:
49 if (empty($_SESSION['authenticated']) && empty($_SESSION['administrator'])) {
50 notice(L10n::t('Permission denied.') . EOL);
58 $netpublish = !empty($_POST['profile_publish_reg']);
62 $arr['blocked'] = $blocked;
63 $arr['verified'] = $verified;
64 $arr['language'] = L10n::detectLanguage();
67 $result = Model\User::create($arr);
68 } catch (Exception $e) {
69 notice($e->getMessage());
73 $user = $result['user'];
75 if ($netpublish && intval(Config::get('config', 'register_policy')) !== REGISTER_APPROVE) {
76 $url = $a->getBaseUrl() . '/profile/' . $user['nickname'];
77 Worker::add(PRIORITY_LOW, "Directory", $url);
80 $using_invites = Config::get('system', 'invitation_only');
81 $num_invites = Config::get('system', 'number_invites');
82 $invite_id = (!empty($_POST['invite_id']) ? Strings::escapeTags(trim($_POST['invite_id'])) : '');
84 if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN) {
85 if ($using_invites && $invite_id) {
86 Model\Register::deleteByHash($invite_id);
87 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
90 // Only send a password mail when the password wasn't manually provided
91 if (empty($_POST['password1']) || empty($_POST['confirm'])) {
92 $res = Model\User::sendRegisterOpenEmail(
94 Config::get('config', 'sitename'),
100 info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL);
101 $a->internalRedirect();
104 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.',
111 info(L10n::t('Registration successful.') . EOL);
112 $a->internalRedirect();
114 } elseif (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE) {
115 if (!strlen(Config::get('config', 'admin_email'))) {
116 notice(L10n::t('Your registration can not be processed.') . EOL);
117 $a->internalRedirect();
120 Model\Register::createForApproval($user['uid'], Config::get('system', 'language'), $_POST['permonlybox']);
123 if ($using_invites && $invite_id) {
124 Model\Register::deleteByHash($invite_id);
125 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
128 // send email to admins
129 $admin_mail_list = "'" . implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))))) . "'";
130 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
134 // send notification to admins
135 foreach ($adminlist as $admin) {
137 'type' => NOTIFY_SYSTEM,
138 'event' => 'SYSTEM_REGISTER_REQUEST',
139 'source_name' => $user['username'],
140 'source_mail' => $user['email'],
141 'source_nick' => $user['nickname'],
142 'source_link' => $a->getBaseUrl() . "/admin/users/",
143 'link' => $a->getBaseUrl() . "/admin/users/",
144 'source_photo' => $a->getBaseUrl() . "/photo/avatar/" . $user['uid'] . ".jpg",
145 'to_email' => $admin['email'],
146 'uid' => $admin['uid'],
147 'language' => $admin['language'] ? $admin['language'] : 'en',
148 'show_in_notification_page' => false
151 // send notification to the user, that the registration is pending
152 Model\User::sendRegisterPendingEmail(
154 Config::get('config', 'sitename'),
159 info(L10n::t('Your registration is pending approval by the site owner.') . EOL);
160 $a->internalRedirect();
166 function register_content(App $a)
168 // logged in users can register others (people/pages/groups)
169 // even with closed registrations, unless specifically prohibited by site policy.
170 // 'block_extended_register' blocks all registrations, period.
171 $block = Config::get('system', 'block_extended_register');
173 if (local_user() && ($block)) {
174 notice("Permission denied." . EOL);
178 if ((!local_user()) && (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED)) {
179 notice("Permission denied." . EOL);
183 $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
185 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
186 if ($r && $r[0]['total'] >= $max_dailies) {
187 Logger::log('max daily registrations exceeded.');
188 notice(L10n::t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
193 if (!empty($_SESSION['theme'])) {
194 unset($_SESSION['theme']);
196 if (!empty($_SESSION['mobile-theme'])) {
197 unset($_SESSION['mobile-theme']);
201 $username = defaults($_REQUEST, 'username' , '');
202 $email = defaults($_REQUEST, 'email' , '');
203 $openid_url = defaults($_REQUEST, 'openid_url', '');
204 $nickname = defaults($_REQUEST, 'nickname' , '');
205 $photo = defaults($_REQUEST, 'photo' , '');
206 $invite_id = defaults($_REQUEST, 'invite_id' , '');
208 $noid = Config::get('system', 'no_openid');
215 $fillwith = L10n::t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
216 $fillext = L10n::t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
217 $oidlabel = L10n::t("Your OpenID \x28optional\x29: ");
220 if (Config::get('system', 'publish_all')) {
221 $profile_publish = '<input type="hidden" name="profile_publish_reg" value="1" />';
223 $publish_tpl = Renderer::getMarkupTemplate("profile_publish.tpl");
224 $profile_publish = Renderer::replaceMacros($publish_tpl, [
225 '$instance' => 'reg',
226 '$pubdesc' => L10n::t('Include your profile in member directory?'),
227 '$yes_selected' => '',
228 '$no_selected' => ' checked="checked"',
229 '$str_yes' => L10n::t('Yes'),
230 '$str_no' => L10n::t('No'),
234 $r = q("SELECT COUNT(*) AS `contacts` FROM `contact`");
235 $passwords = !$r[0]["contacts"];
237 $tpl = Renderer::getMarkupTemplate("register.tpl");
239 $arr = ['template' => $tpl];
241 Hook::callAll('register_form', $arr);
243 $tpl = $arr['template'];
247 $o = Renderer::replaceMacros($tpl, [
248 '$invitations' => Config::get('system', 'invitation_only'),
249 '$permonly' => intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE,
250 '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')],
251 '$invite_desc' => L10n::t('Membership on this site is by invitation only.'),
252 '$invite_label' => L10n::t('Your invitation code: '),
253 '$invite_id' => $invite_id,
254 '$regtitle' => L10n::t('Registration'),
255 '$registertext' => BBCode::convert(Config::get('config', 'register_text', '')),
256 '$fillwith' => $fillwith,
257 '$fillext' => $fillext,
258 '$oidlabel' => $oidlabel,
259 '$openid' => $openid_url,
260 '$namelabel' => L10n::t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
261 '$addrlabel' => L10n::t("Your Email Address: \x28Initial information will be send there, so this has to be an existing address.\x29"),
262 '$passwords' => $passwords,
263 '$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')],
264 '$password2' => ['confirm', L10n::t('Confirm:'), '', ''],
265 '$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()),
266 '$nicklabel' => L10n::t('Choose a nickname: '),
268 '$publish' => $profile_publish,
269 '$regbutt' => L10n::t('Register'),
270 '$username' => $username,
272 '$nickname' => $nickname,
273 '$sitename' => $a->getHostName(),
274 '$importh' => L10n::t('Import'),
275 '$importt' => L10n::t('Import your profile to this friendica instance'),
276 '$showtoslink' => Config::get('system', 'tosdisplay'),
277 '$tostext' => L10n::t('Terms of Service'),
278 '$showprivstatement' => Config::get('system', 'tosprivstatement'),
279 '$privstatement' => $tos->privacy_complete,
280 '$baseurl' => System::baseurl(),
281 '$form_security_token' => BaseModule::getFormSecurityToken("register"),
282 '$explicit_content' => Config::get('system', 'explicit_content', false),
283 '$explicit_content_note' => L10n::t('Note: This node explicitly contains adult content')