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(App $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;
55 $arr['language'] = get_browser_language();
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 = App::get_baseurl() . '/profile/' . $user['nickname'];
68 proc_run(PRIORITY_LOW, "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 // Only send a password mail when the password wasn't manually provided
84 if (!x($_POST,'password1') OR !x($_POST,'confirm')) {
85 $res = send_register_open_eml(
87 $a->config['sitename'],
93 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
98 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.'),
105 info( t('Registration successful.') . EOL ) ;
109 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
110 if(! strlen($a->config['admin_email'])) {
111 notice( t('Your registration can not be processed.') . EOL);
115 $hash = random_string();
116 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language`, `note` ) VALUES ( '%s', '%s', %d, '%s', '%s', '%s' ) ",
118 dbesc(datetime_convert()),
119 intval($user['uid']),
120 dbesc($result['password']),
122 dbesc($_POST['permonlybox'])
126 if($using_invites && $invite_id) {
127 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
128 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
131 // send email to admins
132 $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
133 $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
137 // send notification to admins
138 foreach ($adminlist as $admin) {
140 'type' => NOTIFY_SYSTEM,
141 'event' => 'SYSTEM_REGISTER_REQUEST',
142 'source_name' => $user['username'],
143 'source_mail' => $user['email'],
144 'source_nick' => $user['nickname'],
145 'source_link' => App::get_baseurl()."/admin/users/",
146 'link' => App::get_baseurl()."/admin/users/",
147 'source_photo' => App::get_baseurl() . "/photo/avatar/".$user['uid'].".jpg",
148 'to_email' => $admin['email'],
149 'uid' => $admin['uid'],
150 'language' => ($admin['language']?$admin['language']:'en'),
151 'show_in_notification_page' => false
154 // send notification to the user, that the registration is pending
155 send_register_pending_eml(
157 $a->config['sitename'],
160 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
174 if(! function_exists('register_content')) {
175 function register_content(App $a) {
177 // logged in users can register others (people/pages/groups)
178 // even with closed registrations, unless specifically prohibited by site policy.
179 // 'block_extended_register' blocks all registrations, period.
181 $block = get_config('system','block_extended_register');
183 if(local_user() && ($block)) {
184 notice("Permission denied." . EOL);
188 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
189 notice("Permission denied." . EOL);
193 $max_dailies = intval(get_config('system','max_daily_registrations'));
195 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
196 if($r && $r[0]['total'] >= $max_dailies) {
197 logger('max daily registrations exceeded.');
198 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
203 if(x($_SESSION,'theme'))
204 unset($_SESSION['theme']);
205 if(x($_SESSION,'mobile-theme'))
206 unset($_SESSION['mobile-theme']);
209 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
210 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
211 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
212 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
213 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
214 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
216 $noid = get_config('system','no_openid');
225 $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" >';
226 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
227 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
228 $oidlabel = t("Your OpenID \x28optional\x29: ");
231 // I set this and got even more fake names than before...
233 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
235 if(get_config('system','publish_all')) {
236 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
239 $publish_tpl = get_markup_template("profile_publish.tpl");
240 $profile_publish = replace_macros($publish_tpl,array(
241 '$instance' => 'reg',
242 '$pubdesc' => t('Include your profile in member directory?'),
243 '$yes_selected' => ' checked="checked" ',
244 '$no_selected' => '',
245 '$str_yes' => t('Yes'),
246 '$str_no' => t('No'),
250 $r = q("SELECT count(*) AS `contacts` FROM `contact`");
251 $passwords = !$r[0]["contacts"];
255 $o = get_markup_template("register.tpl");
257 $arr = array('template' => $o);
259 call_hooks('register_form',$arr);
261 $o = $arr['template'];
263 $o = replace_macros($o, array(
264 '$oidhtml' => $oidhtml,
265 '$invitations' => get_config('system','invitation_only'),
266 '$permonly' => $a->config['register_policy'] == REGISTER_APPROVE,
267 '$permonlybox' => array('permonlybox', t('Note for the admin'), '', t('Leave a message for the admin, why you want to join this node')),
268 '$invite_desc' => t('Membership on this site is by invitation only.'),
269 '$invite_label' => t('Your invitation ID: '),
270 '$invite_id' => $invite_id,
271 '$realpeople' => $realpeople,
272 '$regtitle' => t('Registration'),
273 '$registertext' =>((x($a->config,'register_text'))
274 ? bbcode($a->config['register_text'])
276 '$fillwith' => $fillwith,
277 '$fillext' => $fillext,
278 '$oidlabel' => $oidlabel,
279 '$openid' => $openid_url,
280 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
281 '$addrlabel' => t('Your Email Address: '),
282 '$passwords' => $passwords,
283 '$password1' => array('password1', t('New Password:'), '', t('Leave empty for an auto generated password.')),
284 '$password2' => array('confirm', t('Confirm:'), '', ''),
285 '$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>\'.')),
286 '$nicklabel' => t('Choose a nickname: '),
288 '$publish' => $profile_publish,
289 '$regbutt' => t('Register'),
290 '$username' => $username,
292 '$nickname' => $nickname,
293 '$license' => $license,
294 '$sitename' => $a->get_hostname(),
295 '$importh' => t('Import'),
296 '$importt' => t('Import your profile to this friendica instance'),