Refback will be payed now (user cannot setup currently)
[mailer.git] / inc / modules / chk_login.php
index 14a9ee7..a96bc1d 100644 (file)
  ************************************************************************/
 
 // Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
-{
+if (!defined('__SECURITY')) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
 
+// @TODO Replace with own template!
 OPEN_TABLE("500", "guest_login_header dashed", "center");
-
-OUTPUT_HTML("<br /><STRONG>".VALIDATING_LOGIN."</STRONG><br />");
+OUTPUT_HTML("<br /><strong>".VALIDATING_LOGIN."</strong><br />");
 
 if (!empty($GLOBALS['userid']) && (isSessionVariableSet('u_hash')) && (isSessionVariableSet('lifetime'))) {
+       // Login failtures are supported since 0.4.7
+       // Do we have 0.4.7 of sql_patches or later?
+       $ADD = "";
+       if (GET_EXT_VERSION("sql_patches") >= "0.4.7") {
+               // Load them here
+               $ADD = ", login_failtures, UNIX_TIMESTAMP(last_failture) AS last_failture";
+       } // END - if
+
        // Get theme from profile
-       $result = SQL_QUERY_ESC("SELECT curr_theme FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
-        array($GLOBALS['userid']), __FILE__, __LINE__);
-       list($NewTheme) = SQL_FETCHROW($result);
+       $result = SQL_QUERY_ESC("SELECT curr_theme".$ADD." FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
+               array($GLOBALS['userid']), __FILE__, __LINE__);
+
+       // Load data
+       $data = SQL_FETCHARRAY($result);
+
+       // Free result
        SQL_FREERESULT($result);
 
        // Change to new theme
-       set_session("mxchange_theme", $NewTheme);
+       set_session("mxchange_theme", $data['curr_theme']);
+
+       // Remmeber login failtures if available
+       if (GET_EXT_VERSION("sql_patches") >= "0.4.7") {
+               // Reset login failtures
+               SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data
+SET login_failtures=0, last_failture='0000-00-00 00:00:00'
+WHERE userid=%s
+LIMIT 1",
+                       array($GLOBALS['userid']), __FILE__, __LINE__);
 
+               // Store it in session
+               set_session('mxchange_member_failtures', $data['login_failtures']);
+               set_session('mxchange_member_last_fail', $data['last_failture']);
+       } // END - if
+
+       // Bonus is not given by default ;-)
        $bonus = false;
        if ((GET_EXT_VERSION("sql_patches") >= "0.2.8") && (GET_EXT_VERSION("bonus") >= "0.2.1") && ($_CONFIG['bonus_login_yn'] == "N") && ($_CONFIG['bonus_login_yn'] == "Y")) {
-               // Update last login
+               // Update last login if far enougth away
                $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data
 SET last_login=UNIX_TIMESTAMP()
-WHERE userid=%d AND last_login < (UNIX_TIMESTAMP() - %d)
-LIMIT 1", array($GLOBALS['userid'], $_CONFIG['login_timeout']),
- __FILE__, __LINE__);
-               if (SQL_AFFECTEDROWS($link) == 1) $bonus = true;
-       }
-       if (($bonus) && ($_GET['mode'] == "bonus") && (EXT_IS_ACTIVE("bonus")))         {
+WHERE userid=%s AND last_login < (UNIX_TIMESTAMP() - %s)
+LIMIT 1",
+                       array(
+                               $GLOBALS['userid'],
+                               $_CONFIG['login_timeout']
+                       ), __FILE__, __LINE__
+               );
+               if (SQL_AFFECTEDROWS() == 1) $bonus = true;
+       } // END - if
+
+       if (($bonus) && ($_GET['mode'] == "bonus") && (EXT_IS_ACTIVE("bonus"))) {
                // Output message with added points
-               OUTPUT_HTML("<FONT class=\"tiny\">
+               OUTPUT_HTML("<font class=\"tiny\">
   ".BONUS_LOGIN_BONUS_ADDED_1."
-  <STRONG>".TRANSLATE_COMMA($_CONFIG['login_bonus'])." ".POINTS."</STRONG>
+  <strong>".TRANSLATE_COMMA($_CONFIG['login_bonus'])." ".POINTS."</strong>
   ".BONUS_LOGIN_BONUS_ADDED_2."
-</FONT>");
-       }
-        elseif (EXT_IS_ACTIVE("bonus"))
-       {
+</font>");
+       } elseif (EXT_IS_ACTIVE("bonus")) {
                // No login bonus added!
-               OUTPUT_HTML("<FONT class=\"member_failed\">".BONUS_LOGIN_BONUS_NOT_ADDED."</FONT>");
+               OUTPUT_HTML("<font class=\"member_failed\">".BONUS_LOGIN_BONUS_NOT_ADDED."</font>");
        }
 
        // Redirect to member area
        LOAD_TEMPLATE("member_login_js");
-}
- else
-{
+} else {
        // Login failed!
        LOAD_TEMPLATE("login_failed_js");
 }