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']));
40 if((! x($username)) || (! x($email)) || (! x($nickname))) {
41 notice( t('Please enter the required information.') . EOL );
48 if(strlen($username) > 48)
49 $err .= t('Please use a shorter name.') . EOL;
50 if(strlen($username) < 3)
51 $err .= t('Name too short.') . EOL;
53 // I don't really like having this rule, but it cuts down
54 // on the number of auto-registrations by Russian spammers
56 $no_utf = get_config('system','no_utf');
58 $pat = (($no_utf) ? '/^[a-zA-Z]* [a-zA-Z]*$/' : '/^\p{L}* \p{L}*$/u' );
60 $loose_reg = get_config('system','no_regfullname');
62 if((! $loose_reg) && (! preg_match($pat,$username)))
63 $err .= t('That doesn\'t appear to be your full name.') . EOL;
65 if(! allowed_email($email))
66 $err .= t('Your email domain is not among those allowed on this site.') . EOL;
68 if((! valid_email($email)) || (! validate_email($email)))
69 $err .= t('Not a valid email address.') . EOL;
71 $nickname = $_POST['nickname'] = strtolower($nickname);
73 if(! preg_match("/^[a-z][a-z0-9\-\_]*$/",$nickname))
74 $err .= t('Your "nickname" can only contain "a-z", "0-9", "-", and "_", and must also begin with a letter.') . EOL;
75 $r = q("SELECT `uid` FROM `user`
76 WHERE `nickname` = '%s' LIMIT 1",
80 $err .= t('Nickname is already registered. Please choose another.') . EOL;
88 $new_password = autoname(6) . mt_rand(100,9999);
89 $new_password_encoded = hash('whirlpool',$new_password);
91 $res=openssl_pkey_new(array(
92 'digest_alg' => 'whirlpool',
93 'private_key_bits' => 4096,
94 'encrypt_key' => false ));
100 openssl_pkey_export($res, $prvkey);
104 $pkey = openssl_pkey_get_details($res);
105 $pubkey = $pkey["key"];
107 $sres=openssl_pkey_new(array(
108 'encrypt_key' => false ));
114 openssl_pkey_export($sres, $sprvkey);
118 $spkey = openssl_pkey_get_details($sres);
119 $spubkey = $spkey["key"];
121 $r = q("INSERT INTO `user` ( `username`, `password`, `email`, `nickname`,
122 `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `verified`, `blocked` )
123 VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
125 dbesc($new_password_encoded),
137 $r = q("SELECT `uid` FROM `user`
138 WHERE `username` = '%s' AND `password` = '%s' LIMIT 1",
140 dbesc($new_password_encoded)
142 if($r !== false && count($r))
143 $newuid = intval($r[0]['uid']);
146 notice( t('An error occurred during registration. Please try again.') . EOL );
150 if(x($newuid) !== false) {
151 $r = q("INSERT INTO `profile` ( `uid`, `profile-name`, `is-default`, `name`, `photo`, `thumb` )
152 VALUES ( %d, '%s', %d, '%s', '%s', '%s' ) ",
157 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
158 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg")
162 notice( t('An error occurred creating your default profile. Please try again.') . EOL );
163 // Start fresh next time.
164 $r = q("DELETE FROM `user` WHERE `uid` = %d",
168 $r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`,
169 `request`, `notify`, `poll`, `confirm`, `name-date`, `uri-date`, `avatar-date` )
170 VALUES ( %d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
175 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
176 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg"),
177 dbesc($a->get_baseurl() . "/photo/micro/{$newuid}.jpg"),
178 dbesc($a->get_baseurl() . "/profile/$nickname"),
179 dbesc($a->get_baseurl() . "/dfrn_request/$nickname"),
180 dbesc($a->get_baseurl() . "/dfrn_notify/$nickname"),
181 dbesc($a->get_baseurl() . "/dfrn_poll/$nickname"),
182 dbesc($a->get_baseurl() . "/dfrn_confirm/$nickname"),
183 dbesc(datetime_convert()),
184 dbesc(datetime_convert()),
185 dbesc(datetime_convert())
191 require_once('include/Photo.php');
193 $photo = gravatar_img($email);
194 $photo_failure = false;
196 $filename = basename($photo);
197 $img_str = fetch_url($photo,true);
198 $img = new Photo($img_str);
199 if($img->is_valid()) {
201 $img->scaleImageSquare(175);
203 $hash = photo_new_resource();
205 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4 );
208 $photo_failure = true;
210 $img->scaleImage(80);
212 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5 );
215 $photo_failure = true;
217 $img->scaleImage(48);
219 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6 );
222 $photo_failure = true;
224 if(! $photo_failure) {
225 q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ",
231 if( $a->config['register_policy'] == REGISTER_OPEN ) {
232 $email_tpl = load_view_file("view/register_open_eml.tpl");
233 $email_tpl = replace_macros($email_tpl, array(
234 '$sitename' => $a->config['sitename'],
235 '$siteurl' => $a->get_baseurl(),
236 '$username' => $username,
238 '$password' => $new_password,
239 '$uid' => $newuid ));
241 $res = mail($email, t('Registration details for ') . $a->config['sitename'],
242 $email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
246 notice( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
247 goaway($a->get_baseurl());
250 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
253 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
254 if(! strlen($a->config['admin_email'])) {
255 notice( t('Your registration can not be processed.') . EOL);
256 goaway($a->get_baseurl());
259 $hash = random_string();
260 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password` ) VALUES ( '%s', '%s', %d, '%s' ) ",
262 dbesc(datetime_convert()),
267 $email_tpl = load_view_file("view/register_verify_eml.tpl");
268 $email_tpl = replace_macros($email_tpl, array(
269 '$sitename' => $a->config['sitename'],
270 '$siteurl' => $a->get_baseurl(),
271 '$username' => $username,
273 '$password' => $new_password,
278 $res = mail($a->config['admin_email'], t('Registration request at ') . $a->config['sitename'],
279 $email_tpl,'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
282 notice( t('Your registration is pending approval by the site owner.') . EOL ) ;
283 goaway($a->get_baseurl());
296 if(! function_exists('register_content')) {
297 function register_content(&$a) {
299 // logged in users can register others (people/pages/groups)
300 // even with closed registrations, unless specifically prohibited by site policy.
301 // 'block_extended_register' blocks all registrations, period.
303 $block = get_config('system','block_extended_register');
305 if((($a->config['register_policy'] == REGISTER_CLOSED) && (! getuid())) || ($block)) {
306 notice("Permission denied." . EOL);
310 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
311 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
312 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
314 $o = load_view_file("view/register.tpl");
315 $o = replace_macros($o, array(
316 '$regtitle' => t('Registration'),
317 '$registertext' =>((x($a->config,'register_text'))
318 ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
320 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
321 '$addrlabel' => t('Your Email Address: '),
322 '$nickdesc' => t('Choose a profile nickname. This must begin with a text character. Your global profile locator will then be \'<strong>nickname@$sitename</strong>\'.'),
323 '$nicklabel' => t('Choose a nickname: '),
324 '$regbutt' => t('Register'),
325 '$username' => $username,
327 '$nickname' => $nickname,
328 '$sitename' => $a->get_hostname()