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 if((! x($username)) || (! x($email)) || (! x($nickname))) {
42 $_SESSION['register'] = 1;
43 $_SESSION['openid'] = $openid_url;
44 require_once('library/openid.php');
45 $openid = new LightOpenID;
46 $openid->identity = $openid_url;
47 $openid->returnUrl = $a->get_baseurl() . '/openid';
48 $openid->required = array('namePerson/friendly', 'contact/email', 'namePerson');
49 $openid->optional = array('namePerson/first','media/image/aspect11','media/image/default');
50 goaway($openid->authUrl());
54 notice( t('Please enter the required information.') . EOL );
61 if(strlen($username) > 48)
62 $err .= t('Please use a shorter name.') . EOL;
63 if(strlen($username) < 3)
64 $err .= t('Name too short.') . EOL;
66 // I don't really like having this rule, but it cuts down
67 // on the number of auto-registrations by Russian spammers
69 // Using preg_match was completely unreliable, due to mixed UTF-8 regex support
70 // $no_utf = get_config('system','no_utf');
71 // $pat = (($no_utf) ? '/^[a-zA-Z]* [a-zA-Z]*$/' : '/^\p{L}* \p{L}*$/u' );
73 // So now we are just looking for a space in the full name.
75 $loose_reg = get_config('system','no_regfullname');
76 if((! $loose_reg) && (! strpos($username,' ')))
77 $err .= t("That doesn\'t appear to be your full \x28First Last\x29 name.") . EOL;
79 if(! allowed_email($email))
80 $err .= t('Your email domain is not among those allowed on this site.') . EOL;
82 if((! valid_email($email)) || (! validate_email($email)))
83 $err .= t('Not a valid email address.') . EOL;
85 $nickname = $_POST['nickname'] = strtolower($nickname);
87 if(! preg_match("/^[a-z][a-z0-9\-\_]*$/",$nickname))
88 $err .= t('Your "nickname" can only contain "a-z", "0-9", "-", and "_", and must also begin with a letter.') . EOL;
89 $r = q("SELECT `uid` FROM `user`
90 WHERE `nickname` = '%s' LIMIT 1",
94 $err .= t('Nickname is already registered. Please choose another.') . EOL;
102 $new_password = autoname(6) . mt_rand(100,9999);
103 $new_password_encoded = hash('whirlpool',$new_password);
105 $res=openssl_pkey_new(array(
106 'digest_alg' => 'sha1',
107 'private_key_bits' => 4096,
108 'encrypt_key' => false ));
113 notice( t('SERIOUS ERROR: Generation of security keys failed.') . EOL);
119 openssl_pkey_export($res, $prvkey);
123 $pkey = openssl_pkey_get_details($res);
124 $pubkey = $pkey["key"];
128 * Create another keypair for signing/verifying
129 * salmon protocol messages. We have to use a slightly
130 * less robust key because this won't be using openssl
131 * but the phpseclib. Since it is PHP interpreted code
132 * it is not nearly as efficient, and the larger keys
133 * will take several minutes each to process.
137 $sres=openssl_pkey_new(array(
138 'digest_alg' => 'sha1',
139 'private_key_bits' => 512,
140 'encrypt_key' => false ));
146 openssl_pkey_export($sres, $sprvkey);
150 $spkey = openssl_pkey_get_details($sres);
151 $spubkey = $spkey["key"];
153 $r = q("INSERT INTO `user` ( `username`, `password`, `email`, `openid`, `nickname`,
154 `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked` )
155 VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
157 dbesc($new_password_encoded),
165 dbesc(datetime_convert()),
171 $r = q("SELECT `uid` FROM `user`
172 WHERE `username` = '%s' AND `password` = '%s' LIMIT 1",
174 dbesc($new_password_encoded)
176 if($r !== false && count($r))
177 $newuid = intval($r[0]['uid']);
180 notice( t('An error occurred during registration. Please try again.') . EOL );
184 if(x($newuid) !== false) {
185 $r = q("INSERT INTO `profile` ( `uid`, `profile-name`, `is-default`, `name`, `photo`, `thumb` )
186 VALUES ( %d, '%s', %d, '%s', '%s', '%s' ) ",
191 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
192 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg")
196 notice( t('An error occurred creating your default profile. Please try again.') . EOL );
197 // Start fresh next time.
198 $r = q("DELETE FROM `user` WHERE `uid` = %d",
202 $r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`,
203 `request`, `notify`, `poll`, `confirm`, `name-date`, `uri-date`, `avatar-date` )
204 VALUES ( %d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
209 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
210 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg"),
211 dbesc($a->get_baseurl() . "/photo/micro/{$newuid}.jpg"),
212 dbesc($a->get_baseurl() . "/profile/$nickname"),
213 dbesc($a->get_baseurl() . "/dfrn_request/$nickname"),
214 dbesc($a->get_baseurl() . "/dfrn_notify/$nickname"),
215 dbesc($a->get_baseurl() . "/dfrn_poll/$nickname"),
216 dbesc($a->get_baseurl() . "/dfrn_confirm/$nickname"),
217 dbesc(datetime_convert()),
218 dbesc(datetime_convert()),
219 dbesc(datetime_convert())
225 $use_gravatar = ((get_config('system','no_gravatar')) ? false : true);
227 // if we have an openid photo use it.
228 // otherwise unless it is disabled, use gravatar
230 if($use_gravatar || strlen($photo)) {
232 require_once('include/Photo.php');
234 if(($use_gravatar) && (! strlen($photo)))
235 $photo = gravatar_img($email);
236 $photo_failure = false;
238 $filename = basename($photo);
239 $img_str = fetch_url($photo,true);
240 $img = new Photo($img_str);
241 if($img->is_valid()) {
243 $img->scaleImageSquare(175);
245 $hash = photo_new_resource();
247 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4 );
250 $photo_failure = true;
252 $img->scaleImage(80);
254 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5 );
257 $photo_failure = true;
259 $img->scaleImage(48);
261 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6 );
264 $photo_failure = true;
266 if(! $photo_failure) {
267 q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ",
274 if( $a->config['register_policy'] == REGISTER_OPEN ) {
275 $email_tpl = load_view_file("view/register_open_eml.tpl");
276 $email_tpl = replace_macros($email_tpl, array(
277 '$sitename' => $a->config['sitename'],
278 '$siteurl' => $a->get_baseurl(),
279 '$username' => $username,
281 '$password' => $new_password,
282 '$uid' => $newuid ));
284 $res = mail($email, t('Registration details for ') . $a->config['sitename'],
285 $email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
289 notice( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
290 goaway($a->get_baseurl());
293 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
296 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
297 if(! strlen($a->config['admin_email'])) {
298 notice( t('Your registration can not be processed.') . EOL);
299 goaway($a->get_baseurl());
302 $hash = random_string();
303 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password` ) VALUES ( '%s', '%s', %d, '%s' ) ",
305 dbesc(datetime_convert()),
310 $email_tpl = load_view_file("view/register_verify_eml.tpl");
311 $email_tpl = replace_macros($email_tpl, array(
312 '$sitename' => $a->config['sitename'],
313 '$siteurl' => $a->get_baseurl(),
314 '$username' => $username,
316 '$password' => $new_password,
321 $res = mail($a->config['admin_email'], t('Registration request at ') . $a->config['sitename'],
322 $email_tpl,'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
325 notice( t('Your registration is pending approval by the site owner.') . EOL ) ;
326 goaway($a->get_baseurl());
338 if(! function_exists('register_content')) {
339 function register_content(&$a) {
341 // logged in users can register others (people/pages/groups)
342 // even with closed registrations, unless specifically prohibited by site policy.
343 // 'block_extended_register' blocks all registrations, period.
345 $block = get_config('system','block_extended_register');
347 if((($a->config['register_policy'] == REGISTER_CLOSED) && (! getuid())) || ($block)) {
348 notice("Permission denied." . EOL);
352 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
353 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
354 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
355 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
356 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
358 $noid = get_config('system','no_openid');
367 $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" >';
368 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
369 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
370 $oidlabel = t("Your OpenID \x28optional\x29: ");
373 $license = t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.');
376 $o = load_view_file("view/register.tpl");
377 $o = replace_macros($o, array(
378 '$oidhtml' => $oidhtml,
379 '$regtitle' => t('Registration'),
380 '$registertext' =>((x($a->config,'register_text'))
381 ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
383 '$fillwith' => $fillwith,
384 '$fillext' => $fillext,
385 '$oidlabel' => $oidlabel,
386 '$openid' => $openid_url,
387 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
388 '$addrlabel' => t('Your Email Address: '),
389 '$nickdesc' => t('Choose a profile nickname. This must begin with a text character. Your global profile locator will then be \'<strong>nickname@$sitename</strong>\'.'),
390 '$nicklabel' => t('Choose a nickname: '),
392 '$regbutt' => t('Register'),
393 '$username' => $username,
395 '$nickname' => $nickname,
396 '$license' => $license,
397 '$sitename' => $a->get_hostname()