]> git.wh0rd.org Git - tt-rss.git/blob - login.php
better handling of feeds with broken timestamps (closes #119)
[tt-rss.git] / login.php
1 <?php
2 //      require_once "sessions.php";
3
4         require_once "sanity_check.php";
5         require_once "version.php"; 
6         require_once "config.php";
7         require_once "functions.php";
8
9         $error_msg = "";
10
11         $url_path = get_script_urlpath();
12         $return_to = $_REQUEST["rt"];
13
14         if (ENABLE_LOGIN_SSL) {         
15                 $redirect_base = "https://" . $_SERVER["SERVER_NAME"] . $url_path;
16         } else {
17                 $redirect_base = "http://" . $_SERVER["SERVER_NAME"] . $url_path;
18         }
19
20         if (SINGLE_USER_MODE && $return_to != "none") {
21                 header("Location: $redirect_base/tt-rss.php");
22                 exit;
23         }
24
25         $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
26
27         $login = $_POST["login"];
28         $password = $_POST["password"];
29         $action = $_POST["action"];
30
31         if ($_COOKIE[get_session_cookie_name()] && $return_to != "none") {
32                 require_once "sessions.php";
33                 if ($_SESSION["uid"]) {
34                         initialize_user_prefs($link, $_SESSION["uid"]); 
35                         header("Location: $redirect_base/tt-rss.php");
36                         exit;
37                 }
38         }
39
40         if ($login && $password) {
41
42                 if ($_POST["remember_me"]) {
43                         session_set_cookie_params(SESSION_COOKIE_LIFETIME_REMEMBER);
44                 } else {
45                         session_set_cookie_params(SESSION_COOKIE_LIFETIME);
46                 }
47                         
48                 require_once "sessions.php";
49
50                 if (authenticate_user($link, $login, $password)) {
51                         initialize_user_prefs($link, $_SESSION["uid"]); 
52
53                         if ($_POST["remember_me"]) {
54                                 $_SESSION["cookie_lifetime"] = time() + SESSION_COOKIE_LIFETIME_REMEMBER;
55                         } else {
56                                 $_SESSION["cookie_lifetime"] = time() + SESSION_COOKIE_LIFETIME;
57                         }
58
59                         setcookie("ttrss_cltime", $_SESSION["cookie_lifetime"], 
60                                 $_SESSION["cookie_lifetime"]);
61
62                         if (!$return_to) {
63                                 $return_to = "tt-rss.php";
64                         }
65                         header("Location: $redirect_base/$return_to");
66                         exit;
67                 } else {
68                         $error_msg = "Error: Unable to authenticate user. Please check login and password.";
69                 }
70         } else if ($action) {
71                 $error_msg = "Error: Either login or password is blank.";
72         }
73
74 ?>
75 <html>
76 <head>
77         <title>Tiny Tiny RSS : Login</title>
78         <link rel="stylesheet" type="text/css" href="tt-rss.css">
79         <link rel="shortcut icon" type="image/png" href="images/favicon.png">
80         <!--[if gte IE 5.5000]>
81                 <script type="text/javascript" src="pngfix.js"></script>
82         <![endif]-->
83         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
84 </head>
85
86 <body>
87
88 <script type="text/javascript">
89 function init() {
90
91         if (arguments.callee.done) return;
92         arguments.callee.done = true;           
93
94         var login = document.forms["loginForm"].login;
95
96         login.focus();
97
98 }
99 </script>
100
101 <script type="text/javascript">
102 if (document.addEventListener) {
103         document.addEventListener("DOMContentLoaded", init, null);
104 }
105 window.onload = init;
106 </script>
107
108 <form action="login.php" method="POST" name="loginForm">
109
110 <table width="100%" class="loginForm2">
111 <tr>
112         <td class="loginTop" valign="bottom" align="left">
113                 <img src="images/ttrss_logo_big.png" alt="Logo">
114         </td>
115 </tr><tr>
116         <td align="center" valign="middle" class="loginMiddle" height="100%">
117                 <?php if ($error_msg) { ?>
118                         <div class="loginError"><?php echo $error_msg ?></div>
119                 <?php } ?>
120                 <table>
121                         <tr><td align="right">Login:</td>
122                         <td align="right"><input name="login"></td></tr>
123                         <tr><td align="right">Password:</td>
124                         <td align="right"><input type="password" name="password"></td></tr>
125                         <tr><td colspan="2">
126                                 <input type="checkbox" name="remember_me" id="remember_me">
127                                 <label for="remember_me">Remember me on this computer</label>
128                         </td></tr>
129                         <tr><td colspan="2" align="right" class="innerLoginCell">
130                                 <input type="submit" class="button" value="Login">
131                                 <input type="hidden" name="action" value="login">
132                                 <input type="hidden" name="rt" 
133                                         value="<?php if ($return_to != 'none') { echo $return_to; } ?>">
134                         </td></tr>
135                 </table>
136         </td>
137 </tr><tr>
138         <td align="center" class="loginBottom">
139                 <a href="http://tt-rss.spb.ru/">Tiny Tiny RSS</a> &copy; 2005-2007 <a href="http://bah.org.ru/">Andrew Dolgov</a>
140         </td>
141 </tr>
142
143 </table>
144
145 </form>
146
147 <?php db_close($link); ?>
148
149 <script type="text/javascript">
150         /* for IE */
151         function statechange() {
152                 if (document.readyState == "interactive") init();
153         }
154
155         if (document.readyState) {      
156                 if (document.readyState == "interactive" || document.readyState == "complete") {
157                         init();
158                 } else {
159                         document.onreadystatechange = statechange;
160                 }
161         }
162 </script>
163
164 </body>
165 </html>