4 use Friendica\Core\System;
5 use Friendica\Core\Worker;
7 require_once('include/enotify.php');
8 require_once('include/bbcode.php');
9 require_once('include/user.php');
11 if(! function_exists('register_post')) {
12 function register_post(App $a) {
13 check_form_security_token_redirectOnErr('/register', 'register');
20 $arr = array('post' => $_POST);
21 call_hooks('register_post', $arr);
23 $max_dailies = intval(get_config('system','max_daily_registrations'));
25 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
26 if($r && $r[0]['total'] >= $max_dailies) {
31 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();
62 $result = create_user($arr);
64 if(! $result['success']) {
65 notice($result['message']);
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 = get_config('system','invitation_only');
77 $num_invites = get_config('system','number_invites');
78 $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
81 if( $a->config['register_policy'] == REGISTER_OPEN ) {
83 if($using_invites && $invite_id) {
84 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
85 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
88 // Only send a password mail when the password wasn't manually provided
89 if (!x($_POST,'password1') || !x($_POST,'confirm')) {
90 $res = send_register_open_eml(
92 $a->config['sitename'],
98 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
99 goaway(System::baseUrl());
103 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.'),
110 info( t('Registration successful.') . EOL ) ;
111 goaway(System::baseUrl());
114 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
115 if(! strlen($a->config['admin_email'])) {
116 notice( t('Your registration can not be processed.') . EOL);
117 goaway(System::baseUrl());
120 $hash = random_string();
121 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
123 dbesc(datetime_convert()),
124 intval($user['uid']),
125 dbesc($result['password']),
127 dbesc($_POST['permonlybox'])
131 if($using_invites && $invite_id) {
132 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
133 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
136 // send email to admins
137 $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
138 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
142 // send notification to admins
143 foreach ($adminlist as $admin) {
145 'type' => NOTIFY_SYSTEM,
146 'event' => 'SYSTEM_REGISTER_REQUEST',
147 'source_name' => $user['username'],
148 'source_mail' => $user['email'],
149 'source_nick' => $user['nickname'],
150 'source_link' => System::baseUrl()."/admin/users/",
151 'link' => System::baseUrl()."/admin/users/",
152 'source_photo' => System::baseUrl() . "/photo/avatar/".$user['uid'].".jpg",
153 'to_email' => $admin['email'],
154 'uid' => $admin['uid'],
155 'language' => ($admin['language']?$admin['language']:'en'),
156 'show_in_notification_page' => false
159 // send notification to the user, that the registration is pending
160 send_register_pending_eml(
162 $a->config['sitename'],
165 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
166 goaway(System::baseUrl());
179 if(! function_exists('register_content')) {
180 function register_content(App $a) {
182 // logged in users can register others (people/pages/groups)
183 // even with closed registrations, unless specifically prohibited by site policy.
184 // 'block_extended_register' blocks all registrations, period.
186 $block = get_config('system','block_extended_register');
188 if(local_user() && ($block)) {
189 notice("Permission denied." . EOL);
193 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
194 notice("Permission denied." . EOL);
198 $max_dailies = intval(get_config('system','max_daily_registrations'));
200 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
201 if($r && $r[0]['total'] >= $max_dailies) {
202 logger('max daily registrations exceeded.');
203 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
208 if(x($_SESSION,'theme'))
209 unset($_SESSION['theme']);
210 if(x($_SESSION,'mobile-theme'))
211 unset($_SESSION['mobile-theme']);
214 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
215 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
216 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
217 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
218 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
219 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
221 $noid = get_config('system','no_openid');
230 $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" >';
231 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
232 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
233 $oidlabel = t("Your OpenID \x28optional\x29: ");
236 // I set this and got even more fake names than before...
238 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
240 if(get_config('system','publish_all')) {
241 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
244 $publish_tpl = get_markup_template("profile_publish.tpl");
245 $profile_publish = replace_macros($publish_tpl,array(
246 '$instance' => 'reg',
247 '$pubdesc' => t('Include your profile in member directory?'),
248 '$yes_selected' => ' checked="checked" ',
249 '$no_selected' => '',
250 '$str_yes' => t('Yes'),
251 '$str_no' => t('No'),
255 $r = q("SELECT count(*) AS `contacts` FROM `contact`");
256 $passwords = !$r[0]["contacts"];
260 $o = get_markup_template("register.tpl");
262 $arr = array('template' => $o);
264 call_hooks('register_form',$arr);
266 $o = $arr['template'];
268 $o = replace_macros($o, array(
269 '$oidhtml' => $oidhtml,
270 '$invitations' => get_config('system','invitation_only'),
271 '$permonly' => $a->config['register_policy'] == REGISTER_APPROVE,
272 '$permonlybox' => array('permonlybox', t('Note for the admin'), '', t('Leave a message for the admin, why you want to join this node')),
273 '$invite_desc' => t('Membership on this site is by invitation only.'),
274 '$invite_label' => t('Your invitation ID: '),
275 '$invite_id' => $invite_id,
276 '$realpeople' => $realpeople,
277 '$regtitle' => t('Registration'),
278 '$registertext' =>((x($a->config,'register_text'))
279 ? bbcode($a->config['register_text'])
281 '$fillwith' => $fillwith,
282 '$fillext' => $fillext,
283 '$oidlabel' => $oidlabel,
284 '$openid' => $openid_url,
285 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
286 '$addrlabel' => t('Your Email Address: '),
287 '$passwords' => $passwords,
288 '$password1' => array('password1', t('New Password:'), '', t('Leave empty for an auto generated password.')),
289 '$password2' => array('confirm', t('Confirm:'), '', ''),
290 '$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>\'.')),
291 '$nicklabel' => t('Choose a nickname: '),
293 '$publish' => $profile_publish,
294 '$regbutt' => t('Register'),
295 '$username' => $username,
297 '$nickname' => $nickname,
298 '$license' => $license,
299 '$sitename' => $a->get_hostname(),
300 '$importh' => t('Import'),
301 '$importt' => t('Import your profile to this friendica instance'),
302 '$form_security_token' => get_form_security_token("register")