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(get_include_path() . PATH_SEPARATOR .
8 dirname(__FILE__) . "/include");
10 require_once 'lib/phpmailer/class.phpmailer.php';
12 $action = $_REQUEST["action"];
14 require_once "functions.php";
15 require_once "sessions.php";
16 require_once "sanity_check.php";
17 require_once "config.php";
18 require_once "db.php";
20 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
22 if (!init_connection($link)) 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($link, "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($link, "DELETE FROM ttrss_users WHERE last_login IS NULL
64 AND created < NOW() - INTERVAL '1 day' AND access_level = 0");
66 db_query($link, "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($link, "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 <link rel="stylesheet" type="text/css" href="utility.css">
99 <script type="text/javascript" src="js/functions.js"></script>
100 <script type="text/javascript" src="lib/prototype.js"></script>
101 <script type="text/javascript" src="lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls"></script>
104 <script type="text/javascript">
106 function checkUsername() {
109 var f = document.forms['register_form'];
110 var login = f.login.value;
113 new Effect.Highlight(f.login);
114 f.sub_btn.disabled = true;
118 var query = "register.php?action=check&login=" +
121 new Ajax.Request(query, {
122 onComplete: function(transport) {
126 var reply = transport.responseXML;
128 var result = reply.getElementsByTagName('result')[0];
129 var result_code = result.firstChild.nodeValue;
131 if (result_code == 0) {
132 new Effect.Highlight(f.login, {startcolor : '#00ff00'});
133 f.sub_btn.disabled = false;
135 new Effect.Highlight(f.login, {startcolor : '#ff0000'});
136 f.sub_btn.disabled = true;
139 exception_error("checkUsername_callback", e);
145 exception_error("checkUsername", e);
152 function validateRegForm() {
155 var f = document.forms['register_form'];
157 if (f.login.value.length == 0) {
158 new Effect.Highlight(f.login);
162 if (f.email.value.length == 0) {
163 new Effect.Highlight(f.email);
167 if (f.turing_test.value.length == 0) {
168 new Effect.Highlight(f.turing_test);
175 exception_error("validateRegForm", e);
184 <div class="floatingLogo"><img src="images/logo_wide.png"></div>
186 <h1><?php echo __("Create new account") ?></h1>
189 if (!ENABLE_REGISTRATION) {
190 print_error(__("New user registrations are administratively disabled."));
192 print "<p><form method=\"GET\" action=\"backend.php\">
193 <input type=\"hidden\" name=\"op\" value=\"logout\">
194 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
200 <?php if (REG_MAX_USERS > 0) {
201 $result = db_query($link, "SELECT COUNT(*) AS cu FROM ttrss_users");
202 $num_users = db_fetch_result($result, 0, "cu");
205 <?php if (!REG_MAX_USERS || $num_users < REG_MAX_USERS) { ?>
207 <!-- If you have any rules or ToS you'd like to display, enter them here -->
209 <?php if (file_exists("templates/register_notice.txt")) {
210 require_once "templates/register_notice.txt";
213 <?php if (!$action) { ?>
215 <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>
217 <form action="register.php" method="POST" name="register_form">
218 <input type="hidden" name="action" value="do_register">
221 <td><?php echo __('Desired login:') ?></td><td>
224 <input type="submit" value="<?php echo __('Check availability') ?>" onclick='return checkUsername()'>
226 <tr><td><?php echo __('Email:') ?></td><td>
229 <tr><td><?php echo __('How much is two plus two:') ?></td><td>
230 <input name="turing_test"></td></tr>
231 <tr><td colspan="2" align="right">
232 <input type="submit" name="sub_btn" value="<?php echo __('Submit registration') ?>"
233 disabled="disabled" onclick='return validateRegForm()'>
238 <?php print "<p><form method=\"GET\" action=\"index.php\">
239 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
242 <?php } else if ($action == "do_register") { ?>
245 $login = mb_strtolower(trim(db_escape_string($_REQUEST["login"])));
246 $email = trim(db_escape_string($_REQUEST["email"]));
247 $test = trim(db_escape_string($_REQUEST["turing_test"]));
249 if (!$login || !$email || !$test) {
250 print_error(__("Your registration information is incomplete."));
251 print "<p><form method=\"GET\" action=\"index.php\">
252 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
257 if ($test == "four" || $test == "4") {
259 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
262 $is_registered = db_num_rows($result) > 0;
264 if ($is_registered) {
265 print_error(__('Sorry, this username is already taken.'));
266 print "<p><form method=\"GET\" action=\"index.php\">
267 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
271 $password = make_password();
273 $pwd_hash = encrypt_password($password, $login);
275 db_query($link, "INSERT INTO ttrss_users
276 (login,pwd_hash,access_level,last_login, email, created)
277 VALUES ('$login', '$pwd_hash', 0, null, '$email', NOW())");
279 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
280 login = '$login' AND pwd_hash = '$pwd_hash'");
282 if (db_num_rows($result) != 1) {
283 print_error(__('Registration failed.'));
284 print "<p><form method=\"GET\" action=\"index.php\">
285 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
289 $new_uid = db_fetch_result($result, 0, "id");
291 initialize_user($link, $new_uid);
295 "You are receiving this message, because you (or somebody else) have opened\n".
296 "an account at Tiny Tiny RSS.\n".
298 "Your login information is as follows:\n".
301 "Password: $password\n".
303 "Don't forget to login at least once to your new account, otherwise\n".
304 "it will be deleted in 24 hours.\n".
306 "If that wasn't you, just ignore this message. Thanks.";
308 $mail = new PHPMailer();
310 $mail->PluginDir = "lib/phpmailer/";
311 $mail->SetLanguage("en", "lib/phpmailer/language/");
313 $mail->CharSet = "UTF-8";
315 $mail->From = SMTP_FROM_ADDRESS;
316 $mail->FromName = SMTP_FROM_NAME;
317 $mail->AddAddress($email);
320 $mail->Host = SMTP_HOST;
321 $mail->Mailer = "smtp";
322 $mail->Username = SMTP_LOGIN;
323 $mail->Password = SMTP_PASSWORD;
326 // $mail->IsHTML(true);
327 $mail->Subject = "Registration information for Tiny Tiny RSS";
328 $mail->Body = $reg_text;
329 // $mail->AltBody = $digest_text;
333 if (!$rc) print_error($mail->ErrorInfo);
337 "New user had registered at your Tiny Tiny RSS installation.\n".
342 $mail = new PHPMailer();
344 $mail->PluginDir = "lib/phpmailer/";
345 $mail->SetLanguage("en", "lib/phpmailer/language/");
347 $mail->CharSet = "UTF-8";
349 $mail->From = SMTP_FROM_ADDRESS;
350 $mail->FromName = SMTP_FROM_NAME;
351 $mail->AddAddress(REG_NOTIFY_ADDRESS);
354 $mail->Host = SMTP_HOST;
355 $mail->Mailer = "smtp";
356 $mail->Username = SMTP_LOGIN;
357 $mail->Password = SMTP_PASSWORD;
360 // $mail->IsHTML(true);
361 $mail->Subject = "Registration notice for Tiny Tiny RSS";
362 $mail->Body = $reg_text;
363 // $mail->AltBody = $digest_text;
367 print_notice(__("Account created successfully."));
369 print "<p><form method=\"GET\" action=\"index.php\">
370 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
378 print_error('Plese check the form again, you have failed the robot test.');
379 print "<p><form method=\"GET\" action=\"index.php\">
380 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
389 <?php print_notice(__('New user registrations are currently closed.')) ?>
391 <?php print "<p><form method=\"GET\" action=\"index.php\">
392 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">