]> git.wh0rd.org Git - tt-rss.git/commitdiff
login system tweaks
authorAndrew Dolgov <fox@madoka.spb.ru>
Fri, 2 Mar 2007 10:48:46 +0000 (11:48 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Fri, 2 Mar 2007 10:48:46 +0000 (11:48 +0100)
backend.php
functions.php
login_form.php

index b4eeaf5e0dcace95a6bb4a88715a386c8bbe0f8f..67bdabb56fe788ced67f360c352ebf516b064d86 100644 (file)
@@ -16,8 +16,6 @@
        
        error_reporting(DEFAULT_ERROR_LEVEL); */
 
-       $op = $_REQUEST["op"];
-
        define('SCHEMA_VERSION', 13);
 
        require_once "sanity_check.php";
        require_once "db-prefs.php";
        require_once "functions.php";
 
+       $script_started = getmicrotime();
+
+       $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
+
+       if (!$link) {
+               if (DB_TYPE == "mysql") {
+                       print mysql_error();
+               }
+               // PG seems to display its own errors just fine by default.             
+               return;
+       }
+
+       if (DB_TYPE == "pgsql") {
+               pg_query("set client_encoding = 'UTF-8'");
+               pg_set_client_encoding("UNICODE");
+       }
+
+       $op = $_REQUEST["op"];
+
        $print_exec_time = false;
 
        if ((!$op || $op == "rpc" || $op == "rss" || $op == "digestSend" ||
@@ -41,7 +58,8 @@
                print_error_xml(7); exit;
        }
 
-       if (!$_SESSION["uid"] && $op != "globalUpdateFeeds" && $op != "rss" && $op != "getUnread") {
+       if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds" 
+                       && $op != "rss" && $op != "getUnread") {
 
                if ($op == "rpc") {
                        print_error_xml(6); die;
        require_once "modules/pref-users.php";
        require_once "modules/pref-feed-browser.php"; 
 
-       $script_started = getmicrotime();
-
-       $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
-
-       if (!$link) {
-               if (DB_TYPE == "mysql") {
-                       print mysql_error();
-               }
-               // PG seems to display its own errors just fine by default.             
-               return;
-       }
-
-       if (DB_TYPE == "pgsql") {
-               pg_query("set client_encoding = 'UTF-8'");
-               pg_set_client_encoding("UNICODE");
-       }
 
        if (!sanity_check($link)) { return; }
 
index 5f7565f73a843e9f61d1797eb4c28734576c93a6..98bfc2e64588530af85eae207367f17b45093d9f 100644 (file)
                if (SESSION_CHECK_ADDRESS && $_SESSION["uid"]) {
                        if ($_SESSION["ip_address"]) {
                                if ($_SESSION["ip_address"] != $_SERVER["REMOTE_ADDR"]) {
+                                       $_SESSION["login_error_msg"] = "Session failed to validate (incorrect IP)";
                                        return false;
                                }
                        }
                                }
                        }
 
-                       if ($_COOKIE[get_session_cookie_name()]) {
+/*                     if ($_COOKIE[get_session_cookie_name()]) {
                                require_once "sessions.php";
-                       }
+} */
+
+                       $login_action = $_POST["login_action"];
 
-                       if (!validate_session($link)) {
+/*                     if (!validate_session($link) && $login_action != "do_login") {
                                logout_user();
                                render_login_form($link);
                                exit;
-                       }
+} */
 
-                       $login_action = $_POST["login_action"];
+                       $session_started = false;
 
                        # try to authenticate user if called from login form                    
-                       if ($login_action == "do_login" && !$_SESSION["uid"]) {
+                       if ($login_action == "do_login") {
                                $login = $_POST["login"];
                                $password = $_POST["password"];
                                $remember_me = $_POST["remember_me"];
 
                                require_once "sessions.php";
 
-                               session_regenerate_id();
+                               $session_started = true;
 
                                if (authenticate_user($link, $login, $password)) {
                                        $_POST["password"] = "";
                                        exit;
 
                                        return;
+                               } else {
+                                       $_SESSION["login_error_msg"] = "Incorrect username or password";
                                }
                        }
 
-                       if (!$_SESSION["uid"]) {
+                       if (!$session_started) {
+                               require_once "sessions.php";
+                       }
+
+                       if (!$_SESSION["uid"] || !validate_session($link)) {
                                render_login_form($link);
                                exit;
                        }
index 6139b0205b9a8b642897993597f7164dfbe04584..0ecf3cc120837df4cc503dc8ad04dba7598a2f97 100644 (file)
@@ -41,8 +41,9 @@ window.onload = init;
        </td>
 </tr><tr>
        <td align="center" valign="middle" class="loginMiddle" height="100%">
-               <?php if ($error_msg) { ?>
-                       <div class="loginError"><?php echo $error_msg ?></div>
+               <?php if ($_SESSION['login_error_msg']) { ?>
+                       <div class="loginError"><?php echo $_SESSION['login_error_msg'] ?></div>
+                       <?php $_SESSION['login_error_msg'] = ""; ?>
                <?php } ?>
                <table>
                        <tr><td align="right">Login:</td>