5 require_once('include/enotify.php');
6 require_once('include/bbcode.php');
7 require_once('include/user.php');
9 if(! function_exists('register_post')) {
10 function register_post(App $a) {
17 $arr = array('post' => $_POST);
18 call_hooks('register_post', $arr);
20 $max_dailies = intval(get_config('system','max_daily_registrations'));
22 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
23 if($r && $r[0]['total'] >= $max_dailies) {
28 switch($a->config['register_policy']) {
36 case REGISTER_APPROVE:
43 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
44 notice( t('Permission denied.') . EOL );
55 $arr['blocked'] = $blocked;
56 $arr['verified'] = $verified;
57 $arr['language'] = get_browser_language();
59 $result = create_user($arr);
61 if(! $result['success']) {
62 notice($result['message']);
66 $user = $result['user'];
68 if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
69 $url = App::get_baseurl() . '/profile/' . $user['nickname'];
70 proc_run(PRIORITY_LOW, "include/directory.php", $url);
73 $using_invites = get_config('system','invitation_only');
74 $num_invites = get_config('system','number_invites');
75 $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
78 if( $a->config['register_policy'] == REGISTER_OPEN ) {
80 if($using_invites && $invite_id) {
81 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
82 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
85 // Only send a password mail when the password wasn't manually provided
86 if (!x($_POST,'password1') OR !x($_POST,'confirm')) {
87 $res = send_register_open_eml(
89 $a->config['sitename'],
95 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
100 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.'),
107 info( t('Registration successful.') . EOL ) ;
111 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
112 if(! strlen($a->config['admin_email'])) {
113 notice( t('Your registration can not be processed.') . EOL);
117 $hash = random_string();
118 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
120 dbesc(datetime_convert()),
121 intval($user['uid']),
122 dbesc($result['password']),
124 dbesc($_POST['permonlybox'])
128 if($using_invites && $invite_id) {
129 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
130 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
133 // send email to admins
134 $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
135 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
139 // send notification to admins
140 foreach ($adminlist as $admin) {
142 'type' => NOTIFY_SYSTEM,
143 'event' => 'SYSTEM_REGISTER_REQUEST',
144 'source_name' => $user['username'],
145 'source_mail' => $user['email'],
146 'source_nick' => $user['nickname'],
147 'source_link' => App::get_baseurl()."/admin/users/",
148 'link' => App::get_baseurl()."/admin/users/",
149 'source_photo' => App::get_baseurl() . "/photo/avatar/".$user['uid'].".jpg",
150 'to_email' => $admin['email'],
151 'uid' => $admin['uid'],
152 'language' => ($admin['language']?$admin['language']:'en'),
153 'show_in_notification_page' => false
156 // send notification to the user, that the registration is pending
157 send_register_pending_eml(
159 $a->config['sitename'],
162 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
176 if(! function_exists('register_content')) {
177 function register_content(App $a) {
179 // logged in users can register others (people/pages/groups)
180 // even with closed registrations, unless specifically prohibited by site policy.
181 // 'block_extended_register' blocks all registrations, period.
183 $block = get_config('system','block_extended_register');
185 if(local_user() && ($block)) {
186 notice("Permission denied." . EOL);
190 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
191 notice("Permission denied." . EOL);
195 $max_dailies = intval(get_config('system','max_daily_registrations'));
197 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
198 if($r && $r[0]['total'] >= $max_dailies) {
199 logger('max daily registrations exceeded.');
200 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
205 if(x($_SESSION,'theme'))
206 unset($_SESSION['theme']);
207 if(x($_SESSION,'mobile-theme'))
208 unset($_SESSION['mobile-theme']);
211 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
212 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
213 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
214 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
215 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
216 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
218 $noid = get_config('system','no_openid');
227 $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" >';
228 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
229 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
230 $oidlabel = t("Your OpenID \x28optional\x29: ");
233 // I set this and got even more fake names than before...
235 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
237 if(get_config('system','publish_all')) {
238 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
241 $publish_tpl = get_markup_template("profile_publish.tpl");
242 $profile_publish = replace_macros($publish_tpl,array(
243 '$instance' => 'reg',
244 '$pubdesc' => t('Include your profile in member directory?'),
245 '$yes_selected' => ' checked="checked" ',
246 '$no_selected' => '',
247 '$str_yes' => t('Yes'),
248 '$str_no' => t('No'),
252 $r = q("SELECT count(*) AS `contacts` FROM `contact`");
253 $passwords = !$r[0]["contacts"];
257 $o = get_markup_template("register.tpl");
259 $arr = array('template' => $o);
261 call_hooks('register_form',$arr);
263 $o = $arr['template'];
265 $o = replace_macros($o, array(
266 '$oidhtml' => $oidhtml,
267 '$invitations' => get_config('system','invitation_only'),
268 '$permonly' => $a->config['register_policy'] == REGISTER_APPROVE,
269 '$permonlybox' => array('permonlybox', t('Note for the admin'), '', t('Leave a message for the admin, why you want to join this node')),
270 '$invite_desc' => t('Membership on this site is by invitation only.'),
271 '$invite_label' => t('Your invitation ID: '),
272 '$invite_id' => $invite_id,
273 '$realpeople' => $realpeople,
274 '$regtitle' => t('Registration'),
275 '$registertext' =>((x($a->config,'register_text'))
276 ? bbcode($a->config['register_text'])
278 '$fillwith' => $fillwith,
279 '$fillext' => $fillext,
280 '$oidlabel' => $oidlabel,
281 '$openid' => $openid_url,
282 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
283 '$addrlabel' => t('Your Email Address: '),
284 '$passwords' => $passwords,
285 '$password1' => array('password1', t('New Password:'), '', t('Leave empty for an auto generated password.')),
286 '$password2' => array('confirm', t('Confirm:'), '', ''),
287 '$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>\'.')),
288 '$nicklabel' => t('Choose a nickname: '),
290 '$publish' => $profile_publish,
291 '$regbutt' => t('Register'),
292 '$username' => $username,
294 '$nickname' => $nickname,
295 '$license' => $license,
296 '$sitename' => $a->get_hostname(),
297 '$importh' => t('Import'),
298 '$importt' => t('Import your profile to this friendica instance'),