3 * @file mod/register.php
6 use Friendica\Core\Addon;
7 use Friendica\Core\Config;
8 use Friendica\Core\L10n;
9 use Friendica\Core\PConfig;
10 use Friendica\Core\System;
11 use Friendica\Core\Worker;
12 use Friendica\Model\User;
14 require_once 'include/enotify.php';
15 require_once 'include/bbcode.php';
17 function register_post(App $a)
19 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 ($a->config['register_policy']) {
43 case REGISTER_APPROVE:
50 if ((!x($_SESSION, 'authenticated') && (!x($_SESSION, 'administrator')))) {
51 notice(L10n::t('Permission denied.') . EOL);
62 $arr['blocked'] = $blocked;
63 $arr['verified'] = $verified;
64 $arr['language'] = L10n::getBrowserLanguage();
67 $result = User::create($arr);
68 } catch (Exception $e) {
69 notice($e->getMessage());
73 $user = $result['user'];
75 if ($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
76 $url = System::baseUrl() . '/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 = ((x($_POST, 'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
84 if ($a->config['register_policy'] == REGISTER_OPEN) {
85 if ($using_invites && $invite_id) {
86 q("delete * from register where hash = '%s' limit 1", dbesc($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 (!x($_POST, 'password1') || !x($_POST, 'confirm')) {
92 $res = User::sendRegisterOpenEmail(
93 $user['email'], $a->config['sitename'], System::baseUrl(), $user['username'], $result['password']);
96 info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL);
97 goaway(System::baseUrl());
100 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.',
107 info(L10n::t('Registration successful.') . EOL);
108 goaway(System::baseUrl());
110 } elseif ($a->config['register_policy'] == REGISTER_APPROVE) {
111 if (!strlen($a->config['admin_email'])) {
112 notice(L10n::t('Your registration can not be processed.') . EOL);
113 goaway(System::baseUrl());
116 $hash = random_string();
117 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
119 dbesc(datetime_convert()),
120 intval($user['uid']),
121 dbesc($result['password']),
123 dbesc($_POST['permonlybox'])
127 if ($using_invites && $invite_id) {
128 q("DELETE * FROM `register` WHERE `hash` = '%s' LIMIT 1", dbesc($invite_id));
129 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
132 // send email to admins
133 $admin_mail_list = "'" . implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email'])))) . "'";
134 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
138 // send notification to admins
139 foreach ($adminlist as $admin) {
141 'type' => NOTIFY_SYSTEM,
142 'event' => 'SYSTEM_REGISTER_REQUEST',
143 'source_name' => $user['username'],
144 'source_mail' => $user['email'],
145 'source_nick' => $user['nickname'],
146 'source_link' => System::baseUrl() . "/admin/users/",
147 'link' => System::baseUrl() . "/admin/users/",
148 'source_photo' => System::baseUrl() . "/photo/avatar/" . $user['uid'] . ".jpg",
149 'to_email' => $admin['email'],
150 'uid' => $admin['uid'],
151 'language' => $admin['language'] ? $admin['language'] : 'en',
152 'show_in_notification_page' => false
155 // send notification to the user, that the registration is pending
156 User::sendRegisterPendingEmail(
157 $user['email'], $a->config['sitename'], $user['username']);
159 info(L10n::t('Your registration is pending approval by the site owner.') . EOL);
160 goaway(System::baseUrl());
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()) && ($a->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('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 (x($_SESSION, 'theme')) {
194 unset($_SESSION['theme']);
196 if (x($_SESSION, 'mobile-theme')) {
197 unset($_SESSION['mobile-theme']);
201 $username = x($_REQUEST, 'username') ? $_REQUEST['username'] : '';
202 $email = x($_REQUEST, 'email') ? $_REQUEST['email'] : '';
203 $openid_url = x($_REQUEST, 'openid_url') ? $_REQUEST['openid_url'] : '';
204 $nickname = x($_REQUEST, 'nickname') ? $_REQUEST['nickname'] : '';
205 $photo = x($_REQUEST, 'photo') ? $_REQUEST['photo'] : '';
206 $invite_id = x($_REQUEST, 'invite_id') ? $_REQUEST['invite_id'] : '';
208 $noid = Config::get('system', 'no_openid');
216 $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" >';
217 $fillwith = L10n::t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
218 $fillext = L10n::t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
219 $oidlabel = L10n::t("Your OpenID \x28optional\x29: ");
222 // I set this and got even more fake names than before...
223 $realpeople = ''; // L10n::t('Members of this network prefer to communicate with real people who use their real names.');
225 if (Config::get('system', 'publish_all')) {
226 $profile_publish = '<input type="hidden" name="profile_publish_reg" value="1" />';
228 $publish_tpl = get_markup_template("profile_publish.tpl");
229 $profile_publish = replace_macros($publish_tpl, [
230 '$instance' => 'reg',
231 '$pubdesc' => L10n::t('Include your profile in member directory?'),
232 '$yes_selected' => ' checked="checked" ',
233 '$no_selected' => '',
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"];
244 $tpl = get_markup_template("register.tpl");
246 $arr = ['template' => $tpl];
248 Addon::callHooks('register_form', $arr);
250 $tpl = $arr['template'];
252 $o = replace_macros($tpl, [
253 '$oidhtml' => $oidhtml,
254 '$invitations' => Config::get('system', 'invitation_only'),
255 '$permonly' => $a->config['register_policy'] == REGISTER_APPROVE,
256 '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')],
257 '$invite_desc' => L10n::t('Membership on this site is by invitation only.'),
258 '$invite_label' => L10n::t('Your invitation ID: '),
259 '$invite_id' => $invite_id,
260 '$realpeople' => $realpeople,
261 '$regtitle' => L10n::t('Registration'),
262 '$registertext' => x($a->config, 'register_text') ? bbcode($a->config['register_text']) : "",
263 '$fillwith' => $fillwith,
264 '$fillext' => $fillext,
265 '$oidlabel' => $oidlabel,
266 '$openid' => $openid_url,
267 '$namelabel' => L10n::t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
268 '$addrlabel' => L10n::t('Your Email Address: (Initial information will be send there, so this has to be an existing address.)'),
269 '$passwords' => $passwords,
270 '$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')],
271 '$password2' => ['confirm', L10n::t('Confirm:'), '', ''],
272 '$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->get_hostname()),
273 '$nicklabel' => L10n::t('Choose a nickname: '),
275 '$publish' => $profile_publish,
276 '$regbutt' => L10n::t('Register'),
277 '$username' => $username,
279 '$nickname' => $nickname,
280 '$license' => $license,
281 '$sitename' => $a->get_hostname(),
282 '$importh' => L10n::t('Import'),
283 '$importt' => L10n::t('Import your profile to this friendica instance'),
284 '$form_security_token' => get_form_security_token("register")