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 );
53 $arr['blocked'] = $blocked;
54 $arr['verified'] = $verified;
56 $result = create_user($arr);
58 if(! $result['success']) {
59 notice($result['message']);
63 $user = $result['user'];
65 if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
66 $url = $a->get_baseurl() . '/profile/' . $user['nickname'];
67 proc_run('php',"include/directory.php","$url");
70 $using_invites = get_config('system','invitation_only');
71 $num_invites = get_config('system','number_invites');
72 $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
75 if( $a->config['register_policy'] == REGISTER_OPEN ) {
77 if($using_invites && $invite_id) {
78 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
79 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
82 $res = send_register_open_eml(
84 $a->config['sitename'],
90 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
96 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.'),
103 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
104 if(! strlen($a->config['admin_email'])) {
105 notice( t('Your registration can not be processed.') . EOL);
109 $hash = random_string();
110 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
112 dbesc(datetime_convert()),
113 intval($user['uid']),
114 dbesc($result['password']),
119 if($using_invites && $invite_id) {
120 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
121 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
124 // send email to admins
125 $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
126 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
131 foreach ($adminlist as $admin) {
133 'type' => NOTIFY_SYSTEM,
134 'event' => 'SYSTEM_REGISTER_REQUEST',
135 'source_name' => $user['username'],
136 'source_mail' => $user['email'],
137 'source_nick' => $user['nickname'],
138 'source_link' => $a->get_baseurl()."/admin/users/",
139 'link' => $a->get_baseurl()."/admin/users/",
140 'source_photo' => $a->get_baseurl() . "/photo/avatar/".$user['uid'].".jpg",
141 'to_email' => $admin['email'],
142 'uid' => $admin['uid'],
143 'language' => ($admin['language']?$admin['language']:'en'))
148 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
162 if(! function_exists('register_content')) {
163 function register_content(&$a) {
165 // logged in users can register others (people/pages/groups)
166 // even with closed registrations, unless specifically prohibited by site policy.
167 // 'block_extended_register' blocks all registrations, period.
169 $block = get_config('system','block_extended_register');
171 if(local_user() && ($block)) {
172 notice("Permission denied." . EOL);
176 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
177 notice("Permission denied." . EOL);
181 $max_dailies = intval(get_config('system','max_daily_registrations'));
183 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
184 if($r && $r[0]['total'] >= $max_dailies) {
185 logger('max daily registrations exceeded.');
186 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
191 if(x($_SESSION,'theme'))
192 unset($_SESSION['theme']);
193 if(x($_SESSION,'mobile-theme'))
194 unset($_SESSION['mobile-theme']);
197 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
198 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
199 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
200 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
201 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
202 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
204 $noid = get_config('system','no_openid');
213 $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" >';
214 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
215 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
216 $oidlabel = t("Your OpenID \x28optional\x29: ");
219 // I set this and got even more fake names than before...
221 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
223 if(get_config('system','publish_all')) {
224 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
227 $publish_tpl = get_markup_template("profile_publish.tpl");
228 $profile_publish = replace_macros($publish_tpl,array(
229 '$instance' => 'reg',
230 '$pubdesc' => t('Include your profile in member directory?'),
231 '$yes_selected' => ' checked="checked" ',
232 '$no_selected' => '',
233 '$str_yes' => t('Yes'),
234 '$str_no' => t('No'),
240 $o = get_markup_template("register.tpl");
242 $arr = array('template' => $o);
244 call_hooks('register_form',$arr);
246 $o = $arr['template'];
248 $o = replace_macros($o, array(
249 '$oidhtml' => $oidhtml,
250 '$invitations' => get_config('system','invitation_only'),
251 '$invite_desc' => t('Membership on this site is by invitation only.'),
252 '$invite_label' => t('Your invitation ID: '),
253 '$invite_id' => $invite_id,
254 '$realpeople' => $realpeople,
255 '$regtitle' => t('Registration'),
256 '$registertext' =>((x($a->config,'register_text'))
257 ? bbcode($a->config['register_text'])
259 '$fillwith' => $fillwith,
260 '$fillext' => $fillext,
261 '$oidlabel' => $oidlabel,
262 '$openid' => $openid_url,
263 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
264 '$addrlabel' => t('Your Email Address: '),
265 '$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>\'.')),
266 '$nicklabel' => t('Choose a nickname: '),
268 '$publish' => $profile_publish,
269 '$regbutt' => t('Register'),
270 '$username' => $username,
272 '$nickname' => $nickname,
273 '$license' => $license,
274 '$sitename' => $a->get_hostname(),
275 '$importh' => t('Import'),
276 '$importt' => t('Import your profile to this friendica instance'),