3 if(! function_exists('register_post')) {
4 function register_post(&$a) {
9 switch($a->config['register_policy']) {
17 case REGISTER_APPROVE:
24 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
25 notice( t('Permission denied.') . EOL );
34 $username = ((x($_POST,'username')) ? notags(trim($_POST['username'])) : '');
35 $nickname = ((x($_POST,'nickname')) ? notags(trim($_POST['nickname'])) : '');
36 $email = ((x($_POST,'email')) ? notags(trim($_POST['email'])) : '');
37 $openid_url = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url'])) : '');
38 $photo = ((x($_POST,'photo')) ? notags(trim($_POST['photo'])) : '');
40 $tmp_str = $openid_url;
41 if((! x($username)) || (! x($email)) || (! x($nickname))) {
43 if(! validate_url($tmp_str)) {
44 notice( t('Invalid OpenID url') . EOL);
47 $_SESSION['register'] = 1;
48 $_SESSION['openid'] = $openid_url;
49 require_once('library/openid.php');
50 $openid = new LightOpenID;
51 $openid->identity = $openid_url;
52 $openid->returnUrl = $a->get_baseurl() . '/openid';
53 $openid->required = array('namePerson/friendly', 'contact/email', 'namePerson');
54 $openid->optional = array('namePerson/first','media/image/aspect11','media/image/default');
55 goaway($openid->authUrl());
59 notice( t('Please enter the required information.') . EOL );
66 if(strlen($username) > 48)
67 $err .= t('Please use a shorter name.') . EOL;
68 if(strlen($username) < 3)
69 $err .= t('Name too short.') . EOL;
71 // I don't really like having this rule, but it cuts down
72 // on the number of auto-registrations by Russian spammers
74 // Using preg_match was completely unreliable, due to mixed UTF-8 regex support
75 // $no_utf = get_config('system','no_utf');
76 // $pat = (($no_utf) ? '/^[a-zA-Z]* [a-zA-Z]*$/' : '/^\p{L}* \p{L}*$/u' );
78 // So now we are just looking for a space in the full name.
80 $loose_reg = get_config('system','no_regfullname');
81 if((! $loose_reg) && (! strpos($username,' ')))
82 $err .= t("That doesn\'t appear to be your full \x28First Last\x29 name.") . EOL;
84 if(! allowed_email($email))
85 $err .= t('Your email domain is not among those allowed on this site.') . EOL;
87 if((! valid_email($email)) || (! validate_email($email)))
88 $err .= t('Not a valid email address.') . EOL;
90 // Disallow somebody creating an account using openid that uses the admin email address,
91 // since openid bypasses email verification.
93 if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0) && strlen($openid_url))
94 $err .= t('Cannot use that email.') . EOL;
96 $nickname = $_POST['nickname'] = strtolower($nickname);
98 if(! preg_match("/^[a-z][a-z0-9\-\_]*$/",$nickname))
99 $err .= t('Your "nickname" can only contain "a-z", "0-9", "-", and "_", and must also begin with a letter.') . EOL;
100 $r = q("SELECT `uid` FROM `user`
101 WHERE `nickname` = '%s' LIMIT 1",
105 $err .= t('Nickname is already registered. Please choose another.') . EOL;
113 $new_password = autoname(6) . mt_rand(100,9999);
114 $new_password_encoded = hash('whirlpool',$new_password);
116 $res=openssl_pkey_new(array(
117 'digest_alg' => 'sha1',
118 'private_key_bits' => 4096,
119 'encrypt_key' => false ));
124 notice( t('SERIOUS ERROR: Generation of security keys failed.') . EOL);
130 openssl_pkey_export($res, $prvkey);
134 $pkey = openssl_pkey_get_details($res);
135 $pubkey = $pkey["key"];
139 * Create another keypair for signing/verifying
140 * salmon protocol messages. We have to use a slightly
141 * less robust key because this won't be using openssl
142 * but the phpseclib. Since it is PHP interpreted code
143 * it is not nearly as efficient, and the larger keys
144 * will take several minutes each to process.
148 $sres=openssl_pkey_new(array(
149 'digest_alg' => 'sha1',
150 'private_key_bits' => 512,
151 'encrypt_key' => false ));
157 openssl_pkey_export($sres, $sprvkey);
161 $spkey = openssl_pkey_get_details($sres);
162 $spubkey = $spkey["key"];
164 $r = q("INSERT INTO `user` ( `username`, `password`, `email`, `openid`, `nickname`,
165 `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked` )
166 VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
168 dbesc($new_password_encoded),
176 dbesc(datetime_convert()),
182 $r = q("SELECT `uid` FROM `user`
183 WHERE `username` = '%s' AND `password` = '%s' LIMIT 1",
185 dbesc($new_password_encoded)
187 if($r !== false && count($r))
188 $newuid = intval($r[0]['uid']);
191 notice( t('An error occurred during registration. Please try again.') . EOL );
195 if(x($newuid) !== false) {
196 $r = q("INSERT INTO `profile` ( `uid`, `profile-name`, `is-default`, `name`, `photo`, `thumb` )
197 VALUES ( %d, '%s', %d, '%s', '%s', '%s' ) ",
202 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
203 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg")
207 notice( t('An error occurred creating your default profile. Please try again.') . EOL );
208 // Start fresh next time.
209 $r = q("DELETE FROM `user` WHERE `uid` = %d",
213 $r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`,
214 `request`, `notify`, `poll`, `confirm`, `name-date`, `uri-date`, `avatar-date` )
215 VALUES ( %d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
220 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
221 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg"),
222 dbesc($a->get_baseurl() . "/photo/micro/{$newuid}.jpg"),
223 dbesc($a->get_baseurl() . "/profile/$nickname"),
224 dbesc($a->get_baseurl() . "/dfrn_request/$nickname"),
225 dbesc($a->get_baseurl() . "/dfrn_notify/$nickname"),
226 dbesc($a->get_baseurl() . "/dfrn_poll/$nickname"),
227 dbesc($a->get_baseurl() . "/dfrn_confirm/$nickname"),
228 dbesc(datetime_convert()),
229 dbesc(datetime_convert()),
230 dbesc(datetime_convert())
236 $use_gravatar = ((get_config('system','no_gravatar')) ? false : true);
238 // if we have an openid photo use it.
239 // otherwise unless it is disabled, use gravatar
241 if($use_gravatar || strlen($photo)) {
243 require_once('include/Photo.php');
245 if(($use_gravatar) && (! strlen($photo)))
246 $photo = gravatar_img($email);
247 $photo_failure = false;
249 $filename = basename($photo);
250 $img_str = fetch_url($photo,true);
251 $img = new Photo($img_str);
252 if($img->is_valid()) {
254 $img->scaleImageSquare(175);
256 $hash = photo_new_resource();
258 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4 );
261 $photo_failure = true;
263 $img->scaleImage(80);
265 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5 );
268 $photo_failure = true;
270 $img->scaleImage(48);
272 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6 );
275 $photo_failure = true;
277 if(! $photo_failure) {
278 q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ",
285 if( $a->config['register_policy'] == REGISTER_OPEN ) {
286 $email_tpl = load_view_file("view/register_open_eml.tpl");
287 $email_tpl = replace_macros($email_tpl, array(
288 '$sitename' => $a->config['sitename'],
289 '$siteurl' => $a->get_baseurl(),
290 '$username' => $username,
292 '$password' => $new_password,
293 '$uid' => $newuid ));
295 $res = mail($email, t('Registration details for ') . $a->config['sitename'],
296 $email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
300 notice( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
301 goaway($a->get_baseurl());
304 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
307 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
308 if(! strlen($a->config['admin_email'])) {
309 notice( t('Your registration can not be processed.') . EOL);
310 goaway($a->get_baseurl());
313 $hash = random_string();
314 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password` ) VALUES ( '%s', '%s', %d, '%s' ) ",
316 dbesc(datetime_convert()),
321 $email_tpl = load_view_file("view/register_verify_eml.tpl");
322 $email_tpl = replace_macros($email_tpl, array(
323 '$sitename' => $a->config['sitename'],
324 '$siteurl' => $a->get_baseurl(),
325 '$username' => $username,
327 '$password' => $new_password,
332 $res = mail($a->config['admin_email'], t('Registration request at ') . $a->config['sitename'],
333 $email_tpl,'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
336 notice( t('Your registration is pending approval by the site owner.') . EOL ) ;
337 goaway($a->get_baseurl());
349 if(! function_exists('register_content')) {
350 function register_content(&$a) {
352 // logged in users can register others (people/pages/groups)
353 // even with closed registrations, unless specifically prohibited by site policy.
354 // 'block_extended_register' blocks all registrations, period.
356 $block = get_config('system','block_extended_register');
358 if((($a->config['register_policy'] == REGISTER_CLOSED) && (! getuid())) || ($block)) {
359 notice("Permission denied." . EOL);
363 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
364 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
365 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
366 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
367 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
369 $noid = get_config('system','no_openid');
378 $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" >';
379 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
380 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
381 $oidlabel = t("Your OpenID \x28optional\x29: ");
384 $license = t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.');
387 $o = load_view_file("view/register.tpl");
388 $o = replace_macros($o, array(
389 '$oidhtml' => $oidhtml,
390 '$regtitle' => t('Registration'),
391 '$registertext' =>((x($a->config,'register_text'))
392 ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
394 '$fillwith' => $fillwith,
395 '$fillext' => $fillext,
396 '$oidlabel' => $oidlabel,
397 '$openid' => $openid_url,
398 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
399 '$addrlabel' => t('Your Email Address: '),
400 '$nickdesc' => t('Choose a profile nickname. This must begin with a text character. Your global profile locator will then be \'<strong>nickname@$sitename</strong>\'.'),
401 '$nicklabel' => t('Choose a nickname: '),
403 '$regbutt' => t('Register'),
404 '$username' => $username,
406 '$nickname' => $nickname,
407 '$license' => $license,
408 '$sitename' => $a->get_hostname()