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(!eregi('[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,6}',$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 if(! preg_match("/^[a-zA-Z]* [a-zA-Z]*$/",$username))
60 $err .= t(' That doesn\'t appear to be your full name.');
63 $r = q("SELECT `uid` FROM `user`
64 WHERE `email` = '%s' LIMIT 1",
68 if($r !== false && count($r))
69 $err .= t(' Your email address is already registered on this system.') ;
71 if(! preg_match("/^[a-zA-Z][a-zA-Z0-9\-\_]*$/",$nickname))
72 $err .= t(' Nickname <strong>must</strong> start with a letter and contain only letters, numbers, dashes, or underscore.') ;
73 $r = q("SELECT `uid` FROM `user`
74 WHERE `nickname` = '%s' LIMIT 1",
78 $err .= t(' Nickname is already registered. Please choose another.');
86 $new_password = autoname(6) . mt_rand(100,9999);
87 $new_password_encoded = hash('whirlpool',$new_password);
89 $res=openssl_pkey_new(array(
90 'digest_alg' => 'whirlpool',
91 'private_key_bits' => 4096,
92 'encrypt_key' => false ));
98 openssl_pkey_export($res, $prvkey);
102 $pkey = openssl_pkey_get_details($res);
103 $pubkey = $pkey["key"];
105 $r = q("INSERT INTO `user` ( `username`, `password`, `email`, `nickname`,
106 `pubkey`, `prvkey`, `verified`, `blocked` )
107 VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
109 dbesc($new_password_encoded),
119 $r = q("SELECT `uid` FROM `user`
120 WHERE `username` = '%s' AND `password` = '%s' LIMIT 1",
122 dbesc($new_password_encoded)
124 if($r !== false && count($r))
125 $newuid = intval($r[0]['uid']);
128 notice( t('An error occurred during registration. Please try again.') . EOL );
132 if(x($newuid) !== false) {
133 $r = q("INSERT INTO `profile` ( `uid`, `profile-name`, `is-default`, `name`, `photo`, `thumb` )
134 VALUES ( %d, '%s', %d, '%s', '%s', '%s' ) ",
139 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
140 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg")
144 notice( t('An error occurred creating your default profile. Please try again.') . EOL );
145 // Start fresh next time.
146 $r = q("DELETE FROM `user` WHERE `uid` = %d",
150 $r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `photo`, `thumb`, `blocked`, `pending`, `url`,
151 `request`, `notify`, `poll`, `confirm`, `name-date`, `uri-date`, `avatar-date` )
152 VALUES ( %d, '%s', 1, '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
156 dbesc($a->get_baseurl() . "/photo/profile/{$newuid}.jpg"),
157 dbesc($a->get_baseurl() . "/photo/avatar/{$newuid}.jpg"),
158 dbesc($a->get_baseurl() . "/profile/$nickname"),
159 dbesc($a->get_baseurl() . "/dfrn_request/$nickname"),
160 dbesc($a->get_baseurl() . "/dfrn_notify/$nickname"),
161 dbesc($a->get_baseurl() . "/dfrn_poll/$nickname"),
162 dbesc($a->get_baseurl() . "/dfrn_confirm/$nickname"),
163 dbesc(datetime_convert()),
164 dbesc(datetime_convert()),
165 dbesc(datetime_convert())
171 if( $a->config['register_policy'] == REGISTER_OPEN ) {
172 $email_tpl = file_get_contents("view/register_open_eml.tpl");
173 $email_tpl = replace_macros($email_tpl, array(
174 '$sitename' => $a->config['sitename'],
175 '$siteurl' => $a->get_baseurl(),
176 '$username' => $username,
178 '$password' => $new_password,
179 '$uid' => $newuid ));
181 $res = mail($email, t('Registration details for ') . $a->config['sitename'],
182 $email_tpl, 'From: ' . t('Administrator@') . $_SERVER[SERVER_NAME]);
186 notice( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
187 goaway($a->get_baseurl());
190 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
193 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
194 if(! strlen($a->config['admin_email'])) {
195 notice( t('Your registration can not be processed.') . EOL);
196 goaway($a->get_baseurl());
199 $hash = random_string();
200 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password` ) VALUES ( '%s', '%s', %d, '%s' ) ",
202 dbesc(datetime_convert()),
207 $email_tpl = file_get_contents("view/register_verify_eml.tpl");
208 $email_tpl = replace_macros($email_tpl, array(
209 '$sitename' => $a->config['sitename'],
210 '$siteurl' => $a->get_baseurl(),
211 '$username' => $username,
213 '$password' => $new_password,
218 $res = mail($a->config['admin_email'], t('Registration request at ') . $a->config['sitename'],
219 $email_tpl,'From: ' . t('Administrator@') . $_SERVER[SERVER_NAME]);
222 notice( t('Your registration is pending approval by the site owner.') . EOL ) ;
223 goaway($a->get_baseurl());
236 if(! function_exists('register_content')) {
237 function register_content(&$a) {
239 if($a->config['register_policy'] == REGISTER_CLOSED) {
240 notice("Permission denied." . EOL);
244 $o = file_get_contents("view/register.tpl");
245 $o = replace_macros($o, array(
246 '$registertext' =>((x($a->config,'register_text'))
247 ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
249 '$sitename' => $a->get_hostname()