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(PRIORITY_LOW, "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)",
135 foreach ($adminlist as $admin) {
137 'type' => NOTIFY_SYSTEM,
138 'event' => 'SYSTEM_REGISTER_REQUEST',
139 'source_name' => $user['username'],
140 'source_mail' => $user['email'],
141 'source_nick' => $user['nickname'],
142 'source_link' => $a->get_baseurl()."/admin/users/",
143 'link' => $a->get_baseurl()."/admin/users/",
144 'source_photo' => $a->get_baseurl() . "/photo/avatar/".$user['uid'].".jpg",
145 'to_email' => $admin['email'],
146 'uid' => $admin['uid'],
147 'language' => ($admin['language']?$admin['language']:'en'),
148 'show_in_notification_page' => false
152 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
166 if(! function_exists('register_content')) {
167 function register_content(&$a) {
169 // logged in users can register others (people/pages/groups)
170 // even with closed registrations, unless specifically prohibited by site policy.
171 // 'block_extended_register' blocks all registrations, period.
173 $block = get_config('system','block_extended_register');
175 if(local_user() && ($block)) {
176 notice("Permission denied." . EOL);
180 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
181 notice("Permission denied." . EOL);
185 $max_dailies = intval(get_config('system','max_daily_registrations'));
187 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
188 if($r && $r[0]['total'] >= $max_dailies) {
189 logger('max daily registrations exceeded.');
190 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
195 if(x($_SESSION,'theme'))
196 unset($_SESSION['theme']);
197 if(x($_SESSION,'mobile-theme'))
198 unset($_SESSION['mobile-theme']);
201 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
202 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
203 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
204 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
205 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
206 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
208 $noid = get_config('system','no_openid');
217 $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" >';
218 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
219 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
220 $oidlabel = t("Your OpenID \x28optional\x29: ");
223 // I set this and got even more fake names than before...
225 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
227 if(get_config('system','publish_all')) {
228 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
231 $publish_tpl = get_markup_template("profile_publish.tpl");
232 $profile_publish = replace_macros($publish_tpl,array(
233 '$instance' => 'reg',
234 '$pubdesc' => t('Include your profile in member directory?'),
235 '$yes_selected' => ' checked="checked" ',
236 '$no_selected' => '',
237 '$str_yes' => t('Yes'),
238 '$str_no' => t('No'),
242 $r = q("SELECT count(*) AS `contacts` FROM `contact`");
243 $passwords = !$r[0]["contacts"];
247 $o = get_markup_template("register.tpl");
249 $arr = array('template' => $o);
251 call_hooks('register_form',$arr);
253 $o = $arr['template'];
255 $o = replace_macros($o, array(
256 '$oidhtml' => $oidhtml,
257 '$invitations' => get_config('system','invitation_only'),
258 '$invite_desc' => t('Membership on this site is by invitation only.'),
259 '$invite_label' => t('Your invitation ID: '),
260 '$invite_id' => $invite_id,
261 '$realpeople' => $realpeople,
262 '$regtitle' => t('Registration'),
263 '$registertext' =>((x($a->config,'register_text'))
264 ? bbcode($a->config['register_text'])
266 '$fillwith' => $fillwith,
267 '$fillext' => $fillext,
268 '$oidlabel' => $oidlabel,
269 '$openid' => $openid_url,
270 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
271 '$addrlabel' => t('Your Email Address: '),
272 '$passwords' => $passwords,
273 '$password1' => array('password1', t('New Password:'), '', t('Leave empty for an auto generated password.')),
274 '$password2' => array('confirm', t('Confirm:'), '', ''),
275 '$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>\'.')),
276 '$nicklabel' => t('Choose a nickname: '),
278 '$publish' => $profile_publish,
279 '$regbutt' => t('Register'),
280 '$username' => $username,
282 '$nickname' => $nickname,
283 '$license' => $license,
284 '$sitename' => $a->get_hostname(),
285 '$importh' => t('Import'),
286 '$importt' => t('Import your profile to this friendica instance'),