3 if(! function_exists('register_post')) {
4 function register_post(&$a) {
11 switch($a->config['register_policy']) {
19 case REGISTER_APPROVE:
26 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
27 notice( t('Permission denied.') . EOL );
36 $username = ((x($_POST,'username')) ? notags(trim($_POST['username'])) : '');
37 $nickname = ((x($_POST,'nickname')) ? notags(trim($_POST['nickname'])) : '');
38 $email = ((x($_POST,'email')) ? notags(trim($_POST['email'])) : '');
39 $openid_url = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url'])) : '');
40 $photo = ((x($_POST,'photo')) ? notags(trim($_POST['photo'])) : '');
41 $publish = ((x($_POST,'profile_publish_reg') && intval($_POST['profile_publish_reg'])) ? 1 : 0);
43 $netpublish = ((strlen(get_config('system','directory_submit_url'))) ? $publish : 0);
45 $tmp_str = $openid_url;
46 if((! x($username)) || (! x($email)) || (! x($nickname))) {
48 if(! validate_url($tmp_str)) {
49 notice( t('Invalid OpenID url') . EOL);
52 $_SESSION['register'] = 1;
53 $_SESSION['openid'] = $openid_url;
54 require_once('library/openid.php');
55 $openid = new LightOpenID;
56 $openid->identity = $openid_url;
57 $openid->returnUrl = $a->get_baseurl() . '/openid';
58 $openid->required = array('namePerson/friendly', 'contact/email', 'namePerson');
59 $openid->optional = array('namePerson/first','media/image/aspect11','media/image/default');
60 goaway($openid->authUrl());
64 notice( t('Please enter the required information.') . EOL );
68 if(! validate_url($tmp_str))
75 if(mb_strlen($username) > 48)
76 $err .= t('Please use a shorter name.') . EOL;
77 if(mb_strlen($username) < 3)
78 $err .= t('Name too short.') . EOL;
80 // I don't really like having this rule, but it cuts down
81 // on the number of auto-registrations by Russian spammers
83 // Using preg_match was completely unreliable, due to mixed UTF-8 regex support
84 // $no_utf = get_config('system','no_utf');
85 // $pat = (($no_utf) ? '/^[a-zA-Z]* [a-zA-Z]*$/' : '/^\p{L}* \p{L}*$/u' );
87 // So now we are just looking for a space in the full name.
89 $loose_reg = get_config('system','no_regfullname');
91 $username = mb_convert_case($username,MB_CASE_TITLE,'UTF-8');
92 if(! strpos($username,' '))
93 $err .= t("That doesn't appear to be your full \x28First Last\x29 name.") . EOL;
96 if(! allowed_email($email))
97 $err .= t('Your email domain is not among those allowed on this site.') . EOL;
99 if((! valid_email($email)) || (! validate_email($email)))
100 $err .= t('Not a valid email address.') . EOL;
102 // Disallow somebody creating an account using openid that uses the admin email address,
103 // since openid bypasses email verification.
105 if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0) && strlen($openid_url))
106 $err .= t('Cannot use that email.') . EOL;
108 $nickname = $_POST['nickname'] = strtolower($nickname);
110 if(! preg_match("/^[a-z][a-z0-9\-\_]*$/",$nickname))
111 $err .= t('Your "nickname" can only contain "a-z", "0-9", "-", and "_", and must also begin with a letter.') . EOL;
112 $r = q("SELECT `uid` FROM `user`
113 WHERE `nickname` = '%s' LIMIT 1",
117 $err .= t('Nickname is already registered. Please choose another.') . EOL;
125 $new_password = autoname(6) . mt_rand(100,9999);
126 $new_password_encoded = hash('whirlpool',$new_password);
128 $res=openssl_pkey_new(array(
129 'digest_alg' => 'sha1',
130 'private_key_bits' => 4096,
131 'encrypt_key' => false ));
136 notice( t('SERIOUS ERROR: Generation of security keys failed.') . EOL);
142 openssl_pkey_export($res, $prvkey);
146 $pkey = openssl_pkey_get_details($res);
147 $pubkey = $pkey["key"];
151 * Create another keypair for signing/verifying
152 * salmon protocol messages. We have to use a slightly
153 * less robust key because this won't be using openssl
154 * but the phpseclib. Since it is PHP interpreted code
155 * it is not nearly as efficient, and the larger keys
156 * will take several minutes each to process.
160 $sres=openssl_pkey_new(array(
161 'digest_alg' => 'sha1',
162 'private_key_bits' => 512,
163 'encrypt_key' => false ));
169 openssl_pkey_export($sres, $sprvkey);
173 $spkey = openssl_pkey_get_details($sres);
174 $spubkey = $spkey["key"];
176 $r = q("INSERT INTO `user` ( `username`, `password`, `email`, `openid`, `nickname`,
177 `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked` )
178 VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
180 dbesc($new_password_encoded),
188 dbesc(datetime_convert()),
194 $r = q("SELECT `uid` FROM `user`
195 WHERE `username` = '%s' AND `password` = '%s' LIMIT 1",
197 dbesc($new_password_encoded)
199 if($r !== false && count($r))
200 $newuid = intval($r[0]['uid']);
203 notice( t('An error occurred during registration. Please try again.') . EOL );
208 * if somebody clicked submit twice very quickly, they could end up with two accounts
209 * due to race condition. Remove this one.
212 $r = q("SELECT `uid` FROM `user`
213 WHERE `nickname` = '%s' ",
216 if((count($r) > 1) && $newuid) {
217 $err .= t('Nickname is already registered. Please choose another.') . EOL;
218 q("DELETE FROM `user` WHERE `uid` = %d LIMIT 1",
225 if(x($newuid) !== false) {
226 $r = q("INSERT INTO `profile` ( `uid`, `profile-name`, `is-default`, `name`, `photo`, `thumb`, `publish`, `net-publish` )
227 VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, %d ) ",
232 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
233 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg"),
239 notice( t('An error occurred creating your default profile. Please try again.') . EOL );
240 // Start fresh next time.
241 $r = q("DELETE FROM `user` WHERE `uid` = %d",
245 $r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`,
246 `request`, `notify`, `poll`, `confirm`, `name-date`, `uri-date`, `avatar-date` )
247 VALUES ( %d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
252 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
253 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg"),
254 dbesc($a->get_baseurl() . "/photo/micro/{$newuid}.jpg"),
255 dbesc($a->get_baseurl() . "/profile/$nickname"),
256 dbesc($a->get_baseurl() . "/dfrn_request/$nickname"),
257 dbesc($a->get_baseurl() . "/dfrn_notify/$nickname"),
258 dbesc($a->get_baseurl() . "/dfrn_poll/$nickname"),
259 dbesc($a->get_baseurl() . "/dfrn_confirm/$nickname"),
260 dbesc(datetime_convert()),
261 dbesc(datetime_convert()),
262 dbesc(datetime_convert())
268 $use_gravatar = ((get_config('system','no_gravatar')) ? false : true);
270 // if we have an openid photo use it.
271 // otherwise unless it is disabled, use gravatar
273 if($use_gravatar || strlen($photo)) {
275 require_once('include/Photo.php');
277 if(($use_gravatar) && (! strlen($photo)))
278 $photo = gravatar_img($email);
279 $photo_failure = false;
281 $filename = basename($photo);
282 $img_str = fetch_url($photo,true);
283 $img = new Photo($img_str);
284 if($img->is_valid()) {
286 $img->scaleImageSquare(175);
288 $hash = photo_new_resource();
290 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4 );
293 $photo_failure = true;
295 $img->scaleImage(80);
297 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5 );
300 $photo_failure = true;
302 $img->scaleImage(48);
304 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6 );
307 $photo_failure = true;
309 if(! $photo_failure) {
310 q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ",
317 if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
318 $url = $a->get_baseurl() . "/profile/$nickname";
319 proc_run('php',"include/directory.php","$url");
323 if( $a->config['register_policy'] == REGISTER_OPEN ) {
324 $email_tpl = get_intltext_template("register_open_eml.tpl");
325 $email_tpl = replace_macros($email_tpl, array(
326 '$sitename' => $a->config['sitename'],
327 '$siteurl' => $a->get_baseurl(),
328 '$username' => $username,
330 '$password' => $new_password,
331 '$uid' => $newuid ));
333 $res = mail($email, sprintf(t('Registration details for %s'), $a->config['sitename']),
335 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
336 . 'Content-type: text/plain; charset=UTF-8' . "\n"
337 . 'Content-transfer-encoding: 8bit' );
341 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
342 goaway($a->get_baseurl());
345 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
348 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
349 if(! strlen($a->config['admin_email'])) {
350 notice( t('Your registration can not be processed.') . EOL);
351 goaway($a->get_baseurl());
354 $hash = random_string();
355 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
357 dbesc(datetime_convert()),
359 dbesc($new_password),
363 $r = q("SELECT `language` FROM `user` WHERE `email` = '%s' LIMIT 1",
364 dbesc($a->config['admin_email'])
367 push_lang($r[0]['language']);
372 $email_tpl = get_intltext_template("register_verify_eml.tpl");
373 $email_tpl = replace_macros($email_tpl, array(
374 '$sitename' => $a->config['sitename'],
375 '$siteurl' => $a->get_baseurl(),
376 '$username' => $username,
378 '$password' => $new_password,
383 $res = mail($a->config['admin_email'], sprintf(t('Registration request at %s'), $a->config['sitename']),
385 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
386 . 'Content-type: text/plain; charset=UTF-8' . "\n"
387 . 'Content-transfer-encoding: 8bit' );
392 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
393 goaway($a->get_baseurl());
406 if(! function_exists('register_content')) {
407 function register_content(&$a) {
409 // logged in users can register others (people/pages/groups)
410 // even with closed registrations, unless specifically prohibited by site policy.
411 // 'block_extended_register' blocks all registrations, period.
413 $block = get_config('system','block_extended_register');
415 if((($a->config['register_policy'] == REGISTER_CLOSED) && (! local_user())) || ($block)) {
416 notice("Permission denied." . EOL);
420 if(x($_SESSION,'theme'))
421 unset($_SESSION['theme']);
424 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
425 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
426 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
427 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
428 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
430 $noid = get_config('system','no_openid');
439 $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" >';
440 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
441 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
442 $oidlabel = t("Your OpenID \x28optional\x29: ");
445 // I set this and got even more fake names than before...
447 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
449 if(get_config('system','publish_all')) {
450 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
453 $publish_tpl = get_markup_template("profile_publish.tpl");
454 $profile_publish = replace_macros($publish_tpl,array(
455 '$instance' => 'reg',
456 '$pubdesc' => t('Include your profile in member directory?'),
457 '$yes_selected' => ' checked="checked" ',
458 '$no_selected' => '',
459 '$str_yes' => t('Yes'),
465 $license = t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.');
468 $o = get_markup_template("register.tpl");
469 $o = replace_macros($o, array(
470 '$oidhtml' => $oidhtml,
471 '$realpeople' => $realpeople,
472 '$regtitle' => t('Registration'),
473 '$registertext' =>((x($a->config,'register_text'))
474 ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
476 '$fillwith' => $fillwith,
477 '$fillext' => $fillext,
478 '$oidlabel' => $oidlabel,
479 '$openid' => $openid_url,
480 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
481 '$addrlabel' => t('Your Email Address: '),
482 '$nickdesc' => 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>\'.'),
483 '$nicklabel' => t('Choose a nickname: '),
485 '$publish' => $profile_publish,
486 '$regbutt' => t('Register'),
487 '$username' => $username,
489 '$nickname' => $nickname,
490 '$license' => $license,
491 '$sitename' => $a->get_hostname()