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\PConfig;
13 use Friendica\Core\System;
14 use Friendica\Core\Worker;
15 use Friendica\Database\DBA;
16 use Friendica\Model\User;
17 use Friendica\Module\Tos;
18 use Friendica\Util\DateTimeFormat;
19 use Friendica\Util\Security;
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::getBrowserLanguage();
72 $result = 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 = System::baseUrl() . '/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')) ? notags(trim($_POST['invite_id'])) : '');
89 if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN) {
90 if ($using_invites && $invite_id) {
91 q("delete * from register where hash = '%s' limit 1", DBA::escape($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 = User::sendRegisterOpenEmail(
98 $user['email'], Config::get('config', 'sitename'), System::baseUrl(), $user['username'], $result['password'], $user);
101 info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL);
102 goaway(System::baseUrl());
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);
113 goaway(System::baseUrl());
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);
118 goaway(System::baseUrl());
121 $hash = random_string();
122 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
124 DBA::escape(DateTimeFormat::utcNow()),
125 intval($user['uid']),
126 DBA::escape($result['password']),
127 DBA::escape(Config::get('system', 'language')),
128 DBA::escape($_POST['permonlybox'])
132 if ($using_invites && $invite_id) {
133 q("DELETE * FROM `register` WHERE `hash` = '%s' LIMIT 1", DBA::escape($invite_id));
134 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
137 // send email to admins
138 $admin_mail_list = "'" . implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))))) . "'";
139 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
143 // send notification to admins
144 foreach ($adminlist as $admin) {
146 'type' => NOTIFY_SYSTEM,
147 'event' => 'SYSTEM_REGISTER_REQUEST',
148 'source_name' => $user['username'],
149 'source_mail' => $user['email'],
150 'source_nick' => $user['nickname'],
151 'source_link' => System::baseUrl() . "/admin/users/",
152 'link' => System::baseUrl() . "/admin/users/",
153 'source_photo' => System::baseUrl() . "/photo/avatar/" . $user['uid'] . ".jpg",
154 'to_email' => $admin['email'],
155 'uid' => $admin['uid'],
156 'language' => $admin['language'] ? $admin['language'] : 'en',
157 'show_in_notification_page' => false
160 // send notification to the user, that the registration is pending
161 User::sendRegisterPendingEmail(
162 $user['email'], Config::get('config', 'sitename'), $user['username']);
164 info(L10n::t('Your registration is pending approval by the site owner.') . EOL);
165 goaway(System::baseUrl());
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('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 = get_markup_template("profile_publish.tpl");
234 $profile_publish = replace_macros($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 = get_markup_template("register.tpl");
251 $arr = ['template' => $tpl];
253 Addon::callHooks('register_form', $arr);
255 $tpl = $arr['template'];
259 $o = replace_macros($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')