Changeset 2095 in ExiteCMS for trunk/includes/user_functions.php


Ignore:
Timestamp:
12/07/08 01:22:46 (3 years ago)
Author:
WanWizard
Message:

updated the authentication system to allow new authentication methods to be 'plugged in'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/user_functions.php

    r2078 r2095  
    1919if (eregi("user_functions.php", $_SERVER['PHP_SELF']) || !defined('INIT_CMS_OK')) die(); 
    2020 
     21// load and instantiate the authentication class 
     22require_once "authentication/authentication.php"; 
     23$cms_authentication =& new authentication(); 
     24 
    2125// need the GeoIP functions to determine the users country of origin 
    2226require_once "geoip_include.php"; 
     
    5862        if ($_COOKIE['site_visited'] == "yes") { 
    5963            $site_visited = md5(uniqid(rand(), true)); 
    60             setcookie("site_visited", $site_visited, time() + 31536000, "/", "", "0"); 
    61         } else { 
     64        } else { 
     65            // get the cookie value 
    6266            $site_visited = $_COOKIE['site_visited']; 
    6367        } 
     68        // refresh the cookie 
     69        setcookie("site_visited", $site_visited, time() + 31536000, "/", "", "0"); 
    6470    } 
    6571} 
     
    6773// if not in the process of posting a form, did the login session expire? 
    6874if (count($_POST)==0 && !empty($_SESSION['login_expire']) && $_SESSION['login_expire'] < time()) { 
    69     // clear the login info from the session 
    70     unset($_SESSION['user']); 
    71     unset($_SESSION['userinfo']); 
    72     unset($_SESSION['login_expire']); 
     75    $cms_authentication->logoff(); 
    7376} 
    7477 
    7578// Are we logged in? 
    76 if (isset($_SESSION['userinfo'])) { 
    77     $userinfo_vars = explode(".", $_SESSION['userinfo']); 
    78     $userinfo_1 = isNum($userinfo_vars['0']) ? $userinfo_vars['0'] : "0"; 
    79     $userinfo_2 = (preg_match("/^[0-9a-z]{32}$/", $userinfo_vars['1']) ? $userinfo_vars['1'] : ""); 
    80     $result = dbquery("SELECT * FROM ".$db_prefix."users WHERE user_id='$userinfo_1' AND user_password='$userinfo_2'"); 
    81     unset($userinfo_vars,$userinfo_1,$userinfo_2); 
    82     if (dbrows($result) != 0) { 
    83         $userdata = dbarray($result); 
    84         if ($userdata['user_status'] == 0) { 
    85             // set the user's theme 
    86             if (isset($_SESSION['set_theme']) && file_exists(PATH_THEMES.$_SESSION['set_theme']."/theme.php")) { 
    87                 $userdata['user_theme'] = $_SESSION['set_theme']; 
    88                 unset($_SESSION['set_theme']); 
    89                 $result2 = dbquery("UPDATE ".$db_prefix."users SET user_theme = '".$userdata['user_theme']."' WHERE user_id='$userinfo_1' AND user_password='$userinfo_2'"); 
    90                 define("PATH_THEME", PATH_THEMES.$userdata['user_theme']."/"); 
    91                 define("THEME", THEMES.$userdata['user_theme']."/"); 
    92             } elseif ($userdata['user_theme'] != "Default" && file_exists(PATH_THEMES.$userdata['user_theme']."/theme.php")) { 
    93                 define("PATH_THEME", PATH_THEMES.$userdata['user_theme']."/"); 
    94                 define("THEME", THEMES.$userdata['user_theme']."/"); 
    95             } else { 
    96                 define("PATH_THEME", PATH_THEMES.$settings['theme']."/"); 
    97                 define("THEME", THEMES.$settings['theme']."/"); 
    98                 // make sure the default theme exists! 
    99                 if (!file_exists(PATH_THEMES.$settings['theme']."/theme.php")) { 
    100                     die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>FATAL ERROR: Unable to load the default theme</b></div>"); 
    101                 } 
    102             } 
    103             if ($userdata['user_offset'] <> 0) { 
    104                 $settings['timeoffset'] = $settings['timeoffset'] + $userdata['user_offset']; 
    105             } 
    106             if (empty($_SESSION['lastvisit'])) { 
    107                 $_SESSION['lastvisit'] = $userdata['user_lastvisit']; 
    108                 $lastvisited = $userdata['user_lastvisit']; 
    109             } else { 
    110                 $lastvisited = $_SESSION['lastvisit']; 
    111             } 
    112         } else { 
    113             header("P3P: CP='NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM'"); 
    114             // make sure the user info is erased from the session 
    115             unset($_SESSION['user']); 
    116             unset($_SESSION['userinfo']); 
    117             unset($_SESSION['login_expire']); 
    118             redirect(BASEDIR."index.php", "script"); 
    119             exit; 
    120         } 
    121         // update the login expiration timestamp 
    122         if ($settings['login_expire']) { 
    123             if (isset($_SESSION['remember_me']) && $_SESSION['remember_me'] == "yes") { 
    124                 $_SESSION['login_expire'] = time() + $settings['login_extended_expire']; 
    125             } else { 
    126                 $_SESSION['login_expire'] = time() + $settings['login_expire']; 
    127             } 
    128         } else { 
    129             $_SESSION['login_expire'] = mktime(0,0,0,1,1,2038); // do not expire 
    130         } 
    131     } else { 
    132         header("P3P: CP='NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM'"); 
    133         // make sure the user info is erased from the session 
    134         unset($_SESSION['user']); 
    135         unset($_SESSION['userinfo']); 
    136         unset($_SESSION['login_expire']); 
    137         redirect(BASEDIR."index.php", "script"); 
    138         exit; 
     79if ($cms_authentication->logged_on()) { 
     80 
     81    $userdata = $cms_authentication->get_userinfo(); 
     82    // set the user's theme 
     83    if (isset($_SESSION['set_theme']) && file_exists(PATH_THEMES.$_SESSION['set_theme']."/theme.php")) { 
     84        $userdata['user_theme'] = $_SESSION['set_theme']; 
     85        unset($_SESSION['set_theme']); 
     86        $result2 = dbquery("UPDATE ".$db_prefix."users SET user_theme = '".$userdata['user_theme']."' WHERE user_id='$userinfo_1' AND user_password='$userinfo_2'"); 
     87        define("PATH_THEME", PATH_THEMES.$userdata['user_theme']."/"); 
     88        define("THEME", THEMES.$userdata['user_theme']."/"); 
     89    } elseif ($userdata['user_theme'] != "Default" && file_exists(PATH_THEMES.$userdata['user_theme']."/theme.php")) { 
     90        define("PATH_THEME", PATH_THEMES.$userdata['user_theme']."/"); 
     91        define("THEME", THEMES.$userdata['user_theme']."/"); 
     92    } else { 
     93        define("PATH_THEME", PATH_THEMES.$settings['theme']."/"); 
     94        define("THEME", THEMES.$settings['theme']."/"); 
     95        // make sure the default theme exists! 
     96        if (!file_exists(PATH_THEMES.$settings['theme']."/theme.php")) { 
     97            die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>FATAL ERROR: Unable to load the default theme</b></div>"); 
     98        } 
     99    } 
     100    if ($userdata['user_offset'] <> 0) { 
     101        $settings['timeoffset'] = $settings['timeoffset'] + $userdata['user_offset']; 
     102    } 
     103    if (empty($_SESSION['lastvisit'])) { 
     104        $_SESSION['lastvisit'] = $userdata['user_lastvisit']; 
     105        $lastvisited = $userdata['user_lastvisit']; 
     106    } else { 
     107        $lastvisited = $_SESSION['lastvisit']; 
     108    } 
     109    // update the login expiration timestamp 
     110    if ($settings['login_expire']) { 
     111        if (isset($_SESSION['remember_me']) && $_SESSION['remember_me'] == "yes") { 
     112            $_SESSION['login_expire'] = time() + $settings['login_extended_expire']; 
     113        } else { 
     114            $_SESSION['login_expire'] = time() + $settings['login_expire']; 
     115        } 
     116    } else { 
     117        $_SESSION['login_expire'] = mktime(0,0,0,1,1,2038); // do not expire 
    139118    } 
    140119} else { 
Note: See TracChangeset for help on using the changeset viewer.