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"];
126 $sres=openssl_pkey_new(array(
127 'encrypt_key' => false ));
133 openssl_pkey_export($sres, $sprvkey);
137 $spkey = openssl_pkey_get_details($sres);
138 $spubkey = $spkey["key"];
140 $r = q("INSERT INTO `user` ( `username`, `password`, `email`, `openid`, `nickname`,
141 `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked` )
142 VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
144 dbesc($new_password_encoded),
152 dbesc(datetime_convert()),
158 $r = q("SELECT `uid` FROM `user`
159 WHERE `username` = '%s' AND `password` = '%s' LIMIT 1",
161 dbesc($new_password_encoded)
163 if($r !== false && count($r))
164 $newuid = intval($r[0]['uid']);
167 notice( t('An error occurred during registration. Please try again.') . EOL );
171 if(x($newuid) !== false) {
172 $r = q("INSERT INTO `profile` ( `uid`, `profile-name`, `is-default`, `name`, `photo`, `thumb` )
173 VALUES ( %d, '%s', %d, '%s', '%s', '%s' ) ",
178 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
179 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg")
183 notice( t('An error occurred creating your default profile. Please try again.') . EOL );
184 // Start fresh next time.
185 $r = q("DELETE FROM `user` WHERE `uid` = %d",
189 $r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`,
190 `request`, `notify`, `poll`, `confirm`, `name-date`, `uri-date`, `avatar-date` )
191 VALUES ( %d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
196 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
197 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg"),
198 dbesc($a->get_baseurl() . "/photo/micro/{$newuid}.jpg"),
199 dbesc($a->get_baseurl() . "/profile/$nickname"),
200 dbesc($a->get_baseurl() . "/dfrn_request/$nickname"),
201 dbesc($a->get_baseurl() . "/dfrn_notify/$nickname"),
202 dbesc($a->get_baseurl() . "/dfrn_poll/$nickname"),
203 dbesc($a->get_baseurl() . "/dfrn_confirm/$nickname"),
204 dbesc(datetime_convert()),
205 dbesc(datetime_convert()),
206 dbesc(datetime_convert())
212 $use_gravatar = ((get_config('system','no_gravatar')) ? false : true);
214 // if we have an openid photo use it.
215 // otherwise unless it is disabled, use gravatar
217 if($use_gravatar || strlen($photo)) {
219 require_once('include/Photo.php');
221 if(($use_gravatar) && (! strlen($photo)))
222 $photo = gravatar_img($email);
223 $photo_failure = false;
225 $filename = basename($photo);
226 $img_str = fetch_url($photo,true);
227 $img = new Photo($img_str);
228 if($img->is_valid()) {
230 $img->scaleImageSquare(175);
232 $hash = photo_new_resource();
234 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4 );
237 $photo_failure = true;
239 $img->scaleImage(80);
241 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5 );
244 $photo_failure = true;
246 $img->scaleImage(48);
248 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6 );
251 $photo_failure = true;
253 if(! $photo_failure) {
254 q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ",
261 if( $a->config['register_policy'] == REGISTER_OPEN ) {
262 $email_tpl = load_view_file("view/register_open_eml.tpl");
263 $email_tpl = replace_macros($email_tpl, array(
264 '$sitename' => $a->config['sitename'],
265 '$siteurl' => $a->get_baseurl(),
266 '$username' => $username,
268 '$password' => $new_password,
269 '$uid' => $newuid ));
271 $res = mail($email, t('Registration details for ') . $a->config['sitename'],
272 $email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
276 notice( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
277 goaway($a->get_baseurl());
280 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
283 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
284 if(! strlen($a->config['admin_email'])) {
285 notice( t('Your registration can not be processed.') . EOL);
286 goaway($a->get_baseurl());
289 $hash = random_string();
290 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password` ) VALUES ( '%s', '%s', %d, '%s' ) ",
292 dbesc(datetime_convert()),
297 $email_tpl = load_view_file("view/register_verify_eml.tpl");
298 $email_tpl = replace_macros($email_tpl, array(
299 '$sitename' => $a->config['sitename'],
300 '$siteurl' => $a->get_baseurl(),
301 '$username' => $username,
303 '$password' => $new_password,
308 $res = mail($a->config['admin_email'], t('Registration request at ') . $a->config['sitename'],
309 $email_tpl,'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
312 notice( t('Your registration is pending approval by the site owner.') . EOL ) ;
313 goaway($a->get_baseurl());
325 if(! function_exists('register_content')) {
326 function register_content(&$a) {
328 // logged in users can register others (people/pages/groups)
329 // even with closed registrations, unless specifically prohibited by site policy.
330 // 'block_extended_register' blocks all registrations, period.
332 $block = get_config('system','block_extended_register');
334 if((($a->config['register_policy'] == REGISTER_CLOSED) && (! getuid())) || ($block)) {
335 notice("Permission denied." . EOL);
339 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
340 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
341 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
342 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
343 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
345 $noid = get_config('system','no_openid');
354 $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" >';
355 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
356 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
357 $oidlabel = t("Your OpenID \x28optional\x29: ");
360 $license = t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.');
363 $o = load_view_file("view/register.tpl");
364 $o = replace_macros($o, array(
365 '$oidhtml' => $oidhtml,
366 '$regtitle' => t('Registration'),
367 '$registertext' =>((x($a->config,'register_text'))
368 ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
370 '$fillwith' => $fillwith,
371 '$fillext' => $fillext,
372 '$oidlabel' => $oidlabel,
373 '$openid' => $openid_url,
374 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
375 '$addrlabel' => t('Your Email Address: '),
376 '$nickdesc' => t('Choose a profile nickname. This must begin with a text character. Your global profile locator will then be \'<strong>nickname@$sitename</strong>\'.'),
377 '$nicklabel' => t('Choose a nickname: '),
379 '$regbutt' => t('Register'),
380 '$username' => $username,
382 '$nickname' => $nickname,
383 '$license' => $license,
384 '$sitename' => $a->get_hostname()