Changeset 149


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
Files:
9 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        }
  • trunk/services/logout.php

    r147 r149  
    55 */
    66
    7 if (isset($auth) && method_exists($auth, 'getVal')) {
     7if (isset($auth) && method_exists($auth, 'get')) {
    88    // Delete the current user's record locks.
    99    require_once 'codebase/lib/Lock.inc.php';
     
    1313
    1414// Logout.
    15 $auth->clearAuth();
     15$auth->clear();
    1616
    1717$app->raiseMsg(sprintf(_("Your session has been logged-out."), null), MSG_SUCCESS, __FILE__, __LINE__);
  • trunk/tests/Auth_FileTest.php

    r136 r149  
    4848    }
    4949
    50     function test_clearauth()
     50    function test_clear()
    5151    {
    5252        $result = $this->Auth_File->login('testuser', 'testpass');
    53         $this->Auth_File->clearauth();
     53        $this->Auth_File->clear();
    5454        $this->assertFalse($_SESSION[$this->Auth_File->_ns]['authenticated'], 'testuser authentication not false in session.');
    5555    }
     
    6161        $this->assertTrue($true, 'testuser not logged in but should be.');
    6262
    63         $this->Auth_File->clearauth();
     63        $this->Auth_File->clear();
    6464        $false = $this->Auth_File->isloggedin();
    6565        $this->assertFalse($false, 'testuser is logged in but shouldn\'t be.');
  • trunk/tests/Auth_SQLTest.php

    r136 r149  
    6767    }
    6868
    69     function test_setval()
    70     {
    71         $this->Auth_SQL->setval('testuserkey', 'testuserval');
     69    function test_set()
     70    {
     71        $this->Auth_SQL->set('testuserkey', 'testuserval');
    7272        $this->assertEquals('testuserval', $_SESSION[$this->Auth_SQL->_ns]['user_data']['testuserkey']);
    7373    }
    7474
    75     function test_getval()
     75    function test_get()
    7676    {
    7777        $_SESSION[$this->Auth_SQL->_ns]['user_data']['testuserkey'] = 'testuserval';
    78         $val = $this->Auth_SQL->getVal('testuserkey');
     78        $val = $this->Auth_SQL->get('testuserkey');
    7979        $this->assertEquals('testuserval', $val);
    8080    }
     
    9595    }
    9696
    97     function test_clearauth()
     97    function test_clear()
    9898    {
    9999        $login = $this->Auth_SQL->login('testuser', 'testpass');
     
    101101        $before_logged_in = $this->Auth_SQL->isloggedin();
    102102        $this->assertTrue($before_logged_in, 'User is not logged in, but should be.');
    103         $this->Auth_SQL->clearauth();
     103        $this->Auth_SQL->clear();
    104104        $after_logged_in = $this->Auth_SQL->isloggedin();
    105105        $this->assertFalse($after_logged_in, 'User is still logged in but should not be.');
     
    123123        $before_logged_in = $this->Auth_SQL->isloggedin();
    124124        $this->assertTrue($before_logged_in, '2. User is not logged in, but should be.');
    125         $this->Auth_SQL->clearauth();
     125        $this->Auth_SQL->clear();
    126126        $after_logged_in = $this->Auth_SQL->isloggedin();
    127127        $this->assertFalse($after_logged_in, '3. User is still logged in but should not be.');
     
    132132        $before_logged_in2 = $this->Auth_SQL->isloggedin();
    133133        $this->assertFalse($before_logged_in2, '5. User is logged in, but should not be.');
    134         $this->Auth_SQL->clearauth();
     134        $this->Auth_SQL->clear();
    135135        $after_logged_in2 = $this->Auth_SQL->isloggedin();
    136136        $this->assertFalse($after_logged_in2, '6. Wrong user is still logged in but should not be.');
  • trunk/tests/PrefsTest.php

    r42 r149  
    4848    }
    4949
    50     function test_getvalue()
     50    function test_getue()
    5151    {
    52         $result = $this->Prefs->getvalue(PARAM);
     52        $result = $this->Prefs->getue(PARAM);
    5353        $expected = EXPECTED_VAL;
    5454        $this->assertEquals($expected, $result);
Note: See TracChangeset for help on using the changeset viewer.