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 // Only send a password mail when the password wasn't manually provided
83 if (!x($_POST,'password1') OR !x($_POST,'confirm')) {
84 $res = send_register_open_eml(
86 $a->config['sitename'],
92 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
97 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.'),
104 info( t('Registration successful.') . EOL ) ;
108 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
109 if(! strlen($a->config['admin_email'])) {
110 notice( t('Your registration can not be processed.') . EOL);
114 $hash = random_string();
115 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
117 dbesc(datetime_convert()),
118 intval($user['uid']),
119 dbesc($result['password']),
124 if($using_invites && $invite_id) {
125 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
126 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
129 // send email to admins
130 $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
131 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
136 foreach ($adminlist as $admin) {
138 'type' => NOTIFY_SYSTEM,
139 'event' => 'SYSTEM_REGISTER_REQUEST',
140 'source_name' => $user['username'],
141 'source_mail' => $user['email'],
142 'source_nick' => $user['nickname'],
143 'source_link' => $a->get_baseurl()."/admin/users/",
144 'link' => $a->get_baseurl()."/admin/users/",
145 'source_photo' => $a->get_baseurl() . "/photo/avatar/".$user['uid'].".jpg",
146 'to_email' => $admin['email'],
147 'uid' => $admin['uid'],
148 'language' => ($admin['language']?$admin['language']:'en'))
153 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
167 if(! function_exists('register_content')) {
168 function register_content(&$a) {
170 // logged in users can register others (people/pages/groups)
171 // even with closed registrations, unless specifically prohibited by site policy.
172 // 'block_extended_register' blocks all registrations, period.
174 $block = get_config('system','block_extended_register');
176 if(local_user() && ($block)) {
177 notice("Permission denied." . EOL);
181 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
182 notice("Permission denied." . EOL);
186 $max_dailies = intval(get_config('system','max_daily_registrations'));
188 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
189 if($r && $r[0]['total'] >= $max_dailies) {
190 logger('max daily registrations exceeded.');
191 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
196 if(x($_SESSION,'theme'))
197 unset($_SESSION['theme']);
198 if(x($_SESSION,'mobile-theme'))
199 unset($_SESSION['mobile-theme']);
202 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
203 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
204 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
205 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
206 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
207 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
209 $noid = get_config('system','no_openid');
218 $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" >';
219 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
220 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
221 $oidlabel = t("Your OpenID \x28optional\x29: ");
224 // I set this and got even more fake names than before...
226 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
228 if(get_config('system','publish_all')) {
229 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
232 $publish_tpl = get_markup_template("profile_publish.tpl");
233 $profile_publish = replace_macros($publish_tpl,array(
234 '$instance' => 'reg',
235 '$pubdesc' => t('Include your profile in member directory?'),
236 '$yes_selected' => ' checked="checked" ',
237 '$no_selected' => '',
238 '$str_yes' => t('Yes'),
239 '$str_no' => t('No'),
243 $r = q("SELECT count(*) AS `contacts` FROM `contact`");
244 $passwords = !$r[0]["contacts"];
248 $o = get_markup_template("register.tpl");
250 $arr = array('template' => $o);
252 call_hooks('register_form',$arr);
254 $o = $arr['template'];
256 $o = replace_macros($o, array(
257 '$oidhtml' => $oidhtml,
258 '$invitations' => get_config('system','invitation_only'),
259 '$invite_desc' => t('Membership on this site is by invitation only.'),
260 '$invite_label' => t('Your invitation ID: '),
261 '$invite_id' => $invite_id,
262 '$realpeople' => $realpeople,
263 '$regtitle' => t('Registration'),
264 '$registertext' =>((x($a->config,'register_text'))
265 ? bbcode($a->config['register_text'])
267 '$fillwith' => $fillwith,
268 '$fillext' => $fillext,
269 '$oidlabel' => $oidlabel,
270 '$openid' => $openid_url,
271 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
272 '$addrlabel' => t('Your Email Address: '),
273 '$passwords' => $passwords,
274 '$password1' => array('password1', t('New Password:'), '', t('Leave empty for an auto generated password.')),
275 '$password2' => array('confirm', t('Confirm:'), '', ''),
276 '$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>\'.')),
277 '$nicklabel' => t('Choose a nickname: '),
279 '$publish' => $profile_publish,
280 '$regbutt' => t('Register'),
281 '$username' => $username,
283 '$nickname' => $nickname,
284 '$license' => $license,
285 '$sitename' => $a->get_hostname(),
286 '$importh' => t('Import'),
287 '$importt' => t('Import your profile to this friendica instance'),