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) {
11 check_form_security_token_redirectOnErr('/register', 'register');
18 $arr = array('post' => $_POST);
19 call_hooks('register_post', $arr);
21 $max_dailies = intval(get_config('system','max_daily_registrations'));
23 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
24 if($r && $r[0]['total'] >= $max_dailies) {
29 switch($a->config['register_policy']) {
37 case REGISTER_APPROVE:
44 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
45 notice( t('Permission denied.') . EOL );
56 $arr['blocked'] = $blocked;
57 $arr['verified'] = $verified;
58 $arr['language'] = get_browser_language();
60 $result = create_user($arr);
62 if(! $result['success']) {
63 notice($result['message']);
67 $user = $result['user'];
69 if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
70 $url = App::get_baseurl() . '/profile/' . $user['nickname'];
71 proc_run(PRIORITY_LOW, "include/directory.php", $url);
74 $using_invites = get_config('system','invitation_only');
75 $num_invites = get_config('system','number_invites');
76 $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
79 if( $a->config['register_policy'] == REGISTER_OPEN ) {
81 if($using_invites && $invite_id) {
82 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
83 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
86 // Only send a password mail when the password wasn't manually provided
87 if (!x($_POST,'password1') || !x($_POST,'confirm')) {
88 $res = send_register_open_eml(
90 $a->config['sitename'],
96 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
101 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.'),
108 info( t('Registration successful.') . EOL ) ;
112 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
113 if(! strlen($a->config['admin_email'])) {
114 notice( t('Your registration can not be processed.') . EOL);
118 $hash = random_string();
119 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
121 dbesc(datetime_convert()),
122 intval($user['uid']),
123 dbesc($result['password']),
125 dbesc($_POST['permonlybox'])
129 if($using_invites && $invite_id) {
130 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
131 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
134 // send email to admins
135 $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
136 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
140 // send notification to admins
141 foreach ($adminlist as $admin) {
143 'type' => NOTIFY_SYSTEM,
144 'event' => 'SYSTEM_REGISTER_REQUEST',
145 'source_name' => $user['username'],
146 'source_mail' => $user['email'],
147 'source_nick' => $user['nickname'],
148 'source_link' => App::get_baseurl()."/admin/users/",
149 'link' => App::get_baseurl()."/admin/users/",
150 'source_photo' => App::get_baseurl() . "/photo/avatar/".$user['uid'].".jpg",
151 'to_email' => $admin['email'],
152 'uid' => $admin['uid'],
153 'language' => ($admin['language']?$admin['language']:'en'),
154 'show_in_notification_page' => false
157 // send notification to the user, that the registration is pending
158 send_register_pending_eml(
160 $a->config['sitename'],
163 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
177 if(! function_exists('register_content')) {
178 function register_content(App $a) {
180 // logged in users can register others (people/pages/groups)
181 // even with closed registrations, unless specifically prohibited by site policy.
182 // 'block_extended_register' blocks all registrations, period.
184 $block = get_config('system','block_extended_register');
186 if(local_user() && ($block)) {
187 notice("Permission denied." . EOL);
191 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
192 notice("Permission denied." . EOL);
196 $max_dailies = intval(get_config('system','max_daily_registrations'));
198 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
199 if($r && $r[0]['total'] >= $max_dailies) {
200 logger('max daily registrations exceeded.');
201 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
206 if(x($_SESSION,'theme'))
207 unset($_SESSION['theme']);
208 if(x($_SESSION,'mobile-theme'))
209 unset($_SESSION['mobile-theme']);
212 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
213 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
214 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
215 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
216 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
217 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
219 $noid = get_config('system','no_openid');
228 $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" >';
229 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
230 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
231 $oidlabel = t("Your OpenID \x28optional\x29: ");
234 // I set this and got even more fake names than before...
236 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
238 if(get_config('system','publish_all')) {
239 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
242 $publish_tpl = get_markup_template("profile_publish.tpl");
243 $profile_publish = replace_macros($publish_tpl,array(
244 '$instance' => 'reg',
245 '$pubdesc' => t('Include your profile in member directory?'),
246 '$yes_selected' => ' checked="checked" ',
247 '$no_selected' => '',
248 '$str_yes' => t('Yes'),
249 '$str_no' => t('No'),
253 $r = q("SELECT count(*) AS `contacts` FROM `contact`");
254 $passwords = !$r[0]["contacts"];
258 $o = get_markup_template("register.tpl");
260 $arr = array('template' => $o);
262 call_hooks('register_form',$arr);
264 $o = $arr['template'];
266 $o = replace_macros($o, array(
267 '$oidhtml' => $oidhtml,
268 '$invitations' => get_config('system','invitation_only'),
269 '$permonly' => $a->config['register_policy'] == REGISTER_APPROVE,
270 '$permonlybox' => array('permonlybox', t('Note for the admin'), '', t('Leave a message for the admin, why you want to join this node')),
271 '$invite_desc' => t('Membership on this site is by invitation only.'),
272 '$invite_label' => t('Your invitation ID: '),
273 '$invite_id' => $invite_id,
274 '$realpeople' => $realpeople,
275 '$regtitle' => t('Registration'),
276 '$registertext' =>((x($a->config,'register_text'))
277 ? bbcode($a->config['register_text'])
279 '$fillwith' => $fillwith,
280 '$fillext' => $fillext,
281 '$oidlabel' => $oidlabel,
282 '$openid' => $openid_url,
283 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
284 '$addrlabel' => t('Your Email Address: '),
285 '$passwords' => $passwords,
286 '$password1' => array('password1', t('New Password:'), '', t('Leave empty for an auto generated password.')),
287 '$password2' => array('confirm', t('Confirm:'), '', ''),
288 '$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>\'.')),
289 '$nicklabel' => t('Choose a nickname: '),
291 '$publish' => $profile_publish,
292 '$regbutt' => t('Register'),
293 '$username' => $username,
295 '$nickname' => $nickname,
296 '$license' => $license,
297 '$sitename' => $a->get_hostname(),
298 '$importh' => t('Import'),
299 '$importt' => t('Import your profile to this friendica instance'),
300 '$form_security_token' => get_form_security_token("register")