4 use Friendica\Core\Config;
5 use Friendica\Core\PConfig;
6 use Friendica\Core\System;
7 use Friendica\Core\Worker;
8 use Friendica\Model\User;
10 require_once 'include/enotify.php';
11 require_once 'include/bbcode.php';
13 function register_post(App $a)
15 check_form_security_token_redirectOnErr('/register', 'register');
22 $arr = array('post' => $_POST);
23 call_hooks('register_post', $arr);
25 $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
27 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
28 if ($r && $r[0]['total'] >= $max_dailies) {
33 switch ($a->config['register_policy']) {
39 case REGISTER_APPROVE:
46 if ((!x($_SESSION, 'authenticated') && (!x($_SESSION, 'administrator')))) {
47 notice(t('Permission denied.') . EOL);
58 $arr['blocked'] = $blocked;
59 $arr['verified'] = $verified;
60 $arr['language'] = get_browser_language();
63 $result = User::create($arr);
64 } catch (Exception $e) {
65 notice($e->getMessage());
69 $user = $result['user'];
71 if ($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
72 $url = System::baseUrl() . '/profile/' . $user['nickname'];
73 Worker::add(PRIORITY_LOW, "Directory", $url);
76 $using_invites = Config::get('system', 'invitation_only');
77 $num_invites = Config::get('system', 'number_invites');
78 $invite_id = ((x($_POST, 'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
80 if ($a->config['register_policy'] == REGISTER_OPEN) {
81 if ($using_invites && $invite_id) {
82 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
83 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
86 // Only send a password mail when the password wasn't manually provided
87 if (!x($_POST, 'password1') || !x($_POST, 'confirm')) {
88 $res = User::sendRegisterOpenEmail(
89 $user['email'], $a->config['sitename'], System::baseUrl(), $user['username'], $result['password']);
92 info(t('Registration successful. Please check your email for further instructions.') . EOL);
93 goaway(System::baseUrl());
96 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.',
103 info(t('Registration successful.') . EOL);
104 goaway(System::baseUrl());
106 } elseif ($a->config['register_policy'] == REGISTER_APPROVE) {
107 if (!strlen($a->config['admin_email'])) {
108 notice(t('Your registration can not be processed.') . EOL);
109 goaway(System::baseUrl());
112 $hash = random_string();
113 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
115 dbesc(datetime_convert()),
116 intval($user['uid']),
117 dbesc($result['password']),
119 dbesc($_POST['permonlybox'])
123 if ($using_invites && $invite_id) {
124 q("DELETE * FROM `register` WHERE `hash` = '%s' LIMIT 1", dbesc($invite_id));
125 PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
128 // send email to admins
129 $admin_mail_list = "'" . implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->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' => System::baseUrl() . "/admin/users/",
143 'link' => System::baseUrl() . "/admin/users/",
144 'source_photo' => System::baseUrl() . "/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 User::sendRegisterPendingEmail(
153 $user['email'], $a->config['sitename'], $user['username']);
155 info(t('Your registration is pending approval by the site owner.') . EOL);
156 goaway(System::baseUrl());
162 function register_content(App $a)
164 // logged in users can register others (people/pages/groups)
165 // even with closed registrations, unless specifically prohibited by site policy.
166 // 'block_extended_register' blocks all registrations, period.
167 $block = Config::get('system', 'block_extended_register');
169 if (local_user() && ($block)) {
170 notice("Permission denied." . EOL);
174 if ((!local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
175 notice("Permission denied." . EOL);
179 $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
181 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
182 if ($r && $r[0]['total'] >= $max_dailies) {
183 logger('max daily registrations exceeded.');
184 notice(t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
189 if (x($_SESSION, 'theme')) {
190 unset($_SESSION['theme']);
192 if (x($_SESSION, 'mobile-theme')) {
193 unset($_SESSION['mobile-theme']);
197 $username = x($_REQUEST, 'username') ? $_REQUEST['username'] : '';
198 $email = x($_REQUEST, 'email') ? $_REQUEST['email'] : '';
199 $openid_url = x($_REQUEST, 'openid_url') ? $_REQUEST['openid_url'] : '';
200 $nickname = x($_REQUEST, 'nickname') ? $_REQUEST['nickname'] : '';
201 $photo = x($_REQUEST, 'photo') ? $_REQUEST['photo'] : '';
202 $invite_id = x($_REQUEST, 'invite_id') ? $_REQUEST['invite_id'] : '';
204 $noid = Config::get('system', 'no_openid');
212 $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" >';
213 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
214 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
215 $oidlabel = t("Your OpenID \x28optional\x29: ");
218 // I set this and got even more fake names than before...
219 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
221 if (Config::get('system', 'publish_all')) {
222 $profile_publish = '<input type="hidden" name="profile_publish_reg" value="1" />';
224 $publish_tpl = get_markup_template("profile_publish.tpl");
225 $profile_publish = replace_macros($publish_tpl, array(
226 '$instance' => 'reg',
227 '$pubdesc' => t('Include your profile in member directory?'),
228 '$yes_selected' => ' checked="checked" ',
229 '$no_selected' => '',
230 '$str_yes' => t('Yes'),
231 '$str_no' => t('No'),
235 $r = q("SELECT COUNT(*) AS `contacts` FROM `contact`");
236 $passwords = !$r[0]["contacts"];
240 $o = get_markup_template("register.tpl");
242 $arr = array('template' => $o);
244 call_hooks('register_form', $arr);
246 $o = $arr['template'];
248 $o = replace_macros($o, [
249 '$oidhtml' => $oidhtml,
250 '$invitations' => Config::get('system', 'invitation_only'),
251 '$permonly' => $a->config['register_policy'] == REGISTER_APPROVE,
252 '$permonlybox' => array('permonlybox', t('Note for the admin'), '', t('Leave a message for the admin, why you want to join this node')),
253 '$invite_desc' => t('Membership on this site is by invitation only.'),
254 '$invite_label' => t('Your invitation ID: '),
255 '$invite_id' => $invite_id,
256 '$realpeople' => $realpeople,
257 '$regtitle' => t('Registration'),
258 '$registertext' => x($a->config, 'register_text') ? bbcode($a->config['register_text']) : "",
259 '$fillwith' => $fillwith,
260 '$fillext' => $fillext,
261 '$oidlabel' => $oidlabel,
262 '$openid' => $openid_url,
263 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
264 '$addrlabel' => t('Your Email Address: (Initial information will be send there, so this has to be an existing address.)'),
265 '$passwords' => $passwords,
266 '$password1' => array('password1', t('New Password:'), '', t('Leave empty for an auto generated password.')),
267 '$password2' => array('confirm', t('Confirm:'), '', ''),
268 '$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()),
269 '$nicklabel' => t('Choose a nickname: '),
271 '$publish' => $profile_publish,
272 '$regbutt' => t('Register'),
273 '$username' => $username,
275 '$nickname' => $nickname,
276 '$license' => $license,
277 '$sitename' => $a->get_hostname(),
278 '$importh' => t('Import'),
279 '$importt' => t('Import your profile to this friendica instance'),
280 '$form_security_token' => get_form_security_token("register")