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 "autoload.php";
11 require_once "functions.php";
12 require_once "sessions.php";
13 require_once "sanity_check.php";
14 require_once "config.php";
15 require_once "db.php";
19 $action = $_REQUEST["action"];
21 if (!init_plugins()) return;
23 if ($_REQUEST["format"] == "feed") {
24 header("Content-Type: text/xml");
26 print '<?xml version="1.0" encoding="utf-8"?>';
27 print "<feed xmlns=\"http://www.w3.org/2005/Atom\">
28 <id>".htmlspecialchars(SELF_URL_PATH
. "/register.php")."</id>
29 <title>Tiny Tiny RSS registration slots</title>
30 <link rel=\"self\" href=\"".htmlspecialchars(SELF_URL_PATH
. "/register.php?format=feed")."\"/>
31 <link rel=\"alternate\" href=\"".htmlspecialchars(SELF_URL_PATH
)."\"/>";
33 if (ENABLE_REGISTRATION
) {
34 $result = db_query( "SELECT COUNT(*) AS cu FROM ttrss_users");
35 $num_users = db_fetch_result($result, 0, "cu");
37 $num_users = REG_MAX_USERS
- $num_users;
38 if ($num_users < 0) $num_users = 0;
39 $reg_suffix = "enabled";
42 $reg_suffix = "disabled";
46 <id>".htmlspecialchars(SELF_URL_PATH
)."/register.php?$num_users"."</id>
47 <link rel=\"alternate\" href=\"".htmlspecialchars(SELF_URL_PATH
. "/register.php")."\"/>";
49 print "<title>$num_users slots are currently available, registration $reg_suffix</title>";
50 print "<summary>$num_users slots are currently available, registration $reg_suffix</summary>";
59 /* Remove users which didn't login after receiving their registration information */
61 if (DB_TYPE
== "pgsql") {
62 db_query( "DELETE FROM ttrss_users WHERE last_login IS NULL
63 AND created < NOW() - INTERVAL '1 day' AND access_level = 0");
65 db_query( "DELETE FROM ttrss_users WHERE last_login IS NULL
66 AND created < DATE_SUB(NOW(), INTERVAL 1 DAY) AND access_level = 0");
69 if (file_exists("register_expire_do.php")) {
70 require_once "register_expire_do.php";
73 if ($action == "check") {
74 header("Content-Type: application/xml");
76 $login = trim(db_escape_string( $_REQUEST['login']));
78 $result = db_query( "SELECT id FROM ttrss_users WHERE
79 LOWER(login) = LOWER('$login')");
81 $is_registered = db_num_rows($result) > 0;
85 printf("%d", $is_registered);
95 <title
>Create
new account
</title
>
96 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
97 <?php
echo stylesheet_tag("css/default.css") ?
>
98 <?php
echo javascript_tag("js/functions.js") ?
>
99 <?php
echo javascript_tag("lib/prototype.js") ?
>
100 <?php
echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls") ?
>
103 <script type
="text/javascript">
105 function checkUsername() {
108 var f
= document
.forms
['register_form'];
109 var login
= f
.login
.value
;
112 new Effect
.Highlight(f
.login
);
113 f
.sub_btn
.disabled
= true;
117 var query
= "register.php?action=check&login=" +
120 new Ajax
.Request(query
, {
121 onComplete
: function(transport
) {
125 var reply
= transport
.responseXML
;
127 var result
= reply
.getElementsByTagName('result')[0];
128 var result_code
= result
.firstChild
.nodeValue
;
130 if (result_code
== 0) {
131 new Effect
.Highlight(f
.login
, {startcolor
: '#00ff00'});
132 f
.sub_btn
.disabled
= false;
134 new Effect
.Highlight(f
.login
, {startcolor
: '#ff0000'});
135 f
.sub_btn
.disabled
= true;
138 exception_error("checkUsername_callback", e
);
144 exception_error("checkUsername", e
);
151 function validateRegForm() {
154 var f
= document
.forms
['register_form'];
156 if (f
.login
.value
.length
== 0) {
157 new Effect
.Highlight(f
.login
);
161 if (f
.email
.value
.length
== 0) {
162 new Effect
.Highlight(f
.email
);
166 if (f
.turing_test
.value
.length
== 0) {
167 new Effect
.Highlight(f
.turing_test
);
174 exception_error("validateRegForm", e
);
181 <body
class="claro ttrss_utility">
183 <div
class="floatingLogo"><img src
="images/logo_small.png"></div
>
185 <h1
><?php
echo __("Create new account") ?
></h1
>
187 <div
class="content">
190 if (!ENABLE_REGISTRATION
) {
191 print_error(__("New user registrations are administratively disabled."));
193 print "<p><form method=\"GET\" action=\"backend.php\">
194 <input type=\"hidden\" name=\"op\" value=\"logout\">
195 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
201 <?php
if (REG_MAX_USERS
> 0) {
202 $result = db_query( "SELECT COUNT(*) AS cu FROM ttrss_users");
203 $num_users = db_fetch_result($result, 0, "cu");
206 <?php
if (!REG_MAX_USERS ||
$num_users < REG_MAX_USERS
) { ?
>
208 <!-- If you have any rules
or ToS you
'd like to display, enter them here -->
210 <?php if (file_exists("templates/register_notice.txt")) {
211 require_once "templates/register_notice.txt";
214 <?php if (!$action) { ?>
216 <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>
218 <form action="register.php" method="POST" name="register_form">
219 <input type="hidden" name="action" value="do_register">
222 <td><?php echo __('Desired login
:') ?></td><td>
223 <input name="login" required>
225 <input type="submit" value="<?php echo __('Check availability
') ?>" onclick='return checkUsername()'>
227 <tr><td><?php echo __('Email
:') ?></td><td>
228 <input name="email" type="email" required>
230 <tr><td><?php echo __('How much is two plus two
:') ?></td><td>
231 <input name="turing_test" required></td></tr>
232 <tr><td colspan="2" align="right">
233 <input type="submit" name="sub_btn" value="<?php echo __('Submit registration
') ?>"
234 disabled="disabled" onclick='return validateRegForm()'>
239 <?php print "<p><form method=\"GET\" action=\"index.php\">
240 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
243 <?php } else if ($action == "do_register") { ?>
246 $login = mb_strtolower(trim(db_escape_string( $_REQUEST["login"])));
247 $email = trim(db_escape_string( $_REQUEST["email"]));
248 $test = trim(db_escape_string( $_REQUEST["turing_test"]));
250 if (!$login || !$email || !$test) {
251 print_error(__("Your registration information is incomplete."));
252 print "<p><form method=\"GET\" action=\"index.php\">
253 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
258 if ($test == "four" || $test == "4") {
260 $result = db_query( "SELECT id FROM ttrss_users WHERE
263 $is_registered = db_num_rows($result) > 0;
265 if ($is_registered) {
266 print_error(__('Sorry
, this username is already taken
.'));
267 print "<p><form method=\"GET\" action=\"index.php\">
268 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
272 $password = make_password();
274 $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
275 $pwd_hash = encrypt_password($password, $salt, true);
277 db_query( "INSERT INTO ttrss_users
278 (login,pwd_hash,access_level,last_login, email, created, salt)
279 VALUES ('$login', '$pwd_hash', 0, null, '$email', NOW(), '$salt')");
281 $result = db_query( "SELECT id FROM ttrss_users WHERE
282 login = '$login' AND pwd_hash = '$pwd_hash'");
284 if (db_num_rows($result) != 1) {
285 print_error(__('Registration failed
.'));
286 print "<p><form method=\"GET\" action=\"index.php\">
287 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
291 $new_uid = db_fetch_result($result, 0, "id");
293 initialize_user( $new_uid);
297 "You are receiving this message, because you (or somebody else) have opened\n".
298 "an account at Tiny Tiny RSS.\n".
300 "Your login information is as follows:\n".
303 "Password: $password\n".
305 "Don't forget to login at least once to your
new account
, otherwise\n
".
306 "it will be deleted in
24 hours
.\n".
308 "If that wasn
't you, just ignore this message. Thanks.";
310 $mailer = new Mailer();
311 $rc = $mailer->mail(["to_address" => $email,
312 "subject" => "Registration information for Tiny Tiny RSS",
313 "message" => $reg_text]);
315 if (!$rc) print_error($mailer->error());
319 "New user had registered at your Tiny Tiny RSS installation.\n".
324 $mailer = new Mailer();
325 $rc = $mailer->mail(["to_address" => REG_NOTIFY_ADDRESS,
326 "subject" => "Registration notice for Tiny Tiny RSS",
327 "message" => $reg_text]);
329 if (!$rc) print_error($mailer->error());
331 print_notice(__("Account created successfully."));
333 print "<p><form method=\"GET\" action=\"index.php\">
334 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
342 print_error('Plese check the form again
, you have failed the robot test
.');
343 print "<p><form method=\"GET\" action=\"index.php\">
344 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
353 <?php print_notice(__('New user registrations are currently closed
.')) ?>
355 <?php print "<p><form method=\"GET\" action=\"index.php\">
356 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">