2 // This file uses two additional include files:
4 // 1) templates/register_notice.txt - displayed above the registration form
5 // 2) register_expire_do.php - contains user expiration queries when necessary
7 set_include_path(dirname(__FILE__
) ."/include" . PATH_SEPARATOR
.
10 require_once 'classes/ttrssmailer.php';
11 require_once "autoload.php";
12 require_once "functions.php";
13 require_once "sessions.php";
14 require_once "sanity_check.php";
15 require_once "config.php";
16 require_once "db.php";
20 $action = $_REQUEST["action"];
22 if (!init_plugins()) return;
24 if ($_REQUEST["format"] == "feed") {
25 header("Content-Type: text/xml");
27 print '<?xml version="1.0" encoding="utf-8"?>';
28 print "<feed xmlns=\"http://www.w3.org/2005/Atom\">
29 <id>".htmlspecialchars(SELF_URL_PATH
. "/register.php")."</id>
30 <title>Tiny Tiny RSS registration slots</title>
31 <link rel=\"self\" href=\"".htmlspecialchars(SELF_URL_PATH
. "/register.php?format=feed")."\"/>
32 <link rel=\"alternate\" href=\"".htmlspecialchars(SELF_URL_PATH
)."\"/>";
34 if (ENABLE_REGISTRATION
) {
35 $result = db_query( "SELECT COUNT(*) AS cu FROM ttrss_users");
36 $num_users = db_fetch_result($result, 0, "cu");
38 $num_users = REG_MAX_USERS
- $num_users;
39 if ($num_users < 0) $num_users = 0;
40 $reg_suffix = "enabled";
43 $reg_suffix = "disabled";
47 <id>".htmlspecialchars(SELF_URL_PATH
)."/register.php?$num_users"."</id>
48 <link rel=\"alternate\" href=\"".htmlspecialchars(SELF_URL_PATH
. "/register.php")."\"/>";
50 print "<title>$num_users slots are currently available, registration $reg_suffix</title>";
51 print "<summary>$num_users slots are currently available, registration $reg_suffix</summary>";
60 /* Remove users which didn't login after receiving their registration information */
62 if (DB_TYPE
== "pgsql") {
63 db_query( "DELETE FROM ttrss_users WHERE last_login IS NULL
64 AND created < NOW() - INTERVAL '1 day' AND access_level = 0");
66 db_query( "DELETE FROM ttrss_users WHERE last_login IS NULL
67 AND created < DATE_SUB(NOW(), INTERVAL 1 DAY) AND access_level = 0");
70 if (file_exists("register_expire_do.php")) {
71 require_once "register_expire_do.php";
74 if ($action == "check") {
75 header("Content-Type: application/xml");
77 $login = trim(db_escape_string( $_REQUEST['login']));
79 $result = db_query( "SELECT id FROM ttrss_users WHERE
80 LOWER(login) = LOWER('$login')");
82 $is_registered = db_num_rows($result) > 0;
86 printf("%d", $is_registered);
96 <title
>Create
new account
</title
>
97 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
98 <?php
echo stylesheet_tag("css/utility.css") ?
>
99 <?php
echo stylesheet_tag("css/dijit.css") ?
>
100 <?php
echo javascript_tag("js/functions.js") ?
>
101 <?php
echo javascript_tag("lib/prototype.js") ?
>
102 <?php
echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls") ?
>
105 <script type
="text/javascript">
107 function checkUsername() {
110 var f
= document
.forms
['register_form'];
111 var login
= f
.login
.value
;
114 new Effect
.Highlight(f
.login
);
115 f
.sub_btn
.disabled
= true;
119 var query
= "register.php?action=check&login=" +
122 new Ajax
.Request(query
, {
123 onComplete
: function(transport
) {
127 var reply
= transport
.responseXML
;
129 var result
= reply
.getElementsByTagName('result')[0];
130 var result_code
= result
.firstChild
.nodeValue
;
132 if (result_code
== 0) {
133 new Effect
.Highlight(f
.login
, {startcolor
: '#00ff00'});
134 f
.sub_btn
.disabled
= false;
136 new Effect
.Highlight(f
.login
, {startcolor
: '#ff0000'});
137 f
.sub_btn
.disabled
= true;
140 exception_error("checkUsername_callback", e
);
146 exception_error("checkUsername", e
);
153 function validateRegForm() {
156 var f
= document
.forms
['register_form'];
158 if (f
.login
.value
.length
== 0) {
159 new Effect
.Highlight(f
.login
);
163 if (f
.email
.value
.length
== 0) {
164 new Effect
.Highlight(f
.email
);
168 if (f
.turing_test
.value
.length
== 0) {
169 new Effect
.Highlight(f
.turing_test
);
176 exception_error("validateRegForm", e
);
185 <div
class="floatingLogo"><img src
="images/logo_small.png"></div
>
187 <h1
><?php
echo __("Create new account") ?
></h1
>
189 <div
class="content">
192 if (!ENABLE_REGISTRATION
) {
193 print_error(__("New user registrations are administratively disabled."));
195 print "<p><form method=\"GET\" action=\"backend.php\">
196 <input type=\"hidden\" name=\"op\" value=\"logout\">
197 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
203 <?php
if (REG_MAX_USERS
> 0) {
204 $result = db_query( "SELECT COUNT(*) AS cu FROM ttrss_users");
205 $num_users = db_fetch_result($result, 0, "cu");
208 <?php
if (!REG_MAX_USERS ||
$num_users < REG_MAX_USERS
) { ?
>
210 <!-- If you have any rules
or ToS you
'd like to display, enter them here -->
212 <?php if (file_exists("templates/register_notice.txt")) {
213 require_once "templates/register_notice.txt";
216 <?php if (!$action) { ?>
218 <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>
220 <form action="register.php" method="POST" name="register_form">
221 <input type="hidden" name="action" value="do_register">
224 <td><?php echo __('Desired login
:') ?></td><td>
225 <input name="login" required>
227 <input type="submit" value="<?php echo __('Check availability
') ?>" onclick='return checkUsername()'>
229 <tr><td><?php echo __('Email
:') ?></td><td>
230 <input name="email" type="email" required>
232 <tr><td><?php echo __('How much is two plus two
:') ?></td><td>
233 <input name="turing_test" required></td></tr>
234 <tr><td colspan="2" align="right">
235 <input type="submit" name="sub_btn" value="<?php echo __('Submit registration
') ?>"
236 disabled="disabled" onclick='return validateRegForm()'>
241 <?php print "<p><form method=\"GET\" action=\"index.php\">
242 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
245 <?php } else if ($action == "do_register") { ?>
248 $login = mb_strtolower(trim(db_escape_string( $_REQUEST["login"])));
249 $email = trim(db_escape_string( $_REQUEST["email"]));
250 $test = trim(db_escape_string( $_REQUEST["turing_test"]));
252 if (!$login || !$email || !$test) {
253 print_error(__("Your registration information is incomplete."));
254 print "<p><form method=\"GET\" action=\"index.php\">
255 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
260 if ($test == "four" || $test == "4") {
262 $result = db_query( "SELECT id FROM ttrss_users WHERE
265 $is_registered = db_num_rows($result) > 0;
267 if ($is_registered) {
268 print_error(__('Sorry
, this username is already taken
.'));
269 print "<p><form method=\"GET\" action=\"index.php\">
270 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
274 $password = make_password();
276 $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
277 $pwd_hash = encrypt_password($password, $salt, true);
279 db_query( "INSERT INTO ttrss_users
280 (login,pwd_hash,access_level,last_login, email, created, salt)
281 VALUES ('$login', '$pwd_hash', 0, null, '$email', NOW(), '$salt')");
283 $result = db_query( "SELECT id FROM ttrss_users WHERE
284 login = '$login' AND pwd_hash = '$pwd_hash'");
286 if (db_num_rows($result) != 1) {
287 print_error(__('Registration failed
.'));
288 print "<p><form method=\"GET\" action=\"index.php\">
289 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
293 $new_uid = db_fetch_result($result, 0, "id");
295 initialize_user( $new_uid);
299 "You are receiving this message, because you (or somebody else) have opened\n".
300 "an account at Tiny Tiny RSS.\n".
302 "Your login information is as follows:\n".
305 "Password: $password\n".
307 "Don't forget to login at least once to your
new account
, otherwise\n
".
308 "it will be deleted in
24 hours
.\n".
310 "If that wasn
't you, just ignore this message. Thanks.";
312 $mail = new ttrssMailer();
313 $mail->IsHTML(false);
314 $rc = $mail->quickMail($email, "", "Registration information for Tiny Tiny RSS", $reg_text, false);
316 if (!$rc) print_error($mail->ErrorInfo);
323 "New user had registered at your Tiny Tiny RSS installation.\n".
329 $mail = new ttrssMailer();
330 $mail->IsHTML(false);
331 $rc = $mail->quickMail(REG_NOTIFY_ADDRESS, "", "Registration notice for Tiny Tiny RSS", $reg_text, false);
332 if (!$rc) print_error($mail->ErrorInfo);
334 print_notice(__("Account created successfully."));
336 print "<p><form method=\"GET\" action=\"index.php\">
337 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
345 print_error('Plese check the form again
, you have failed the robot test
.');
346 print "<p><form method=\"GET\" action=\"index.php\">
347 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
356 <?php print_notice(__('New user registrations are currently closed
.')) ?>
358 <?php print "<p><form method=\"GET\" action=\"index.php\">
359 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">