3 require_once('include/email.php');
4 require_once('include/bbcode.php');
6 if(! function_exists('register_post')) {
7 function register_post(&$a) {
14 $arr = array('post' => $_POST);
15 call_hooks('register_post', $arr);
17 $max_dailies = intval(get_config('system','max_daily_registrations'));
19 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
20 if($r && $r[0]['total'] >= $max_dailies) {
25 switch($a->config['register_policy']) {
33 case REGISTER_APPROVE:
40 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
41 notice( t('Permission denied.') . EOL );
50 require_once('include/user.php');
54 $arr['blocked'] = $blocked;
55 $arr['verified'] = $verified;
57 $result = create_user($arr);
59 if(! $result['success']) {
60 notice($result['message']);
64 $user = $result['user'];
66 if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
67 $url = $a->get_baseurl() . '/profile/' . $user['nickname'];
68 proc_run('php',"include/directory.php","$url");
71 $using_invites = get_config('system','invitation_only');
72 $num_invites = get_config('system','number_invites');
73 $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
76 if( $a->config['register_policy'] == REGISTER_OPEN ) {
78 if($using_invites && $invite_id) {
79 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
80 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
83 $email_tpl = get_intltext_template("register_open_eml.tpl");
84 $email_tpl = replace_macros($email_tpl, array(
85 '$sitename' => $a->config['sitename'],
86 '$siteurl' => $a->get_baseurl(),
87 '$username' => $user['username'],
88 '$email' => $user['email'],
89 '$password' => $result['password'],
90 '$uid' => $user['uid'] ));
92 $res = mail($user['email'], email_header_encode( sprintf( t('Registration details for %s'), $a->config['sitename']),'UTF-8'),
94 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
95 . 'Content-type: text/plain; charset=UTF-8' . "\n"
96 . 'Content-transfer-encoding: 8bit' );
100 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
104 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
107 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
108 if(! strlen($a->config['admin_email'])) {
109 notice( t('Your registration can not be processed.') . EOL);
113 $hash = random_string();
114 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
116 dbesc(datetime_convert()),
117 intval($user['uid']),
118 dbesc($result['password']),
122 $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
124 $r = q("SELECT `language` FROM `user` WHERE `email` = '%s' LIMIT 1",
125 //dbesc($a->config['admin_email'])
129 push_lang($r[0]['language']);
133 if($using_invites && $invite_id) {
134 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
135 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
138 $email_tpl = get_intltext_template("register_verify_eml.tpl");
139 $email_tpl = replace_macros($email_tpl, array(
140 '$sitename' => $a->config['sitename'],
141 '$siteurl' => $a->get_baseurl(),
142 '$username' => $user['username'],
143 '$email' => $user['email'],
144 '$password' => $result['password'],
145 '$uid' => $user['uid'],
149 $res = mail($a->config['admin_email'], email_header_encode( sprintf(t('Registration request at %s'), $a->config['sitename']),'UTF-8'),
151 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
152 . 'Content-type: text/plain; charset=UTF-8' . "\n"
153 . 'Content-transfer-encoding: 8bit' );
158 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
172 if(! function_exists('register_content')) {
173 function register_content(&$a) {
175 // logged in users can register others (people/pages/groups)
176 // even with closed registrations, unless specifically prohibited by site policy.
177 // 'block_extended_register' blocks all registrations, period.
179 $block = get_config('system','block_extended_register');
181 if(local_user() && ($block)) {
182 notice("Permission denied." . EOL);
186 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
187 notice("Permission denied." . EOL);
191 $max_dailies = intval(get_config('system','max_daily_registrations'));
193 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
194 if($r && $r[0]['total'] >= $max_dailies) {
195 logger('max daily registrations exceeded.');
196 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
201 if(x($_SESSION,'theme'))
202 unset($_SESSION['theme']);
203 if(x($_SESSION,'mobile-theme'))
204 unset($_SESSION['mobile-theme']);
207 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
208 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
209 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
210 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
211 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
212 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
214 $noid = get_config('system','no_openid');
223 $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" >';
224 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
225 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
226 $oidlabel = t("Your OpenID \x28optional\x29: ");
229 // I set this and got even more fake names than before...
231 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
233 if(get_config('system','publish_all')) {
234 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
237 $publish_tpl = get_markup_template("profile_publish.tpl");
238 $profile_publish = replace_macros($publish_tpl,array(
239 '$instance' => 'reg',
240 '$pubdesc' => t('Include your profile in member directory?'),
241 '$yes_selected' => ' checked="checked" ',
242 '$no_selected' => '',
243 '$str_yes' => t('Yes'),
244 '$str_no' => t('No'),
250 $o = get_markup_template("register.tpl");
252 $arr = array('template' => $o);
254 call_hooks('register_form',$arr);
256 $o = $arr['template'];
258 $o = replace_macros($o, array(
259 '$oidhtml' => $oidhtml,
260 '$invitations' => get_config('system','invitation_only'),
261 '$invite_desc' => t('Membership on this site is by invitation only.'),
262 '$invite_label' => t('Your invitation ID: '),
263 '$invite_id' => $invite_id,
264 '$realpeople' => $realpeople,
265 '$regtitle' => t('Registration'),
266 '$registertext' =>((x($a->config,'register_text'))
267 ? '<div class="error-message">' . bbcode($a->config['register_text']) . '</div>'
269 '$fillwith' => $fillwith,
270 '$fillext' => $fillext,
271 '$oidlabel' => $oidlabel,
272 '$openid' => $openid_url,
273 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
274 '$addrlabel' => t('Your Email Address: '),
275 '$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>\'.')),
276 '$nicklabel' => t('Choose a nickname: '),
278 '$publish' => $profile_publish,
279 '$regbutt' => t('Register'),
280 '$username' => $username,
282 '$nickname' => $nickname,
283 '$license' => $license,
284 '$sitename' => $a->get_hostname(),
285 '$importh' => t('Import'),
286 '$importt' => t('Import your profile to this friendica instance'),