4 use Friendica\Core\Config;
5 use Friendica\Core\PConfig;
6 use Friendica\Core\System;
7 use Friendica\Core\Worker;
9 require_once('include/enotify.php');
10 require_once('include/bbcode.php');
11 require_once('include/user.php');
13 if(! function_exists('register_post')) {
14 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']) {
41 case REGISTER_APPROVE:
48 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
49 notice( t('Permission denied.') . EOL );
60 $arr['blocked'] = $blocked;
61 $arr['verified'] = $verified;
62 $arr['language'] = get_browser_language();
64 $result = create_user($arr);
66 if(! $result['success']) {
67 notice($result['message']);
71 $user = $result['user'];
73 if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
74 $url = System::baseUrl() . '/profile/' . $user['nickname'];
75 Worker::add(PRIORITY_LOW, "directory", $url);
78 $using_invites = Config::get('system','invitation_only');
79 $num_invites = Config::get('system','number_invites');
80 $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
83 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 = send_register_open_eml(
94 $a->config['sitename'],
100 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
101 goaway(System::baseUrl());
105 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( t('Registration successful.') . EOL ) ;
113 goaway(System::baseUrl());
116 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
117 if(! strlen($a->config['admin_email'])) {
118 notice( t('Your registration can not be processed.') . EOL);
119 goaway(System::baseUrl());
122 $hash = random_string();
123 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
125 dbesc(datetime_convert()),
126 intval($user['uid']),
127 dbesc($result['password']),
129 dbesc($_POST['permonlybox'])
133 if($using_invites && $invite_id) {
134 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
135 PConfig::set($user['uid'],'system','invites_remaining',$num_invites);
138 // send email to admins
139 $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
140 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
144 // send notification to admins
145 foreach ($adminlist as $admin) {
147 'type' => NOTIFY_SYSTEM,
148 'event' => 'SYSTEM_REGISTER_REQUEST',
149 'source_name' => $user['username'],
150 'source_mail' => $user['email'],
151 'source_nick' => $user['nickname'],
152 'source_link' => System::baseUrl()."/admin/users/",
153 'link' => System::baseUrl()."/admin/users/",
154 'source_photo' => System::baseUrl() . "/photo/avatar/".$user['uid'].".jpg",
155 'to_email' => $admin['email'],
156 'uid' => $admin['uid'],
157 'language' => ($admin['language']?$admin['language']:'en'),
158 'show_in_notification_page' => false
161 // send notification to the user, that the registration is pending
162 send_register_pending_eml(
164 $a->config['sitename'],
167 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
168 goaway(System::baseUrl());
181 if(! function_exists('register_content')) {
182 function register_content(App $a) {
184 // logged in users can register others (people/pages/groups)
185 // even with closed registrations, unless specifically prohibited by site policy.
186 // 'block_extended_register' blocks all registrations, period.
188 $block = Config::get('system','block_extended_register');
190 if(local_user() && ($block)) {
191 notice("Permission denied." . EOL);
195 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
196 notice("Permission denied." . EOL);
200 $max_dailies = intval(Config::get('system','max_daily_registrations'));
202 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
203 if($r && $r[0]['total'] >= $max_dailies) {
204 logger('max daily registrations exceeded.');
205 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
210 if(x($_SESSION,'theme'))
211 unset($_SESSION['theme']);
212 if(x($_SESSION,'mobile-theme'))
213 unset($_SESSION['mobile-theme']);
216 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
217 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
218 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
219 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
220 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
221 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
223 $noid = Config::get('system','no_openid');
232 $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" >';
233 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
234 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
235 $oidlabel = t("Your OpenID \x28optional\x29: ");
238 // I set this and got even more fake names than before...
240 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
242 if(Config::get('system','publish_all')) {
243 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
246 $publish_tpl = get_markup_template("profile_publish.tpl");
247 $profile_publish = replace_macros($publish_tpl,array(
248 '$instance' => 'reg',
249 '$pubdesc' => t('Include your profile in member directory?'),
250 '$yes_selected' => ' checked="checked" ',
251 '$no_selected' => '',
252 '$str_yes' => t('Yes'),
253 '$str_no' => t('No'),
257 $r = q("SELECT count(*) AS `contacts` FROM `contact`");
258 $passwords = !$r[0]["contacts"];
262 $o = get_markup_template("register.tpl");
264 $arr = array('template' => $o);
266 call_hooks('register_form',$arr);
268 $o = $arr['template'];
270 $o = replace_macros($o, array(
271 '$oidhtml' => $oidhtml,
272 '$invitations' => Config::get('system','invitation_only'),
273 '$permonly' => $a->config['register_policy'] == REGISTER_APPROVE,
274 '$permonlybox' => array('permonlybox', t('Note for the admin'), '', t('Leave a message for the admin, why you want to join this node')),
275 '$invite_desc' => t('Membership on this site is by invitation only.'),
276 '$invite_label' => t('Your invitation ID: '),
277 '$invite_id' => $invite_id,
278 '$realpeople' => $realpeople,
279 '$regtitle' => t('Registration'),
280 '$registertext' =>((x($a->config,'register_text'))
281 ? bbcode($a->config['register_text'])
283 '$fillwith' => $fillwith,
284 '$fillext' => $fillext,
285 '$oidlabel' => $oidlabel,
286 '$openid' => $openid_url,
287 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
288 '$addrlabel' => t('Your Email Address: '),
289 '$passwords' => $passwords,
290 '$password1' => array('password1', t('New Password:'), '', t('Leave empty for an auto generated password.')),
291 '$password2' => array('confirm', t('Confirm:'), '', ''),
292 '$nickdesc' => str_replace('$sitename',$a->get_hostname(), t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be \'<strong>nickname@$sitename</strong>\'.')),
293 '$nicklabel' => t('Choose a nickname: '),
295 '$publish' => $profile_publish,
296 '$regbutt' => t('Register'),
297 '$username' => $username,
299 '$nickname' => $nickname,
300 '$license' => $license,
301 '$sitename' => $a->get_hostname(),
302 '$importh' => t('Import'),
303 '$importt' => t('Import your profile to this friendica instance'),
304 '$form_security_token' => get_form_security_token("register")