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 <?php
print "<p><form method=\"GET\" action=\"tt-rss.php\">
195 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
198 <?
} else if ($action == "do_register") { ?
>
201 $login = mb_strtolower(trim(db_escape_string($_REQUEST["login"])));
202 $email = trim(db_escape_string($_REQUEST["email"]));
203 $test = trim(db_escape_string($_REQUEST["turing_test"]));
205 if (!$login ||
!$email ||
!$test) {
206 print_error(__("Your registration information is incomplete."));
207 print "<p><form method=\"GET\" action=\"tt-rss.php\">
208 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
213 if ($test == "four" ||
$test == "4") {
215 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
218 $is_registered = db_num_rows($result) > 0;
220 if ($is_registered) {
221 print_error(__('Sorry, this username is already taken.'));
222 print "<p><form method=\"GET\" action=\"tt-rss.php\">
223 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
227 $password = make_password();
229 $pwd_hash = encrypt_password($password, $login);
231 db_query($link, "INSERT INTO ttrss_users
232 (login,pwd_hash,access_level,last_login, email, created)
233 VALUES ('$login', '$pwd_hash', 0, null, '$email', NOW())");
235 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
236 login = '$login' AND pwd_hash = '$pwd_hash'");
238 if (db_num_rows($result) != 1) {
239 print_error(__('Registration failed.'));
240 print "<p><form method=\"GET\" action=\"tt-rss.php\">
241 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
245 $new_uid = db_fetch_result($result, 0, "id");
247 initialize_user($link, $new_uid);
251 "You are receiving this message, because you (or somebody else) have opened\n".
252 "an account at Tiny Tiny RSS.\n".
254 "Your login information is as follows:\n".
257 "Password: $password\n".
259 "Don't forget to login at least once to your new account, otherwise\n".
260 "it will be deleted in 24 hours.\n".
262 "If that wasn't you, just ignore this message. Thanks.";
264 $mail = new PHPMailer();
266 $mail->PluginDir
= "phpmailer/";
267 $mail->SetLanguage("en", "phpmailer/language/");
269 $mail->CharSet
= "UTF-8";
271 $mail->From
= DIGEST_FROM_ADDRESS
;
272 $mail->FromName
= DIGEST_FROM_NAME
;
273 $mail->AddAddress($email);
275 if (DIGEST_SMTP_HOST
) {
276 $mail->Host
= DIGEST_SMTP_HOST
;
277 $mail->Mailer
= "smtp";
278 $mail->Username
= DIGEST_SMTP_LOGIN
;
279 $mail->Password
= DIGEST_SMTP_PASSWORD
;
282 // $mail->IsHTML(true);
283 $mail->Subject
= "Registration information for Tiny Tiny RSS";
284 $mail->Body
= $reg_text;
285 // $mail->AltBody = $digest_text;
289 if (!$rc) print_error($mail->ErrorInfo
);
293 "New user had registered at your Tiny Tiny RSS installation.\n".
298 $mail = new PHPMailer();
300 $mail->PluginDir
= "phpmailer/";
301 $mail->SetLanguage("en", "phpmailer/language/");
303 $mail->CharSet
= "UTF-8";
305 $mail->From
= DIGEST_FROM_ADDRESS
;
306 $mail->FromName
= DIGEST_FROM_NAME
;
307 $mail->AddAddress(REG_NOTIFY_ADDRESS
);
309 if (DIGEST_SMTP_HOST
) {
310 $mail->Host
= DIGEST_SMTP_HOST
;
311 $mail->Mailer
= "smtp";
312 $mail->Username
= DIGEST_SMTP_LOGIN
;
313 $mail->Password
= DIGEST_SMTP_PASSWORD
;
316 // $mail->IsHTML(true);
317 $mail->Subject
= "Registration notice for Tiny Tiny RSS";
318 $mail->Body
= $reg_text;
319 // $mail->AltBody = $digest_text;
323 print_notice(__("Account created successfully."));
325 print "<p><form method=\"GET\" action=\"tt-rss.php\">
326 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
334 print_error('Plese check the form again, you have failed the robot test.');
335 print "<p><form method=\"GET\" action=\"tt-rss.php\">
336 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
345 <?php
print_notice(__('New user registrations are currently closed.')) ?
>
347 <?php
print "<p><form method=\"GET\" action=\"tt-rss.php\">
348 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">