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']));
43 if((! x($username)) || (! x($email)) || (! x($nickname))) {
45 $_SESSION['register'] = 1;
46 $_SESSION['openid'] = $openid_url;
47 require_once('library/openid.php');
48 $openid = new LightOpenID;
49 $openid->identity = $openid_url;
50 $openid->returnUrl = $a->get_baseurl() . '/openid';
51 $openid->required = array('namePerson/friendly', 'contact/email', 'namePerson');
52 $openid->optional = array('namePerson/first');
53 goaway($openid->authUrl());
57 notice( t('Please enter the required information.') . EOL );
64 if(strlen($username) > 48)
65 $err .= t('Please use a shorter name.') . EOL;
66 if(strlen($username) < 3)
67 $err .= t('Name too short.') . EOL;
69 // I don't really like having this rule, but it cuts down
70 // on the number of auto-registrations by Russian spammers
72 $no_utf = get_config('system','no_utf');
74 $pat = (($no_utf) ? '/^[a-zA-Z]* [a-zA-Z]*$/' : '/^\p{L}* \p{L}*$/u' );
76 $loose_reg = get_config('system','no_regfullname');
78 if((! $loose_reg) && (! preg_match($pat,$username)))
79 $err .= t('That doesn\'t appear to be your full name.') . EOL;
81 if(! allowed_email($email))
82 $err .= t('Your email domain is not among those allowed on this site.') . EOL;
84 if((! valid_email($email)) || (! validate_email($email)))
85 $err .= t('Not a valid email address.') . EOL;
87 $nickname = $_POST['nickname'] = strtolower($nickname);
89 if(! preg_match("/^[a-z][a-z0-9\-\_]*$/",$nickname))
90 $err .= t('Your "nickname" can only contain "a-z", "0-9", "-", and "_", and must also begin with a letter.') . EOL;
91 $r = q("SELECT `uid` FROM `user`
92 WHERE `nickname` = '%s' LIMIT 1",
96 $err .= t('Nickname is already registered. Please choose another.') . EOL;
104 $new_password = autoname(6) . mt_rand(100,9999);
105 $new_password_encoded = hash('whirlpool',$new_password);
107 $res=openssl_pkey_new(array(
108 'digest_alg' => 'whirlpool',
109 'private_key_bits' => 4096,
110 'encrypt_key' => false ));
116 openssl_pkey_export($res, $prvkey);
120 $pkey = openssl_pkey_get_details($res);
121 $pubkey = $pkey["key"];
123 $sres=openssl_pkey_new(array(
124 'encrypt_key' => false ));
130 openssl_pkey_export($sres, $sprvkey);
134 $spkey = openssl_pkey_get_details($sres);
135 $spubkey = $spkey["key"];
137 $r = q("INSERT INTO `user` ( `username`, `password`, `email`, `openid`, `nickname`,
138 `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `verified`, `blocked` )
139 VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
141 dbesc($new_password_encoded),
154 $r = q("SELECT `uid` FROM `user`
155 WHERE `username` = '%s' AND `password` = '%s' LIMIT 1",
157 dbesc($new_password_encoded)
159 if($r !== false && count($r))
160 $newuid = intval($r[0]['uid']);
163 notice( t('An error occurred during registration. Please try again.') . EOL );
167 if(x($newuid) !== false) {
168 $r = q("INSERT INTO `profile` ( `uid`, `profile-name`, `is-default`, `name`, `photo`, `thumb` )
169 VALUES ( %d, '%s', %d, '%s', '%s', '%s' ) ",
174 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
175 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg")
179 notice( t('An error occurred creating your default profile. Please try again.') . EOL );
180 // Start fresh next time.
181 $r = q("DELETE FROM `user` WHERE `uid` = %d",
185 $r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`,
186 `request`, `notify`, `poll`, `confirm`, `name-date`, `uri-date`, `avatar-date` )
187 VALUES ( %d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
192 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
193 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg"),
194 dbesc($a->get_baseurl() . "/photo/micro/{$newuid}.jpg"),
195 dbesc($a->get_baseurl() . "/profile/$nickname"),
196 dbesc($a->get_baseurl() . "/dfrn_request/$nickname"),
197 dbesc($a->get_baseurl() . "/dfrn_notify/$nickname"),
198 dbesc($a->get_baseurl() . "/dfrn_poll/$nickname"),
199 dbesc($a->get_baseurl() . "/dfrn_confirm/$nickname"),
200 dbesc(datetime_convert()),
201 dbesc(datetime_convert()),
202 dbesc(datetime_convert())
208 $use_gravatar = ((get_config('system','no_gravatar')) ? false : true);
211 require_once('include/Photo.php');
213 $photo = gravatar_img($email);
214 $photo_failure = false;
216 $filename = basename($photo);
217 $img_str = fetch_url($photo,true);
218 $img = new Photo($img_str);
219 if($img->is_valid()) {
221 $img->scaleImageSquare(175);
223 $hash = photo_new_resource();
225 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4 );
228 $photo_failure = true;
230 $img->scaleImage(80);
232 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5 );
235 $photo_failure = true;
237 $img->scaleImage(48);
239 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6 );
242 $photo_failure = true;
244 if(! $photo_failure) {
245 q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ",
252 if( $a->config['register_policy'] == REGISTER_OPEN ) {
253 $email_tpl = load_view_file("view/register_open_eml.tpl");
254 $email_tpl = replace_macros($email_tpl, array(
255 '$sitename' => $a->config['sitename'],
256 '$siteurl' => $a->get_baseurl(),
257 '$username' => $username,
259 '$password' => $new_password,
260 '$uid' => $newuid ));
262 $res = mail($email, t('Registration details for ') . $a->config['sitename'],
263 $email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
267 notice( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
268 goaway($a->get_baseurl());
271 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
274 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
275 if(! strlen($a->config['admin_email'])) {
276 notice( t('Your registration can not be processed.') . EOL);
277 goaway($a->get_baseurl());
280 $hash = random_string();
281 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password` ) VALUES ( '%s', '%s', %d, '%s' ) ",
283 dbesc(datetime_convert()),
288 $email_tpl = load_view_file("view/register_verify_eml.tpl");
289 $email_tpl = replace_macros($email_tpl, array(
290 '$sitename' => $a->config['sitename'],
291 '$siteurl' => $a->get_baseurl(),
292 '$username' => $username,
294 '$password' => $new_password,
299 $res = mail($a->config['admin_email'], t('Registration request at ') . $a->config['sitename'],
300 $email_tpl,'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
303 notice( t('Your registration is pending approval by the site owner.') . EOL ) ;
304 goaway($a->get_baseurl());
316 if(! function_exists('register_content')) {
317 function register_content(&$a) {
319 // logged in users can register others (people/pages/groups)
320 // even with closed registrations, unless specifically prohibited by site policy.
321 // 'block_extended_register' blocks all registrations, period.
323 $block = get_config('system','block_extended_register');
325 if((($a->config['register_policy'] == REGISTER_CLOSED) && (! getuid())) || ($block)) {
326 notice("Permission denied." . EOL);
330 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
331 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
332 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
333 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
335 $o = load_view_file("view/register.tpl");
336 $o = replace_macros($o, array(
337 '$regtitle' => t('Registration'),
338 '$registertext' =>((x($a->config,'register_text'))
339 ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
341 '$fillwith' => t('You may ' . "\x28" . 'optionally' . "\x29" . ' fill in this form via OpenID by supplying your OpenID and clicking ') . "'" . t('Register') . "'",
342 '$fillext' => t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.'),
343 '$oidlabel' => t('Your OpenID ' . "\x28" . 'optional' . "\x29" . ': '),
344 '$openid' => $openid_url,
345 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
346 '$addrlabel' => t('Your Email Address: '),
347 '$nickdesc' => t('Choose a profile nickname. This must begin with a text character. Your global profile locator will then be \'<strong>nickname@$sitename</strong>\'.'),
348 '$nicklabel' => t('Choose a nickname: '),
349 '$regbutt' => t('Register'),
350 '$username' => $username,
352 '$nickname' => $nickname,
353 '$sitename' => $a->get_hostname()