4 use Friendica\Core\System;
6 require_once('include/enotify.php');
7 require_once('include/bbcode.php');
8 require_once('include/user.php');
10 if(! function_exists('register_post')) {
11 function register_post(App $a) {
12 check_form_security_token_redirectOnErr('/register', 'register');
19 $arr = array('post' => $_POST);
20 call_hooks('register_post', $arr);
22 $max_dailies = intval(get_config('system','max_daily_registrations'));
24 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
25 if($r && $r[0]['total'] >= $max_dailies) {
30 switch($a->config['register_policy']) {
38 case REGISTER_APPROVE:
45 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
46 notice( t('Permission denied.') . EOL );
57 $arr['blocked'] = $blocked;
58 $arr['verified'] = $verified;
59 $arr['language'] = get_browser_language();
61 $result = create_user($arr);
63 if(! $result['success']) {
64 notice($result['message']);
68 $user = $result['user'];
70 if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
71 $url = System::baseUrl() . '/profile/' . $user['nickname'];
72 proc_run(PRIORITY_LOW, "include/directory.php", $url);
75 $using_invites = get_config('system','invitation_only');
76 $num_invites = get_config('system','number_invites');
77 $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
80 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 set_pconfig($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 = send_register_open_eml(
91 $a->config['sitename'],
97 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
98 goaway(System::baseUrl());
102 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.'),
109 info( t('Registration successful.') . EOL ) ;
110 goaway(System::baseUrl());
113 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
114 if(! strlen($a->config['admin_email'])) {
115 notice( t('Your registration can not be processed.') . EOL);
116 goaway(System::baseUrl());
119 $hash = random_string();
120 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
122 dbesc(datetime_convert()),
123 intval($user['uid']),
124 dbesc($result['password']),
126 dbesc($_POST['permonlybox'])
130 if($using_invites && $invite_id) {
131 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
132 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
135 // send email to admins
136 $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
137 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
141 // send notification to admins
142 foreach ($adminlist as $admin) {
144 'type' => NOTIFY_SYSTEM,
145 'event' => 'SYSTEM_REGISTER_REQUEST',
146 'source_name' => $user['username'],
147 'source_mail' => $user['email'],
148 'source_nick' => $user['nickname'],
149 'source_link' => System::baseUrl()."/admin/users/",
150 'link' => System::baseUrl()."/admin/users/",
151 'source_photo' => System::baseUrl() . "/photo/avatar/".$user['uid'].".jpg",
152 'to_email' => $admin['email'],
153 'uid' => $admin['uid'],
154 'language' => ($admin['language']?$admin['language']:'en'),
155 'show_in_notification_page' => false
158 // send notification to the user, that the registration is pending
159 send_register_pending_eml(
161 $a->config['sitename'],
164 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
165 goaway(System::baseUrl());
178 if(! function_exists('register_content')) {
179 function register_content(App $a) {
181 // logged in users can register others (people/pages/groups)
182 // even with closed registrations, unless specifically prohibited by site policy.
183 // 'block_extended_register' blocks all registrations, period.
185 $block = get_config('system','block_extended_register');
187 if(local_user() && ($block)) {
188 notice("Permission denied." . EOL);
192 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
193 notice("Permission denied." . EOL);
197 $max_dailies = intval(get_config('system','max_daily_registrations'));
199 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
200 if($r && $r[0]['total'] >= $max_dailies) {
201 logger('max daily registrations exceeded.');
202 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
207 if(x($_SESSION,'theme'))
208 unset($_SESSION['theme']);
209 if(x($_SESSION,'mobile-theme'))
210 unset($_SESSION['mobile-theme']);
213 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
214 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
215 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
216 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
217 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
218 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
220 $noid = get_config('system','no_openid');
229 $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" >';
230 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
231 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
232 $oidlabel = t("Your OpenID \x28optional\x29: ");
235 // I set this and got even more fake names than before...
237 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
239 if(get_config('system','publish_all')) {
240 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
243 $publish_tpl = get_markup_template("profile_publish.tpl");
244 $profile_publish = replace_macros($publish_tpl,array(
245 '$instance' => 'reg',
246 '$pubdesc' => t('Include your profile in member directory?'),
247 '$yes_selected' => ' checked="checked" ',
248 '$no_selected' => '',
249 '$str_yes' => t('Yes'),
250 '$str_no' => t('No'),
254 $r = q("SELECT count(*) AS `contacts` FROM `contact`");
255 $passwords = !$r[0]["contacts"];
259 $o = get_markup_template("register.tpl");
261 $arr = array('template' => $o);
263 call_hooks('register_form',$arr);
265 $o = $arr['template'];
267 $o = replace_macros($o, array(
268 '$oidhtml' => $oidhtml,
269 '$invitations' => get_config('system','invitation_only'),
270 '$permonly' => $a->config['register_policy'] == REGISTER_APPROVE,
271 '$permonlybox' => array('permonlybox', t('Note for the admin'), '', t('Leave a message for the admin, why you want to join this node')),
272 '$invite_desc' => t('Membership on this site is by invitation only.'),
273 '$invite_label' => t('Your invitation ID: '),
274 '$invite_id' => $invite_id,
275 '$realpeople' => $realpeople,
276 '$regtitle' => t('Registration'),
277 '$registertext' =>((x($a->config,'register_text'))
278 ? bbcode($a->config['register_text'])
280 '$fillwith' => $fillwith,
281 '$fillext' => $fillext,
282 '$oidlabel' => $oidlabel,
283 '$openid' => $openid_url,
284 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
285 '$addrlabel' => t('Your Email Address: '),
286 '$passwords' => $passwords,
287 '$password1' => array('password1', t('New Password:'), '', t('Leave empty for an auto generated password.')),
288 '$password2' => array('confirm', t('Confirm:'), '', ''),
289 '$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>\'.')),
290 '$nicklabel' => t('Choose a nickname: '),
292 '$publish' => $profile_publish,
293 '$regbutt' => t('Register'),
294 '$username' => $username,
296 '$nickname' => $nickname,
297 '$license' => $license,
298 '$sitename' => $a->get_hostname(),
299 '$importh' => t('Import'),
300 '$importt' => t('Import your profile to this friendica instance'),
301 '$form_security_token' => get_form_security_token("register")