]>
Commit | Line | Data |
---|---|---|
4f7956b3 | 1 | <?php |
a53f3dc4 | 2 | // This file uses two additional include files: |
4f7956b3 | 3 | // |
a53f3dc4 AD |
4 | // 1) templates/register_notice.txt - displayed above the registration form |
5 | // 2) register_expire_do.php - contains user expiration queries when necessary | |
4f7956b3 | 6 | |
31303c6b AD |
7 | require_once 'lib/phpmailer/class.phpmailer.php'; |
8 | ||
4f7956b3 AD |
9 | $action = $_REQUEST["action"]; |
10 | ||
fb074239 | 11 | require_once "functions.php"; |
4f7956b3 | 12 | require_once "sessions.php"; |
4f7956b3 | 13 | require_once "sanity_check.php"; |
4f7956b3 AD |
14 | require_once "config.php"; |
15 | require_once "db.php"; | |
4f7956b3 | 16 | |
133ab8c7 AD |
17 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
18 | ||
19 | init_connection($link); | |
4f7956b3 | 20 | |
870a70e1 AD |
21 | if ($_REQUEST["format"] == "feed") { |
22 | header("Content-Type: text/xml"); | |
23 | ||
24 | print '<?xml version="1.0" encoding="utf-8"?>'; | |
25 | print "<feed xmlns=\"http://www.w3.org/2005/Atom\"> | |
26 | <id>".htmlspecialchars(SELF_URL_PATH . "/register.php")."</id> | |
27 | <title>Tiny Tiny RSS registration slots</title> | |
28 | <link rel=\"self\" href=\"".htmlspecialchars(SELF_URL_PATH . "/register.php?format=feed")."\"/> | |
29 | <link rel=\"alternate\" href=\"".htmlspecialchars(SELF_URL_PATH)."\"/>"; | |
30 | ||
31 | if (ENABLE_REGISTRATION) { | |
32 | $result = db_query($link, "SELECT COUNT(*) AS cu FROM ttrss_users"); | |
33 | $num_users = db_fetch_result($result, 0, "cu"); | |
34 | ||
410c0b3a | 35 | $num_users = REG_MAX_USERS - $num_users; |
870a70e1 AD |
36 | if ($num_users < 0) $num_users = 0; |
37 | $reg_suffix = "enabled"; | |
38 | } else { | |
39 | $num_users = 0; | |
40 | $reg_suffix = "disabled"; | |
41 | } | |
42 | ||
43 | print "<entry> | |
44 | <id>".htmlspecialchars(SELF_URL_PATH)."/register.php?$num_users"."</id> | |
45 | <link rel=\"alternate\" href=\"".htmlspecialchars(SELF_URL_PATH . "/register.php")."\"/>"; | |
46 | ||
47 | print "<title>$num_users slots are currently available, registration $reg_suffix</title>"; | |
48 | print "<summary>$num_users slots are currently available, registration $reg_suffix</summary>"; | |
49 | ||
50 | print "</entry>"; | |
51 | ||
52 | print "</feed>"; | |
53 | ||
54 | return; | |
55 | } | |
56 | ||
4f7956b3 AD |
57 | /* Remove users which didn't login after receiving their registration information */ |
58 | ||
59 | if (DB_TYPE == "pgsql") { | |
133ab8c7 | 60 | db_query($link, "DELETE FROM ttrss_users WHERE last_login IS NULL |
4f7956b3 AD |
61 | AND created < NOW() - INTERVAL '1 day' AND access_level = 0"); |
62 | } else { | |
133ab8c7 | 63 | db_query($link, "DELETE FROM ttrss_users WHERE last_login IS NULL |
4f7956b3 AD |
64 | AND created < DATE_SUB(NOW(), INTERVAL 1 DAY) AND access_level = 0"); |
65 | } | |
66 | ||
a53f3dc4 AD |
67 | if (file_exists("register_expire_do.php")) { |
68 | require_once "register_expire_do.php"; | |
69 | } | |
70 | ||
4f7956b3 AD |
71 | if ($action == "check") { |
72 | header("Content-Type: application/xml"); | |
73 | ||
74 | $login = trim(db_escape_string($_REQUEST['login'])); | |
75 | ||
76 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
77 | LOWER(login) = LOWER('$login')"); | |
133ab8c7 | 78 | |
4f7956b3 AD |
79 | $is_registered = db_num_rows($result) > 0; |
80 | ||
81 | print "<result>"; | |
82 | ||
83 | printf("%d", $is_registered); | |
84 | ||
85 | print "</result>"; | |
86 | ||
87 | return; | |
88 | } | |
89 | ?> | |
90 | ||
91 | <html> | |
92 | <head> | |
93 | <title>Create new account</title> | |
94 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
95 | <link rel="stylesheet" type="text/css" href="utility.css"> | |
4f7956b3 | 96 | <script type="text/javascript" src="functions.js"></script> |
fe7537b5 | 97 | <script type="text/javascript" src="lib/prototype.js"></script> |
bd40e88e | 98 | <script type="text/javascript" src="lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls"></script> |
4f7956b3 AD |
99 | </head> |
100 | ||
101 | <script type="text/javascript"> | |
102 | ||
103 | function checkUsername() { | |
104 | ||
105 | try { | |
106 | var f = document.forms['register_form']; | |
107 | var login = f.login.value; | |
108 | ||
109 | if (login == "") { | |
110 | new Effect.Highlight(f.login); | |
111 | f.sub_btn.disabled = true; | |
112 | return false; | |
113 | } | |
114 | ||
133ab8c7 | 115 | var query = "register.php?action=check&login=" + |
4f7956b3 AD |
116 | param_escape(login); |
117 | ||
118 | new Ajax.Request(query, { | |
133ab8c7 | 119 | onComplete: function(transport) { |
4f7956b3 AD |
120 | |
121 | try { | |
122 | ||
123 | var reply = transport.responseXML; | |
124 | ||
125 | var result = reply.getElementsByTagName('result')[0]; | |
126 | var result_code = result.firstChild.nodeValue; | |
127 | ||
128 | if (result_code == 0) { | |
129 | new Effect.Highlight(f.login, {startcolor : '#00ff00'}); | |
130 | f.sub_btn.disabled = false; | |
131 | } else { | |
132 | new Effect.Highlight(f.login, {startcolor : '#ff0000'}); | |
133 | f.sub_btn.disabled = true; | |
133ab8c7 | 134 | } |
4f7956b3 AD |
135 | } catch (e) { |
136 | exception_error("checkUsername_callback", e); | |
137 | } | |
138 | ||
139 | } }); | |
140 | ||
141 | } catch (e) { | |
142 | exception_error("checkUsername", e); | |
143 | } | |
144 | ||
145 | return false; | |
146 | ||
147 | } | |
148 | ||
149 | function validateRegForm() { | |
150 | try { | |
151 | ||
152 | var f = document.forms['register_form']; | |
153 | ||
154 | if (f.login.value.length == 0) { | |
155 | new Effect.Highlight(f.login); | |
156 | return false; | |
157 | } | |
158 | ||
159 | if (f.email.value.length == 0) { | |
160 | new Effect.Highlight(f.email); | |
161 | return false; | |
162 | } | |
163 | ||
164 | if (f.turing_test.value.length == 0) { | |
165 | new Effect.Highlight(f.turing_test); | |
166 | return false; | |
167 | } | |
168 | ||
169 | return true; | |
170 | ||
171 | } catch (e) { | |
172 | exception_error("validateRegForm", e); | |
173 | return false; | |
174 | } | |
175 | } | |
176 | ||
177 | </script> | |
178 | ||
179 | <body> | |
180 | ||
0ae2bb2a | 181 | <div class="floatingLogo"><img src="images/logo_wide.png"></div> |
4f7956b3 AD |
182 | |
183 | <h1><?php echo __("Create new account") ?></h1> | |
184 | ||
185 | <?php | |
186 | if (!ENABLE_REGISTRATION) { | |
187 | print_error(__("New user registrations are administratively disabled.")); | |
188 | ||
2376ad49 AD |
189 | print "<p><form method=\"GET\" action=\"backend.php\"> |
190 | <input type=\"hidden\" name=\"op\" value=\"logout\"> | |
4f7956b3 AD |
191 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> |
192 | </form>"; | |
193 | return; | |
194 | } | |
195 | ?> | |
196 | ||
4f7956b3 AD |
197 | <?php if (REG_MAX_USERS > 0) { |
198 | $result = db_query($link, "SELECT COUNT(*) AS cu FROM ttrss_users"); | |
199 | $num_users = db_fetch_result($result, 0, "cu"); | |
200 | } ?> | |
201 | ||
0844d6a9 | 202 | <?php if (!REG_MAX_USERS || $num_users < REG_MAX_USERS) { ?> |
4f7956b3 | 203 | |
4ca3d8c4 AD |
204 | <!-- If you have any rules or ToS you'd like to display, enter them here --> |
205 | ||
206 | <?php if (file_exists("templates/register_notice.txt")) { | |
207 | require_once "templates/register_notice.txt"; | |
208 | } ?> | |
209 | ||
0844d6a9 | 210 | <?php if (!$action) { ?> |
133ab8c7 AD |
211 | |
212 | <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> | |
213 | ||
4f7956b3 AD |
214 | <form action="register.php" method="POST" name="register_form"> |
215 | <input type="hidden" name="action" value="do_register"> | |
216 | <table> | |
217 | <tr> | |
218 | <td><?php echo __('Desired login:') ?></td><td> | |
219 | <input name="login"> | |
220 | </td><td> | |
221 | <input type="submit" value="<?php echo __('Check availability') ?>" onclick='return checkUsername()'> | |
222 | </td></tr> | |
e331188f | 223 | <tr><td><?php echo __('Email:') ?></td><td> |
4f7956b3 AD |
224 | <input name="email"> |
225 | </td></tr> | |
e331188f | 226 | <tr><td><?php echo __('How much is two plus two:') ?></td><td> |
4f7956b3 AD |
227 | <input name="turing_test"></td></tr> |
228 | <tr><td colspan="2" align="right"> | |
2a52d96f | 229 | <input type="submit" name="sub_btn" value="<?php echo __('Submit registration') ?>" |
a2998811 | 230 | disabled="disabled" onclick='return validateRegForm()'> |
4f7956b3 AD |
231 | </td></tr> |
232 | </table> | |
233 | </form> | |
1da195e2 AD |
234 | |
235 | <?php print "<p><form method=\"GET\" action=\"tt-rss.php\"> | |
236 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
237 | </form>"; ?> | |
238 | ||
0844d6a9 | 239 | <?php } else if ($action == "do_register") { ?> |
133ab8c7 | 240 | |
0844d6a9 | 241 | <?php |
4f7956b3 AD |
242 | $login = mb_strtolower(trim(db_escape_string($_REQUEST["login"]))); |
243 | $email = trim(db_escape_string($_REQUEST["email"])); | |
244 | $test = trim(db_escape_string($_REQUEST["turing_test"])); | |
133ab8c7 | 245 | |
4f7956b3 | 246 | if (!$login || !$email || !$test) { |
c46a4a05 AD |
247 | print_error(__("Your registration information is incomplete.")); |
248 | print "<p><form method=\"GET\" action=\"tt-rss.php\"> | |
249 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
250 | </form>"; | |
4f7956b3 AD |
251 | return; |
252 | } | |
133ab8c7 | 253 | |
4f7956b3 | 254 | if ($test == "four" || $test == "4") { |
133ab8c7 | 255 | |
4f7956b3 AD |
256 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE |
257 | login = '$login'"); | |
133ab8c7 | 258 | |
4f7956b3 | 259 | $is_registered = db_num_rows($result) > 0; |
133ab8c7 | 260 | |
4f7956b3 AD |
261 | if ($is_registered) { |
262 | print_error(__('Sorry, this username is already taken.')); | |
263 | print "<p><form method=\"GET\" action=\"tt-rss.php\"> | |
264 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
265 | </form>"; | |
266 | } else { | |
133ab8c7 | 267 | |
4f7956b3 | 268 | $password = make_password(); |
133ab8c7 | 269 | |
4f7956b3 | 270 | $pwd_hash = encrypt_password($password, $login); |
133ab8c7 AD |
271 | |
272 | db_query($link, "INSERT INTO ttrss_users | |
4f7956b3 AD |
273 | (login,pwd_hash,access_level,last_login, email, created) |
274 | VALUES ('$login', '$pwd_hash', 0, null, '$email', NOW())"); | |
133ab8c7 AD |
275 | |
276 | $result = db_query($link, "SELECT id FROM ttrss_users WHERE | |
4f7956b3 | 277 | login = '$login' AND pwd_hash = '$pwd_hash'"); |
133ab8c7 | 278 | |
4f7956b3 AD |
279 | if (db_num_rows($result) != 1) { |
280 | print_error(__('Registration failed.')); | |
281 | print "<p><form method=\"GET\" action=\"tt-rss.php\"> | |
282 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
283 | </form>"; | |
284 | } else { | |
133ab8c7 | 285 | |
4f7956b3 | 286 | $new_uid = db_fetch_result($result, 0, "id"); |
133ab8c7 | 287 | |
4f7956b3 | 288 | initialize_user($link, $new_uid); |
133ab8c7 | 289 | |
4f7956b3 AD |
290 | $reg_text = "Hi!\n". |
291 | "\n". | |
292 | "You are receiving this message, because you (or somebody else) have opened\n". | |
293 | "an account at Tiny Tiny RSS.\n". | |
294 | "\n". | |
295 | "Your login information is as follows:\n". | |
296 | "\n". | |
297 | "Login: $login\n". | |
298 | "Password: $password\n". | |
299 | "\n". | |
300 | "Don't forget to login at least once to your new account, otherwise\n". | |
301 | "it will be deleted in 24 hours.\n". | |
302 | "\n". | |
303 | "If that wasn't you, just ignore this message. Thanks."; | |
133ab8c7 | 304 | |
4f7956b3 | 305 | $mail = new PHPMailer(); |
133ab8c7 | 306 | |
d134e3a3 AD |
307 | $mail->PluginDir = "lib/phpmailer/"; |
308 | $mail->SetLanguage("en", "lib/phpmailer/language/"); | |
133ab8c7 | 309 | |
4f7956b3 | 310 | $mail->CharSet = "UTF-8"; |
133ab8c7 | 311 | |
4f7956b3 AD |
312 | $mail->From = DIGEST_FROM_ADDRESS; |
313 | $mail->FromName = DIGEST_FROM_NAME; | |
314 | $mail->AddAddress($email); | |
133ab8c7 | 315 | |
4f7956b3 AD |
316 | if (DIGEST_SMTP_HOST) { |
317 | $mail->Host = DIGEST_SMTP_HOST; | |
318 | $mail->Mailer = "smtp"; | |
319 | $mail->Username = DIGEST_SMTP_LOGIN; | |
320 | $mail->Password = DIGEST_SMTP_PASSWORD; | |
321 | } | |
133ab8c7 | 322 | |
4f7956b3 AD |
323 | // $mail->IsHTML(true); |
324 | $mail->Subject = "Registration information for Tiny Tiny RSS"; | |
325 | $mail->Body = $reg_text; | |
326 | // $mail->AltBody = $digest_text; | |
133ab8c7 | 327 | |
4f7956b3 | 328 | $rc = $mail->Send(); |
133ab8c7 | 329 | |
4f7956b3 | 330 | if (!$rc) print_error($mail->ErrorInfo); |
133ab8c7 | 331 | |
4f7956b3 AD |
332 | $reg_text = "Hi!\n". |
333 | "\n". | |
334 | "New user had registered at your Tiny Tiny RSS installation.\n". | |
335 | "\n". | |
336 | "Login: $login\n". | |
337 | "Email: $email\n"; | |
133ab8c7 | 338 | |
4f7956b3 | 339 | $mail = new PHPMailer(); |
133ab8c7 | 340 | |
d134e3a3 AD |
341 | $mail->PluginDir = "lib/phpmailer/"; |
342 | $mail->SetLanguage("en", "lib/phpmailer/language/"); | |
133ab8c7 | 343 | |
4f7956b3 | 344 | $mail->CharSet = "UTF-8"; |
133ab8c7 | 345 | |
4f7956b3 AD |
346 | $mail->From = DIGEST_FROM_ADDRESS; |
347 | $mail->FromName = DIGEST_FROM_NAME; | |
348 | $mail->AddAddress(REG_NOTIFY_ADDRESS); | |
133ab8c7 | 349 | |
4f7956b3 AD |
350 | if (DIGEST_SMTP_HOST) { |
351 | $mail->Host = DIGEST_SMTP_HOST; | |
352 | $mail->Mailer = "smtp"; | |
353 | $mail->Username = DIGEST_SMTP_LOGIN; | |
354 | $mail->Password = DIGEST_SMTP_PASSWORD; | |
355 | } | |
133ab8c7 | 356 | |
4f7956b3 AD |
357 | // $mail->IsHTML(true); |
358 | $mail->Subject = "Registration notice for Tiny Tiny RSS"; | |
359 | $mail->Body = $reg_text; | |
360 | // $mail->AltBody = $digest_text; | |
133ab8c7 | 361 | |
4f7956b3 | 362 | $rc = $mail->Send(); |
133ab8c7 | 363 | |
4f7956b3 | 364 | print_notice(__("Account created successfully.")); |
133ab8c7 | 365 | |
4f7956b3 AD |
366 | print "<p><form method=\"GET\" action=\"tt-rss.php\"> |
367 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
368 | </form>"; | |
133ab8c7 | 369 | |
4f7956b3 | 370 | } |
133ab8c7 | 371 | |
4f7956b3 | 372 | } |
133ab8c7 | 373 | |
4f7956b3 AD |
374 | } else { |
375 | print_error('Plese check the form again, you have failed the robot test.'); | |
376 | print "<p><form method=\"GET\" action=\"tt-rss.php\"> | |
377 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
378 | </form>"; | |
133ab8c7 | 379 | |
4f7956b3 AD |
380 | } |
381 | } | |
382 | ?> | |
383 | ||
0844d6a9 | 384 | <?php } else { ?> |
4f7956b3 AD |
385 | |
386 | <?php print_notice(__('New user registrations are currently closed.')) ?> | |
387 | ||
388 | <?php print "<p><form method=\"GET\" action=\"tt-rss.php\"> | |
389 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
390 | </form>"; ?> | |
391 | ||
0844d6a9 | 392 | <?php } ?> |
4f7956b3 AD |
393 | |
394 | </body> | |
395 | </html> | |
396 |