3 require_once('include/enotify.php');
4 require_once('include/bbcode.php');
5 require_once('include/user.php');
7 if(! function_exists('register_post')) {
8 function register_post(&$a) {
15 $arr = array('post' => $_POST);
16 call_hooks('register_post', $arr);
18 $max_dailies = intval(get_config('system','max_daily_registrations'));
20 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
21 if($r && $r[0]['total'] >= $max_dailies) {
26 switch($a->config['register_policy']) {
34 case REGISTER_APPROVE:
41 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
42 notice( t('Permission denied.') . EOL );
51 require_once('include/user.php');
55 $arr['blocked'] = $blocked;
56 $arr['verified'] = $verified;
58 $result = create_user($arr);
60 if(! $result['success']) {
61 notice($result['message']);
65 $user = $result['user'];
67 if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
68 $url = $a->get_baseurl() . '/profile/' . $user['nickname'];
69 proc_run('php',"include/directory.php","$url");
72 $using_invites = get_config('system','invitation_only');
73 $num_invites = get_config('system','number_invites');
74 $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
77 if( $a->config['register_policy'] == REGISTER_OPEN ) {
79 if($using_invites && $invite_id) {
80 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
81 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
84 send_register_open_eml(
86 $a->config['sitename'],
93 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
97 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
100 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
101 if(! strlen($a->config['admin_email'])) {
102 notice( t('Your registration can not be processed.') . EOL);
106 $hash = random_string();
107 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
109 dbesc(datetime_convert()),
110 intval($user['uid']),
111 dbesc($result['password']),
116 if($using_invites && $invite_id) {
117 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
118 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
121 // send email to admins
122 $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
123 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s) LIMIT 1",
128 foreach ($adminlist as $admin) {
130 'type' => NOTIFY_SYSTEM,
131 'event' => 'SYSTEM_REGISTER_REQUEST',
132 'source_name' => $user['username'],
133 'source_mail' => $user['email'],
134 'source_nick' => $user['nickname'],
135 'source_link' => $a->get_baseurl()."/admin/users/",
136 'link' => $a->get_baseurl()."/admin/users/",
137 'source_photo' => $a->get_baseurl() . "/photo/avatar/".$user['uid'].".jpg",
138 'to_email' => $admin['mail'],
139 'uid' => $admin['uid'],
140 'language' => ($admin['language']?$admin['language']:'en'))
145 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
159 if(! function_exists('register_content')) {
160 function register_content(&$a) {
162 // logged in users can register others (people/pages/groups)
163 // even with closed registrations, unless specifically prohibited by site policy.
164 // 'block_extended_register' blocks all registrations, period.
166 $block = get_config('system','block_extended_register');
168 if(local_user() && ($block)) {
169 notice("Permission denied." . EOL);
173 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
174 notice("Permission denied." . EOL);
178 $max_dailies = intval(get_config('system','max_daily_registrations'));
180 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
181 if($r && $r[0]['total'] >= $max_dailies) {
182 logger('max daily registrations exceeded.');
183 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
188 if(x($_SESSION,'theme'))
189 unset($_SESSION['theme']);
190 if(x($_SESSION,'mobile-theme'))
191 unset($_SESSION['mobile-theme']);
194 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
195 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
196 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
197 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
198 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
199 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
201 $noid = get_config('system','no_openid');
210 $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" >';
211 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
212 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
213 $oidlabel = t("Your OpenID \x28optional\x29: ");
216 // I set this and got even more fake names than before...
218 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
220 if(get_config('system','publish_all')) {
221 $profile_publish_reg = '<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'),
237 $o = get_markup_template("register.tpl");
239 $arr = array('template' => $o);
241 call_hooks('register_form',$arr);
243 $o = $arr['template'];
245 $o = replace_macros($o, array(
246 '$oidhtml' => $oidhtml,
247 '$invitations' => get_config('system','invitation_only'),
248 '$invite_desc' => t('Membership on this site is by invitation only.'),
249 '$invite_label' => t('Your invitation ID: '),
250 '$invite_id' => $invite_id,
251 '$realpeople' => $realpeople,
252 '$regtitle' => t('Registration'),
253 '$registertext' =>((x($a->config,'register_text'))
254 ? bbcode($a->config['register_text'])
256 '$fillwith' => $fillwith,
257 '$fillext' => $fillext,
258 '$oidlabel' => $oidlabel,
259 '$openid' => $openid_url,
260 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
261 '$addrlabel' => t('Your Email Address: '),
262 '$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>\'.')),
263 '$nicklabel' => t('Choose a nickname: '),
265 '$publish' => $profile_publish,
266 '$regbutt' => t('Register'),
267 '$username' => $username,
269 '$nickname' => $nickname,
270 '$license' => $license,
271 '$sitename' => $a->get_hostname(),
272 '$importh' => t('Import'),
273 '$importt' => t('Import your profile to this friendica instance'),