4 use Friendica\Core\Addon;
5 use Friendica\Core\Config;
6 use Friendica\Core\PConfig;
7 use Friendica\Core\System;
8 use Friendica\Core\Worker;
9 use Friendica\Model\User;
11 require_once 'include/enotify.php';
12 require_once 'include/bbcode.php';
14 function register_post(App $a)
16 check_form_security_token_redirectOnErr('/register', 'register');
23 $arr = ['post' => $_POST];
24 Addon::callHooks('register_post', $arr);
26 $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
28 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
29 if ($r && $r[0]['total'] >= $max_dailies) {
34 switch ($a->config['register_policy']) {
40 case REGISTER_APPROVE:
47 if ((!x($_SESSION, 'authenticated') && (!x($_SESSION, 'administrator')))) {
48 notice(t('Permission denied.') . EOL);
59 $arr['blocked'] = $blocked;
60 $arr['verified'] = $verified;
61 $arr['language'] = get_browser_language();
64 $result = User::create($arr);
65 } catch (Exception $e) {
66 notice($e->getMessage());
70 $user = $result['user'];
72 if ($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
73 $url = System::baseUrl() . '/profile/' . $user['nickname'];
74 Worker::add(PRIORITY_LOW, "Directory", $url);
77 $using_invites = Config::get('system', 'invitation_only');
78 $num_invites = Config::get('system', 'number_invites');
79 $invite_id = ((x($_POST, 'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
81 if ($a->config['register_policy'] == REGISTER_OPEN) {
82 if ($using_invites && $invite_id) {
83 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
84 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
87 // Only send a password mail when the password wasn't manually provided
88 if (!x($_POST, 'password1') || !x($_POST, 'confirm')) {
89 $res = User::sendRegisterOpenEmail(
90 $user['email'], $a->config['sitename'], System::baseUrl(), $user['username'], $result['password']);
93 info(t('Registration successful. Please check your email for further instructions.') . EOL);
94 goaway(System::baseUrl());
97 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.',
104 info(t('Registration successful.') . EOL);
105 goaway(System::baseUrl());
107 } elseif ($a->config['register_policy'] == REGISTER_APPROVE) {
108 if (!strlen($a->config['admin_email'])) {
109 notice(t('Your registration can not be processed.') . EOL);
110 goaway(System::baseUrl());
113 $hash = random_string();
114 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
116 dbesc(datetime_convert()),
117 intval($user['uid']),
118 dbesc($result['password']),
120 dbesc($_POST['permonlybox'])
124 if ($using_invites && $invite_id) {
125 q("DELETE * FROM `register` WHERE `hash` = '%s' LIMIT 1", dbesc($invite_id));
126 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
129 // send email to admins
130 $admin_mail_list = "'" . implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email'])))) . "'";
131 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
135 // send notification to admins
136 foreach ($adminlist as $admin) {
138 'type' => NOTIFY_SYSTEM,
139 'event' => 'SYSTEM_REGISTER_REQUEST',
140 'source_name' => $user['username'],
141 'source_mail' => $user['email'],
142 'source_nick' => $user['nickname'],
143 'source_link' => System::baseUrl() . "/admin/users/",
144 'link' => System::baseUrl() . "/admin/users/",
145 'source_photo' => System::baseUrl() . "/photo/avatar/" . $user['uid'] . ".jpg",
146 'to_email' => $admin['email'],
147 'uid' => $admin['uid'],
148 'language' => $admin['language'] ? $admin['language'] : 'en',
149 'show_in_notification_page' => false
152 // send notification to the user, that the registration is pending
153 User::sendRegisterPendingEmail(
154 $user['email'], $a->config['sitename'], $user['username']);
156 info(t('Your registration is pending approval by the site owner.') . EOL);
157 goaway(System::baseUrl());
163 function register_content(App $a)
165 // logged in users can register others (people/pages/groups)
166 // even with closed registrations, unless specifically prohibited by site policy.
167 // 'block_extended_register' blocks all registrations, period.
168 $block = Config::get('system', 'block_extended_register');
170 if (local_user() && ($block)) {
171 notice("Permission denied." . EOL);
175 if ((!local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
176 notice("Permission denied." . EOL);
180 $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
182 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
183 if ($r && $r[0]['total'] >= $max_dailies) {
184 logger('max daily registrations exceeded.');
185 notice(t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
190 if (x($_SESSION, 'theme')) {
191 unset($_SESSION['theme']);
193 if (x($_SESSION, 'mobile-theme')) {
194 unset($_SESSION['mobile-theme']);
198 $username = x($_REQUEST, 'username') ? $_REQUEST['username'] : '';
199 $email = x($_REQUEST, 'email') ? $_REQUEST['email'] : '';
200 $openid_url = x($_REQUEST, 'openid_url') ? $_REQUEST['openid_url'] : '';
201 $nickname = x($_REQUEST, 'nickname') ? $_REQUEST['nickname'] : '';
202 $photo = x($_REQUEST, 'photo') ? $_REQUEST['photo'] : '';
203 $invite_id = x($_REQUEST, 'invite_id') ? $_REQUEST['invite_id'] : '';
205 $noid = Config::get('system', 'no_openid');
213 $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" >';
214 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
215 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
216 $oidlabel = t("Your OpenID \x28optional\x29: ");
219 // I set this and got even more fake names than before...
220 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
222 if (Config::get('system', 'publish_all')) {
223 $profile_publish = '<input type="hidden" name="profile_publish_reg" value="1" />';
225 $publish_tpl = get_markup_template("profile_publish.tpl");
226 $profile_publish = replace_macros($publish_tpl, [
227 '$instance' => 'reg',
228 '$pubdesc' => t('Include your profile in member directory?'),
229 '$yes_selected' => ' checked="checked" ',
230 '$no_selected' => '',
231 '$str_yes' => t('Yes'),
232 '$str_no' => t('No'),
236 $r = q("SELECT COUNT(*) AS `contacts` FROM `contact`");
237 $passwords = !$r[0]["contacts"];
241 $tpl = get_markup_template("register.tpl");
243 $arr = ['template' => $tpl];
245 Addon::callHooks('register_form', $arr);
247 $tpl = $arr['template'];
249 $o = replace_macros($tpl, [
250 '$oidhtml' => $oidhtml,
251 '$invitations' => Config::get('system', 'invitation_only'),
252 '$permonly' => $a->config['register_policy'] == REGISTER_APPROVE,
253 '$permonlybox' => ['permonlybox', t('Note for the admin'), '', t('Leave a message for the admin, why you want to join this node')],
254 '$invite_desc' => t('Membership on this site is by invitation only.'),
255 '$invite_label' => t('Your invitation ID: '),
256 '$invite_id' => $invite_id,
257 '$realpeople' => $realpeople,
258 '$regtitle' => t('Registration'),
259 '$registertext' => x($a->config, 'register_text') ? bbcode($a->config['register_text']) : "",
260 '$fillwith' => $fillwith,
261 '$fillext' => $fillext,
262 '$oidlabel' => $oidlabel,
263 '$openid' => $openid_url,
264 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
265 '$addrlabel' => t('Your Email Address: (Initial information will be send there, so this has to be an existing address.)'),
266 '$passwords' => $passwords,
267 '$password1' => ['password1', t('New Password:'), '', t('Leave empty for an auto generated password.')],
268 '$password2' => ['confirm', t('Confirm:'), '', ''],
269 '$nickdesc' => 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()),
270 '$nicklabel' => t('Choose a nickname: '),
272 '$publish' => $profile_publish,
273 '$regbutt' => t('Register'),
274 '$username' => $username,
276 '$nickname' => $nickname,
277 '$license' => $license,
278 '$sitename' => $a->get_hostname(),
279 '$importh' => t('Import'),
280 '$importt' => t('Import your profile to this friendica instance'),
281 '$form_security_token' => get_form_security_token("register")