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 );
47 // TODO fix some of these regex's for int'l/utf-8.
49 if(! valid_email($email))
50 $err .= t(' Not a valid email address.');
51 if(strlen($username) > 48)
52 $err .= t(' Please use a shorter name.');
53 if(strlen($username) < 3)
54 $err .= t(' Name too short.');
56 // I don't really like having this rule, but it cuts down
57 // on the number of auto-registrations by Russian spammers
59 $no_utf = get_config('system','no_utf');
61 $pat = (($no_utf) ? '/^[a-zA-Z]* [a-zA-Z]*$/' : '/^\p{L}* \p{L}*$/u' );
63 $loose_reg = get_config('system','no_regfullname');
65 if((! $loose_reg) && (! preg_match($pat,$username)))
66 $err .= t(' That doesn\'t appear to be your full name.');
68 if(! allowed_email($email))
69 $err .= t(' Your email domain is not among those allowed on this site.');
71 $nickname = strtolower($nickname);
72 if(! preg_match("/^[a-z][a-z0-9\-\_]*$/",$nickname))
73 $err .= t(' Your "nickname" can only contain "a-z", "0-9", "-", and "_", and must also begin with a letter.');
74 $r = q("SELECT `uid` FROM `user`
75 WHERE `nickname` = '%s' LIMIT 1",
79 $err .= t(' Nickname is already registered. Please choose another.');
87 $new_password = autoname(6) . mt_rand(100,9999);
88 $new_password_encoded = hash('whirlpool',$new_password);
90 $res=openssl_pkey_new(array(
91 'digest_alg' => 'whirlpool',
92 'private_key_bits' => 4096,
93 'encrypt_key' => false ));
99 openssl_pkey_export($res, $prvkey);
103 $pkey = openssl_pkey_get_details($res);
104 $pubkey = $pkey["key"];
106 $sres=openssl_pkey_new(array(
107 'encrypt_key' => false ));
113 openssl_pkey_export($sres, $sprvkey);
117 $spkey = openssl_pkey_get_details($sres);
118 $spubkey = $spkey["key"];
120 $r = q("INSERT INTO `user` ( `username`, `password`, `email`, `nickname`,
121 `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `verified`, `blocked` )
122 VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
124 dbesc($new_password_encoded),
136 $r = q("SELECT `uid` FROM `user`
137 WHERE `username` = '%s' AND `password` = '%s' LIMIT 1",
139 dbesc($new_password_encoded)
141 if($r !== false && count($r))
142 $newuid = intval($r[0]['uid']);
145 notice( t('An error occurred during registration. Please try again.') . EOL );
149 if(x($newuid) !== false) {
150 $r = q("INSERT INTO `profile` ( `uid`, `profile-name`, `is-default`, `name`, `photo`, `thumb` )
151 VALUES ( %d, '%s', %d, '%s', '%s', '%s' ) ",
156 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
157 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg")
161 notice( t('An error occurred creating your default profile. Please try again.') . EOL );
162 // Start fresh next time.
163 $r = q("DELETE FROM `user` WHERE `uid` = %d",
167 $r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`,
168 `request`, `notify`, `poll`, `confirm`, `name-date`, `uri-date`, `avatar-date` )
169 VALUES ( %d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
174 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
175 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg"),
176 dbesc($a->get_baseurl() . "/photo/micro/{$newuid}.jpg"),
177 dbesc($a->get_baseurl() . "/profile/$nickname"),
178 dbesc($a->get_baseurl() . "/dfrn_request/$nickname"),
179 dbesc($a->get_baseurl() . "/dfrn_notify/$nickname"),
180 dbesc($a->get_baseurl() . "/dfrn_poll/$nickname"),
181 dbesc($a->get_baseurl() . "/dfrn_confirm/$nickname"),
182 dbesc(datetime_convert()),
183 dbesc(datetime_convert()),
184 dbesc(datetime_convert())
190 require_once('include/Photo.php');
192 $photo = gravatar_img($email);
193 $photo_failure = false;
195 $filename = basename($photo);
196 $img_str = fetch_url($photo,true);
197 $img = new Photo($img_str);
198 if($img->is_valid()) {
200 $img->scaleImageSquare(175);
202 $hash = photo_new_resource();
204 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4 );
207 $photo_failure = true;
209 $img->scaleImage(80);
211 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5 );
214 $photo_failure = true;
216 $img->scaleImage(48);
218 $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6 );
221 $photo_failure = true;
223 if(! $photo_failure) {
224 q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ",
230 if( $a->config['register_policy'] == REGISTER_OPEN ) {
231 $email_tpl = load_view_file("view/register_open_eml.tpl");
232 $email_tpl = replace_macros($email_tpl, array(
233 '$sitename' => $a->config['sitename'],
234 '$siteurl' => $a->get_baseurl(),
235 '$username' => $username,
237 '$password' => $new_password,
238 '$uid' => $newuid ));
240 $res = mail($email, t('Registration details for ') . $a->config['sitename'],
241 $email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
245 notice( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
246 goaway($a->get_baseurl());
249 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
252 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
253 if(! strlen($a->config['admin_email'])) {
254 notice( t('Your registration can not be processed.') . EOL);
255 goaway($a->get_baseurl());
258 $hash = random_string();
259 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password` ) VALUES ( '%s', '%s', %d, '%s' ) ",
261 dbesc(datetime_convert()),
266 $email_tpl = load_view_file("view/register_verify_eml.tpl");
267 $email_tpl = replace_macros($email_tpl, array(
268 '$sitename' => $a->config['sitename'],
269 '$siteurl' => $a->get_baseurl(),
270 '$username' => $username,
272 '$password' => $new_password,
277 $res = mail($a->config['admin_email'], t('Registration request at ') . $a->config['sitename'],
278 $email_tpl,'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME']);
281 notice( t('Your registration is pending approval by the site owner.') . EOL ) ;
282 goaway($a->get_baseurl());
295 if(! function_exists('register_content')) {
296 function register_content(&$a) {
298 // logged in users can register others (people/pages/groups)
299 // even with closed registrations, unless specifically prohibited by site policy.
300 // 'block_extended_register' blocks all registrations, period.
302 $block = get_config('system','block_extended_register');
304 if((($a->config['register_policy'] == REGISTER_CLOSED) && (! getuid())) || ($block)) {
305 notice("Permission denied." . EOL);
309 $o = load_view_file("view/register.tpl");
310 $o = replace_macros($o, array(
311 '$registertext' =>((x($a->config,'register_text'))
312 ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
314 '$sitename' => $a->get_hostname()