2 // Note: this script uses an undocumented constant in config.php named
3 // REG_NOTIFY_ADDRESS - email address to send registration notifications to.
5 // define('REG_NOTIFY_ADDRESS', 'my-address@domain.dom');
7 error_reporting(E_ERROR | E_WARNING | E_PARSE
);
9 $action = $_REQUEST["action"];
11 define('MAX_USERS', 55);
13 require_once "sessions.php";
15 require_once "sanity_check.php";
16 require_once "functions.php";
17 require_once "config.php";
18 require_once "db.php";
20 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
22 init_connection($link);
24 /* Remove users which didn't login after receiving their registration information */
26 if (DB_TYPE
== "pgsql") {
27 db_query($link, "DELETE FROM ttrss_users WHERE last_login IS NULL
28 AND created < NOW() - INTERVAL '1 day' AND access_level = 0");
30 db_query($link, "DELETE FROM ttrss_users WHERE last_login IS NULL
31 AND created < DATE_SUB(NOW(), INTERVAL 1 DAY) AND access_level = 0");
34 if ($action == "check") {
35 header("Content-Type: application/xml");
37 $login = trim(db_escape_string($_REQUEST['login']));
39 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
40 LOWER(login) = LOWER('$login')");
42 $is_registered = db_num_rows($result) > 0;
46 printf("%d", $is_registered);
56 <title
>Create
new account
</title
>
57 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
58 <link rel
="stylesheet" type
="text/css" href
="utility.css">
59 <script type
="text/javascript" src
="functions.js"></script
>
60 <script type
="text/javascript" src
="prototype.js"></script
>
61 <script type
="text/javascript" src
="scriptaculous/scriptaculous.js?load=effects,dragdrop,controls"></script
>
64 <script type
="text/javascript">
66 function checkUsername() {
69 var f
= document
.forms
['register_form'];
70 var login
= f
.login
.value
;
73 new Effect
.Highlight(f
.login
);
74 f
.sub_btn
.disabled
= true;
78 var query
= "register.php?action=check&login=" +
81 new Ajax
.Request(query
, {
82 onComplete
: function(transport
) {
86 var reply
= transport
.responseXML
;
88 var result
= reply
.getElementsByTagName('result')[0];
89 var result_code
= result
.firstChild
.nodeValue
;
91 if (result_code
== 0) {
92 new Effect
.Highlight(f
.login
, {startcolor
: '#00ff00'});
93 f
.sub_btn
.disabled
= false;
95 new Effect
.Highlight(f
.login
, {startcolor
: '#ff0000'});
96 f
.sub_btn
.disabled
= true;
99 exception_error("checkUsername_callback", e
);
105 exception_error("checkUsername", e
);
112 function validateRegForm() {
115 var f
= document
.forms
['register_form'];
117 if (f
.login
.value
.length
== 0) {
118 new Effect
.Highlight(f
.login
);
122 if (f
.email
.value
.length
== 0) {
123 new Effect
.Highlight(f
.email
);
127 if (f
.turing_test
.value
.length
== 0) {
128 new Effect
.Highlight(f
.turing_test
);
135 exception_error("validateRegForm", e
);
144 <div
class="floatingLogo"><img src
="images/ttrss_logo.png"></div
>
146 <h1
><?php
echo __("Create new account") ?
></h1
>
149 if (!ENABLE_REGISTRATION
) {
150 print_error(__("New user registrations are administratively disabled."));
152 print "<p><form method=\"GET\" action=\"logout.php\">
153 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
159 <!-- If you have any rules
or ToS you
'd like to display, enter them here -->
162 <?php if (REG_MAX_USERS > 0) {
163 $result = db_query($link, "SELECT COUNT(*) AS cu FROM ttrss_users");
164 $num_users = db_fetch_result($result, 0, "cu");
167 <? if (!REG_MAX_USERS || $num_users < REG_MAX_USERS) { ?>
169 <? if (!$action) { ?>
171 <p><?php echo __('Your temporary password will be sent to the specified email
. Accounts
, which were not logged in once
, are erased automatically
24 hours after temporary password is sent
.') ?></p>
173 <form action="register.php" method="POST" name="register_form">
174 <input type="hidden" name="action" value="do_register">
177 <td><?php echo __('Desired login
:') ?></td><td>
180 <input type="submit" value="<?php echo __('Check availability
') ?>" onclick='return checkUsername()'>
182 <td><?php echo __('Email
:') ?></td><td>
185 <td><?php echo __('How much is two plus two
:') ?></td><td>
186 <input name="turing_test"></td></tr>
187 <tr><td colspan="2" align="right">
188 <input type="submit" name="sub_btn" value="<?php echo __('Submit registration
"') ?>"
189 disabled
="true" onclick
='return validateRegForm()'>
194 <?
} else if ($action == "do_register") { ?
>
196 <p
><?php
echo __('Processing registration...') ?
></p
>
199 $login = mb_strtolower(trim(db_escape_string($_REQUEST["login"])));
200 $email = trim(db_escape_string($_REQUEST["email"]));
201 $test = trim(db_escape_string($_REQUEST["turing_test"]));
203 if (!$login ||
!$email ||
!$test) {
204 print "<div class='error'>Please fill in the form.</div>";
205 print "<p><a href='register.php'>Return to registration form</a></p>";
209 if ($test == "four" ||
$test == "4") {
211 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
214 $is_registered = db_num_rows($result) > 0;
216 if ($is_registered) {
217 print_error(__('Sorry, this username is already taken.'));
218 print "<p><form method=\"GET\" action=\"tt-rss.php\">
219 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
223 $password = make_password();
225 $pwd_hash = encrypt_password($password, $login);
227 db_query($link, "INSERT INTO ttrss_users
228 (login,pwd_hash,access_level,last_login, email, created)
229 VALUES ('$login', '$pwd_hash', 0, null, '$email', NOW())");
231 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
232 login = '$login' AND pwd_hash = '$pwd_hash'");
234 if (db_num_rows($result) != 1) {
235 print_error(__('Registration failed.'));
236 print "<p><form method=\"GET\" action=\"tt-rss.php\">
237 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
241 $new_uid = db_fetch_result($result, 0, "id");
243 initialize_user($link, $new_uid);
247 "You are receiving this message, because you (or somebody else) have opened\n".
248 "an account at Tiny Tiny RSS.\n".
250 "Your login information is as follows:\n".
253 "Password: $password\n".
255 "Don't forget to login at least once to your new account, otherwise\n".
256 "it will be deleted in 24 hours.\n".
258 "If that wasn't you, just ignore this message. Thanks.";
260 $mail = new PHPMailer();
262 $mail->PluginDir
= "phpmailer/";
263 $mail->SetLanguage("en", "phpmailer/language/");
265 $mail->CharSet
= "UTF-8";
267 $mail->From
= DIGEST_FROM_ADDRESS
;
268 $mail->FromName
= DIGEST_FROM_NAME
;
269 $mail->AddAddress($email);
271 if (DIGEST_SMTP_HOST
) {
272 $mail->Host
= DIGEST_SMTP_HOST
;
273 $mail->Mailer
= "smtp";
274 $mail->Username
= DIGEST_SMTP_LOGIN
;
275 $mail->Password
= DIGEST_SMTP_PASSWORD
;
278 // $mail->IsHTML(true);
279 $mail->Subject
= "Registration information for Tiny Tiny RSS";
280 $mail->Body
= $reg_text;
281 // $mail->AltBody = $digest_text;
285 if (!$rc) print_error($mail->ErrorInfo
);
289 "New user had registered at your Tiny Tiny RSS installation.\n".
294 $mail = new PHPMailer();
296 $mail->PluginDir
= "phpmailer/";
297 $mail->SetLanguage("en", "phpmailer/language/");
299 $mail->CharSet
= "UTF-8";
301 $mail->From
= DIGEST_FROM_ADDRESS
;
302 $mail->FromName
= DIGEST_FROM_NAME
;
303 $mail->AddAddress(REG_NOTIFY_ADDRESS
);
305 if (DIGEST_SMTP_HOST
) {
306 $mail->Host
= DIGEST_SMTP_HOST
;
307 $mail->Mailer
= "smtp";
308 $mail->Username
= DIGEST_SMTP_LOGIN
;
309 $mail->Password
= DIGEST_SMTP_PASSWORD
;
312 // $mail->IsHTML(true);
313 $mail->Subject
= "Registration notice for Tiny Tiny RSS";
314 $mail->Body
= $reg_text;
315 // $mail->AltBody = $digest_text;
319 print_notice(__("Account created successfully."));
321 print "<p><form method=\"GET\" action=\"tt-rss.php\">
322 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
330 print_error('Plese check the form again, you have failed the robot test.');
331 print "<p><form method=\"GET\" action=\"tt-rss.php\">
332 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
341 <?php
print_notice(__('New user registrations are currently closed.')) ?
>
343 <?php
print "<p><form method=\"GET\" action=\"tt-rss.php\">
344 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">