Changeset 149 for trunk/lib


Ignore:
Timestamp:
Jun 5, 2006 2:34:47 AM (18 years ago)
Author:
scdev
Message:

Q - while we're changing interfaces I'm going to change ->clearAuth() to ->clear().

Location:
trunk/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Auth_File.inc.php

    r148 r149  
    112112     * @access public
    113113     */
    114     function clearAuth()
     114    function clear()
    115115    {
    116116        $_SESSION[$this->_ns] = array('authenticated' => false);
     
    202202        $username = strtolower(trim($username));
    203203
    204         $this->clearAuth();
     204        $this->clear();
    205205
    206206        if (!$this->authenticate($username, $password)) {
  • trunk/lib/Auth_SQL.inc.php

    r148 r149  
    252252     * @access public
    253253     */
    254     function clearAuth()
     254    function clear()
    255255    {
    256256        $db =& DB::getInstance();
     
    274274     * @param mixed $val      Value to set variable to.
    275275     */
    276     function setVal($key, $val)
     276    function set($key, $val)
    277277    {
    278278        if (!isset($_SESSION[$this->_ns]['user_data'])) {
     
    365365        $this->initDB();
    366366
    367         $this->clearAuth();
     367        $this->clear();
    368368
    369369        if (!$user_data = $this->authenticate($username, $password)) {
     
    402402
    403403                // No login: user is blocked!
    404                 $this->clearAuth();
     404                $this->clear();
    405405                return false;
    406406            }
     
    437437                $db->query("DELETE FROM " . $this->_params['db_login_table'] . " WHERE " . $this->_params['db_primary_key'] . " = '" . $this->get('user_id') . "'");
    438438                // No login: reset password because of account abuse!
    439                 $this->clearAuth();
     439                $this->clear();
    440440                return false;
    441441            }
     
    569569
    570570        // User is not authenticated.
    571         $this->clearAuth();
     571        $this->clear();
    572572        return false;
    573573    }
  • trunk/lib/Lock.inc.php

    r146 r149  
    5555        $app =& App::getInstance();
    5656
    57         if (!method_exists($auth_object, 'getVal') || !method_exists($auth_object, 'getUsername')) {
     57        if (!method_exists($auth_object, 'get') || !method_exists($auth_object, 'getUsername')) {
    5858            trigger_error('Constructor not provided a valid Auth_* object.', E_USER_ERROR);
    5959        }
     
    183183        }
    184184        if ($this->data = mysql_fetch_assoc($qid)) {
    185             $app->logMsg(sprintf('Selecting %slocked record: %s %s %s', ($this->data['set_by_admin_id'] == $this->_auth->getVal('user_id') ? 'self-' : ''), $record_table_or_lock_id, $record_key, $record_val), LOG_DEBUG, __FILE__, __LINE__);
     185            $app->logMsg(sprintf('Selecting %slocked record: %s %s %s', ($this->data['set_by_admin_id'] == $this->_auth->get('user_id') ? 'self-' : ''), $record_table_or_lock_id, $record_key, $record_val), LOG_DEBUG, __FILE__, __LINE__);
    186186            /// FIX ME: What if admin set lock, but public user is current lock user?
    187187            $this->data['editor'] = $this->_auth->getUsername($this->data['set_by_admin_id']);
     
    218218            $qid = $db->query("SELECT * FROM " . $db->escapeString($this->getParam('db_table')) . " WHERE lock_id = '" . $db->escapeString($this->data['lock_id']) . "'");
    219219            if ($lock = mysql_fetch_assoc($qid)) {
    220                 return ($lock['set_by_admin_id'] == $this->_auth->getVal('user_id'));
     220                return ($lock['set_by_admin_id'] == $this->_auth->get('user_id'));
    221221            } else {
    222222                return false;
     
    268268                '" . $db->escapeString($record_val) . "',
    269269                '" . $db->escapeString($title) . "',
    270                 '" . $db->escapeString($this->_auth->getVal('user_id')) . "',
     270                '" . $db->escapeString($this->_auth->get('user_id')) . "',
    271271                NOW()
    272272            )
     
    318318            // Delete specific user's locks.
    319319            $db->query("DELETE FROM " . $db->escapeString($this->getParam('db_table')) . " WHERE set_by_admin_id = '" . $db->escapeString($user_id) . "'");
    320             $app->logMsg(sprintf('Record locks owned by %s %s have been deleted', $this->_auth->getVal('auth_name'), $this->_auth->getUsername($user_id)), LOG_DEBUG, __FILE__, __LINE__);
     320            $app->logMsg(sprintf('Record locks owned by %s %s have been deleted', $this->_auth->get('auth_name'), $this->_auth->getUsername($user_id)), LOG_DEBUG, __FILE__, __LINE__);
    321321        } else {
    322322            // Delete ALL locks.
    323323            $db->query("DELETE FROM " . $db->escapeString($this->getParam('db_table')) . "");
    324             $app->logMsg(sprintf('All record locks deleted by %s %s', $this->_auth->getVal('auth_name'), $this->_auth->getVal('username')), LOG_DEBUG, __FILE__, __LINE__);
     324            $app->logMsg(sprintf('All record locks deleted by %s %s', $this->_auth->get('auth_name'), $this->_auth->get('username')), LOG_DEBUG, __FILE__, __LINE__);
    325325        }
    326326    }
  • trunk/lib/Prefs.inc.php

    r147 r149  
    1818    var $_params = array(
    1919       
     20        // The current user_id for which to load/save preferences.
     21        'user_id' => null,
     22       
     23        // How long before we force a reload of the prefs data? 3600 = once every hour.
     24        'load_timeout' => 3600,
     25       
    2026        // Enable database storage.
    2127        'enable_db' => true,
     
    2632        // Automatically create table and verify columns. Better set to false after site launch.
    2733        'create_table' => true,
    28        
    29         // The current user_id for which to load/save preferences.
    30         'user_id' => null,
    3134    );
    3235
     
    132135    function setDefaults($defaults)
    133136    {
     137        $app =& App::getInstance();
    134138        if (isset($defaults) && is_array($defaults)) {
    135139            // Apply defaults to the session, setting only non-existing values.
     140            $app->logMsg(sprintf('Pre-defaulting: %s', getDump($_SESSION[$this->_ns]['data'])), LOG_DEBUG, __FILE__, __LINE__);
    136141            $_SESSION[$this->_ns]['data'] = array_merge($defaults, $_SESSION[$this->_ns]['data']);
     142            $app->logMsg(sprintf('Post-defaulting: %s', getDump($_SESSION[$this->_ns]['data'])), LOG_DEBUG, __FILE__, __LINE__);
    137143        }
    138144    }
     
    146152    function set($key, $val)
    147153    {
    148         $_SESSION[$this->_ns]['data'][$key] = $val;
     154        if ('' != $key && '' != $val) {
     155            $_SESSION[$this->_ns]['data'][$key] = $val;
     156        }
    149157    }
    150158
     
    185193
    186194    /**
    187      * Empty the $_SESSION cache.
     195     * Empty the $_SESSION cache. This should be executed with the same consideration as $auth->clear()
    188196     */
    189197    function clear()
     
    238246        // Data loaded only once per session.
    239247        $_SESSION[$this->_ns]['loaded'] = true;
     248        $_SESSION[$this->_ns]['load_datetime'] = date('Y-m-d H:i:s');
    240249       
    241250        return true;
     
    243252   
    244253    /*
    245     *   Returns true if the prefs had been loaded from the database into the $_SESSION.
     254    * Returns true if the prefs had been loaded from the database into the $_SESSION recently.
     255    * This function is simply a check so the database isn't access every page load.
    246256    *
    247257    * @access   private
     
    253263    function _isLoaded()
    254264    {
    255         return isset($_SESSION[$this->_ns]['loaded']) && true === $_SESSION[$this->_ns]['loaded'];
     265        if (isset($_SESSION[$this->_ns]['load_datetime'])
     266        && strtotime($_SESSION[$this->_ns]['load_datetime']) > time() - $this->getParam('load_timeout')
     267        && isset($_SESSION[$this->_ns]['loaded'])
     268        && true === $_SESSION[$this->_ns]['loaded']) {
     269            return true;
     270        } else {
     271            return false;
     272        }
    256273    }
    257274   
     
    294311            $insert_values = array();
    295312            foreach ($_SESSION[$this->_ns]['data'] as $key => $val) {
    296                 $insert_values[] = sprintf("('%s', '%s', '%s', '%s')", DB::escapeString($this->getParam('user_id')), DB::escapeString($this->_ns), DB::escapeString($key), DB::escapeString($val));
     313                if ('' != trim($key) && '' != trim($val)) {
     314                    $insert_values[] = sprintf("('%s', '%s', '%s', '%s')", $db->escapeString($this->getParam('user_id')), $db->escapeString($this->_ns), $db->escapeString($key), $db->escapeString($val));
     315                }
    297316            }
    298317            $db->query("
  • trunk/lib/Version.inc.php

    r146 r149  
    6161        $app =& App::getInstance();
    6262
    63         if (!method_exists($auth_object, 'getVal') || !method_exists($auth_object, 'getUsername')) {
     63        if (!method_exists($auth_object, 'get') || !method_exists($auth_object, 'getUsername')) {
    6464            trigger_error('Constructor not provided a valid Auth_* object.', E_USER_ERROR);
    6565        }
     
    202202                '" . $db->escapeString($title) . "',
    203203                '" . $db->escapeString($notes) . "',
    204                 '" . $db->escapeString($this->_auth->getVal('user_id')) . "',
     204                '" . $db->escapeString($this->_auth->get('user_id')) . "',
    205205                NOW()
    206206            )
     
    363363        while ($row = mysql_fetch_assoc($qid)) {
    364364            // Get admin usernames.
    365             $row['editor'] = $this->_auth->getVal('auth_type') . ' ' . $this->_auth->getUsername($row['saved_by_user_id']);
     365            $row['editor'] = $this->_auth->get('auth_type') . ' ' . $this->_auth->getUsername($row['saved_by_user_id']);
    366366            $versions[] = $row;
    367367        }
Note: See TracChangeset for help on using the changeset viewer.