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 );
33 if(x($_POST,'username'))
34 $username = notags(trim($_POST['username']));
35 if(x($_POST['nickname']))
36 $nickname = notags(trim($_POST['nickname']));
38 $email = notags(trim($_POST['email']));
39 if(x($_POST,'openid_url'))
40 $openid_url = notags(trim($_POST['openid_url']));
42 $photo = ((x($_POST,'photo')) ? notags(trim($_POST['photo'])) : '');
45 if((! x($username)) || (! x($email)) || (! x($nickname))) {
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 $no_utf = get_config('system','no_utf');
76 $pat = (($no_utf) ? '/^[a-zA-Z]* [a-zA-Z]*$/' : '/^\p{L}* \p{L}*$/u' );
78 $loose_reg = get_config('system','no_regfullname');
80 if((! $loose_reg) && (! preg_match($pat,$username)))
81 $err .= t('That doesn\'t appear to be your full name.') . EOL;
83 if(! allowed_email($email))
84 $err .= t('Your email domain is not among those allowed on this site.') . EOL;
86 if((! valid_email($email)) || (! validate_email($email)))
87 $err .= t('Not a valid email address.') . EOL;
89 $nickname = $_POST['nickname'] = strtolower($nickname);
91 if(! preg_match("/^[a-z][a-z0-9\-\_]*$/",$nickname))
92 $err .= t('Your "nickname" can only contain "a-z", "0-9", "-", and "_", and must also begin with a letter.') . EOL;
93 $r = q("SELECT `uid` FROM `user`
94 WHERE `nickname` = '%s' LIMIT 1",
98 $err .= t('Nickname is already registered. Please choose another.') . EOL;
106 $new_password = autoname(6) . mt_rand(100,9999);
107 $new_password_encoded = hash('whirlpool',$new_password);
109 $res=openssl_pkey_new(array(
110 'digest_alg' => 'sha1',
111 'private_key_bits' => 4096,
112 'encrypt_key' => false ));
117 notice( t('SERIOUS ERROR: Generation of security keys failed.') . EOL);
123 openssl_pkey_export($res, $prvkey);
127 $pkey = openssl_pkey_get_details($res);
128 $pubkey = $pkey["key"];
130 $sres=openssl_pkey_new(array(
131 'encrypt_key' => false ));
137 openssl_pkey_export($sres, $sprvkey);
141 $spkey = openssl_pkey_get_details($sres);
142 $spubkey = $spkey["key"];
144 $r = q("INSERT INTO `user` ( `username`, `password`, `email`, `openid`, `nickname`,
145 `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `verified`, `blocked` )
146 VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
148 dbesc($new_password_encoded),
161 $r = q("SELECT `uid` FROM `user`
162 WHERE `username` = '%s' AND `password` = '%s' LIMIT 1",
164 dbesc($new_password_encoded)
166 if($r !== false && count($r))
167 $newuid = intval($r[0]['uid']);
170 notice( t('An error occurred during registration. Please try again.') . EOL );
174 if(x($newuid) !== false) {
175 $r = q("INSERT INTO `profile` ( `uid`, `profile-name`, `is-default`, `name`, `photo`, `thumb` )
176 VALUES ( %d, '%s', %d, '%s', '%s', '%s' ) ",
181 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
182 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg")
186 notice( t('An error occurred creating your default profile. Please try again.') . EOL );
187 // Start fresh next time.
188 $r = q("DELETE FROM `user` WHERE `uid` = %d",
192 $r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`,
193 `request`, `notify`, `poll`, `confirm`, `name-date`, `uri-date`, `avatar-date` )
194 VALUES ( %d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
199 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
200 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg"),
201 dbesc($a->get_baseurl() . "/photo/micro/{$newuid}.jpg"),
202 dbesc($a->get_baseurl() . "/profile/$nickname"),
203 dbesc($a->get_baseurl() . "/dfrn_request/$nickname"),
204 dbesc($a->get_baseurl() . "/dfrn_notify/$nickname"),
205 dbesc($a->get_baseurl() . "/dfrn_poll/$nickname"),
206 dbesc($a->get_baseurl() . "/dfrn_confirm/$nickname"),
207 dbesc(datetime_convert()),
208 dbesc(datetime_convert()),
209 dbesc(datetime_convert())
215 $use_gravatar = ((get_config('system','no_gravatar')) ? false : true);
217 // if we have an openid photo use it.
218 // otherwise unless it is disabled, use gravatar
220 if($use_gravatar || strlen($photo)) {
222 require_once('include/Photo.php');
224 if(($use_gravatar) && (! strlen($photo)))
225 $photo = gravatar_img($email);
226 $photo_failure = false;
228 $filename = basename($photo);
229 $img_str = fetch_url($photo,true);
230 $img = new Photo($img_str);
231 if($img->is_valid()) {
233 $img->scaleImageSquare(175);
235 $hash = photo_new_resource();
237 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4 );
240 $photo_failure = true;
242 $img->scaleImage(80);
244 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5 );
247 $photo_failure = true;
249 $img->scaleImage(48);
251 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6 );
254 $photo_failure = true;
256 if(! $photo_failure) {
257 q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ",
264 if( $a->config['register_policy'] == REGISTER_OPEN ) {
265 $email_tpl = load_view_file("view/register_open_eml.tpl");
266 $email_tpl = replace_macros($email_tpl, array(
267 '$sitename' => $a->config['sitename'],
268 '$siteurl' => $a->get_baseurl(),
269 '$username' => $username,
271 '$password' => $new_password,
272 '$uid' => $newuid ));
274 $res = mail($email, t('Registration details for ') . $a->config['sitename'],
275 $email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
279 notice( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
280 goaway($a->get_baseurl());
283 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
286 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
287 if(! strlen($a->config['admin_email'])) {
288 notice( t('Your registration can not be processed.') . EOL);
289 goaway($a->get_baseurl());
292 $hash = random_string();
293 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password` ) VALUES ( '%s', '%s', %d, '%s' ) ",
295 dbesc(datetime_convert()),
300 $email_tpl = load_view_file("view/register_verify_eml.tpl");
301 $email_tpl = replace_macros($email_tpl, array(
302 '$sitename' => $a->config['sitename'],
303 '$siteurl' => $a->get_baseurl(),
304 '$username' => $username,
306 '$password' => $new_password,
311 $res = mail($a->config['admin_email'], t('Registration request at ') . $a->config['sitename'],
312 $email_tpl,'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
315 notice( t('Your registration is pending approval by the site owner.') . EOL ) ;
316 goaway($a->get_baseurl());
328 if(! function_exists('register_content')) {
329 function register_content(&$a) {
331 // logged in users can register others (people/pages/groups)
332 // even with closed registrations, unless specifically prohibited by site policy.
333 // 'block_extended_register' blocks all registrations, period.
335 $block = get_config('system','block_extended_register');
337 if((($a->config['register_policy'] == REGISTER_CLOSED) && (! getuid())) || ($block)) {
338 notice("Permission denied." . EOL);
342 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
343 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
344 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
345 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
346 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
348 $o = load_view_file("view/register.tpl");
349 $o = replace_macros($o, array(
350 '$regtitle' => t('Registration'),
351 '$registertext' =>((x($a->config,'register_text'))
352 ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
354 '$fillwith' => t('You may ' . "\x28" . 'optionally' . "\x29" . ' fill in this form via OpenID by supplying your OpenID and clicking ') . "'" . t('Register') . "'",
355 '$fillext' => t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.'),
356 '$oidlabel' => t('Your OpenID ' . "\x28" . 'optional' . "\x29" . ': '),
357 '$openid' => $openid_url,
358 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
359 '$addrlabel' => t('Your Email Address: '),
360 '$nickdesc' => t('Choose a profile nickname. This must begin with a text character. Your global profile locator will then be \'<strong>nickname@$sitename</strong>\'.'),
361 '$nicklabel' => t('Choose a nickname: '),
363 '$regbutt' => t('Register'),
364 '$username' => $username,
366 '$nickname' => $nickname,
367 '$sitename' => $a->get_hostname()