Changeset 149
- Timestamp:
- Jun 5, 2006 2:34:47 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Auth_File.inc.php
r148 r149 112 112 * @access public 113 113 */ 114 function clear Auth()114 function clear() 115 115 { 116 116 $_SESSION[$this->_ns] = array('authenticated' => false); … … 202 202 $username = strtolower(trim($username)); 203 203 204 $this->clear Auth();204 $this->clear(); 205 205 206 206 if (!$this->authenticate($username, $password)) { -
trunk/lib/Auth_SQL.inc.php
r148 r149 252 252 * @access public 253 253 */ 254 function clear Auth()254 function clear() 255 255 { 256 256 $db =& DB::getInstance(); … … 274 274 * @param mixed $val Value to set variable to. 275 275 */ 276 function set Val($key, $val)276 function set($key, $val) 277 277 { 278 278 if (!isset($_SESSION[$this->_ns]['user_data'])) { … … 365 365 $this->initDB(); 366 366 367 $this->clear Auth();367 $this->clear(); 368 368 369 369 if (!$user_data = $this->authenticate($username, $password)) { … … 402 402 403 403 // No login: user is blocked! 404 $this->clear Auth();404 $this->clear(); 405 405 return false; 406 406 } … … 437 437 $db->query("DELETE FROM " . $this->_params['db_login_table'] . " WHERE " . $this->_params['db_primary_key'] . " = '" . $this->get('user_id') . "'"); 438 438 // No login: reset password because of account abuse! 439 $this->clear Auth();439 $this->clear(); 440 440 return false; 441 441 } … … 569 569 570 570 // User is not authenticated. 571 $this->clear Auth();571 $this->clear(); 572 572 return false; 573 573 } -
trunk/lib/Lock.inc.php
r146 r149 55 55 $app =& App::getInstance(); 56 56 57 if (!method_exists($auth_object, 'get Val') || !method_exists($auth_object, 'getUsername')) {57 if (!method_exists($auth_object, 'get') || !method_exists($auth_object, 'getUsername')) { 58 58 trigger_error('Constructor not provided a valid Auth_* object.', E_USER_ERROR); 59 59 } … … 183 183 } 184 184 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->get Val('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__); 186 186 /// FIX ME: What if admin set lock, but public user is current lock user? 187 187 $this->data['editor'] = $this->_auth->getUsername($this->data['set_by_admin_id']); … … 218 218 $qid = $db->query("SELECT * FROM " . $db->escapeString($this->getParam('db_table')) . " WHERE lock_id = '" . $db->escapeString($this->data['lock_id']) . "'"); 219 219 if ($lock = mysql_fetch_assoc($qid)) { 220 return ($lock['set_by_admin_id'] == $this->_auth->get Val('user_id'));220 return ($lock['set_by_admin_id'] == $this->_auth->get('user_id')); 221 221 } else { 222 222 return false; … … 268 268 '" . $db->escapeString($record_val) . "', 269 269 '" . $db->escapeString($title) . "', 270 '" . $db->escapeString($this->_auth->get Val('user_id')) . "',270 '" . $db->escapeString($this->_auth->get('user_id')) . "', 271 271 NOW() 272 272 ) … … 318 318 // Delete specific user's locks. 319 319 $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->get Val('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__); 321 321 } else { 322 322 // Delete ALL locks. 323 323 $db->query("DELETE FROM " . $db->escapeString($this->getParam('db_table')) . ""); 324 $app->logMsg(sprintf('All record locks deleted by %s %s', $this->_auth->get Val('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__); 325 325 } 326 326 } -
trunk/lib/Prefs.inc.php
r147 r149 18 18 var $_params = array( 19 19 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 20 26 // Enable database storage. 21 27 'enable_db' => true, … … 26 32 // Automatically create table and verify columns. Better set to false after site launch. 27 33 'create_table' => true, 28 29 // The current user_id for which to load/save preferences.30 'user_id' => null,31 34 ); 32 35 … … 132 135 function setDefaults($defaults) 133 136 { 137 $app =& App::getInstance(); 134 138 if (isset($defaults) && is_array($defaults)) { 135 139 // 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__); 136 141 $_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__); 137 143 } 138 144 } … … 146 152 function set($key, $val) 147 153 { 148 $_SESSION[$this->_ns]['data'][$key] = $val; 154 if ('' != $key && '' != $val) { 155 $_SESSION[$this->_ns]['data'][$key] = $val; 156 } 149 157 } 150 158 … … 185 193 186 194 /** 187 * Empty the $_SESSION cache. 195 * Empty the $_SESSION cache. This should be executed with the same consideration as $auth->clear() 188 196 */ 189 197 function clear() … … 238 246 // Data loaded only once per session. 239 247 $_SESSION[$this->_ns]['loaded'] = true; 248 $_SESSION[$this->_ns]['load_datetime'] = date('Y-m-d H:i:s'); 240 249 241 250 return true; … … 243 252 244 253 /* 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. 246 256 * 247 257 * @access private … … 253 263 function _isLoaded() 254 264 { 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 } 256 273 } 257 274 … … 294 311 $insert_values = array(); 295 312 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 } 297 316 } 298 317 $db->query(" -
trunk/lib/Version.inc.php
r146 r149 61 61 $app =& App::getInstance(); 62 62 63 if (!method_exists($auth_object, 'get Val') || !method_exists($auth_object, 'getUsername')) {63 if (!method_exists($auth_object, 'get') || !method_exists($auth_object, 'getUsername')) { 64 64 trigger_error('Constructor not provided a valid Auth_* object.', E_USER_ERROR); 65 65 } … … 202 202 '" . $db->escapeString($title) . "', 203 203 '" . $db->escapeString($notes) . "', 204 '" . $db->escapeString($this->_auth->get Val('user_id')) . "',204 '" . $db->escapeString($this->_auth->get('user_id')) . "', 205 205 NOW() 206 206 ) … … 363 363 while ($row = mysql_fetch_assoc($qid)) { 364 364 // Get admin usernames. 365 $row['editor'] = $this->_auth->get Val('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']); 366 366 $versions[] = $row; 367 367 } -
trunk/services/logout.php
r147 r149 5 5 */ 6 6 7 if (isset($auth) && method_exists($auth, 'get Val')) {7 if (isset($auth) && method_exists($auth, 'get')) { 8 8 // Delete the current user's record locks. 9 9 require_once 'codebase/lib/Lock.inc.php'; … … 13 13 14 14 // Logout. 15 $auth->clear Auth();15 $auth->clear(); 16 16 17 17 $app->raiseMsg(sprintf(_("Your session has been logged-out."), null), MSG_SUCCESS, __FILE__, __LINE__); -
trunk/tests/Auth_FileTest.php
r136 r149 48 48 } 49 49 50 function test_clear auth()50 function test_clear() 51 51 { 52 52 $result = $this->Auth_File->login('testuser', 'testpass'); 53 $this->Auth_File->clear auth();53 $this->Auth_File->clear(); 54 54 $this->assertFalse($_SESSION[$this->Auth_File->_ns]['authenticated'], 'testuser authentication not false in session.'); 55 55 } … … 61 61 $this->assertTrue($true, 'testuser not logged in but should be.'); 62 62 63 $this->Auth_File->clear auth();63 $this->Auth_File->clear(); 64 64 $false = $this->Auth_File->isloggedin(); 65 65 $this->assertFalse($false, 'testuser is logged in but shouldn\'t be.'); -
trunk/tests/Auth_SQLTest.php
r136 r149 67 67 } 68 68 69 function test_set val()70 { 71 $this->Auth_SQL->set val('testuserkey', 'testuserval');69 function test_set() 70 { 71 $this->Auth_SQL->set('testuserkey', 'testuserval'); 72 72 $this->assertEquals('testuserval', $_SESSION[$this->Auth_SQL->_ns]['user_data']['testuserkey']); 73 73 } 74 74 75 function test_get val()75 function test_get() 76 76 { 77 77 $_SESSION[$this->Auth_SQL->_ns]['user_data']['testuserkey'] = 'testuserval'; 78 $val = $this->Auth_SQL->get Val('testuserkey');78 $val = $this->Auth_SQL->get('testuserkey'); 79 79 $this->assertEquals('testuserval', $val); 80 80 } … … 95 95 } 96 96 97 function test_clear auth()97 function test_clear() 98 98 { 99 99 $login = $this->Auth_SQL->login('testuser', 'testpass'); … … 101 101 $before_logged_in = $this->Auth_SQL->isloggedin(); 102 102 $this->assertTrue($before_logged_in, 'User is not logged in, but should be.'); 103 $this->Auth_SQL->clear auth();103 $this->Auth_SQL->clear(); 104 104 $after_logged_in = $this->Auth_SQL->isloggedin(); 105 105 $this->assertFalse($after_logged_in, 'User is still logged in but should not be.'); … … 123 123 $before_logged_in = $this->Auth_SQL->isloggedin(); 124 124 $this->assertTrue($before_logged_in, '2. User is not logged in, but should be.'); 125 $this->Auth_SQL->clear auth();125 $this->Auth_SQL->clear(); 126 126 $after_logged_in = $this->Auth_SQL->isloggedin(); 127 127 $this->assertFalse($after_logged_in, '3. User is still logged in but should not be.'); … … 132 132 $before_logged_in2 = $this->Auth_SQL->isloggedin(); 133 133 $this->assertFalse($before_logged_in2, '5. User is logged in, but should not be.'); 134 $this->Auth_SQL->clear auth();134 $this->Auth_SQL->clear(); 135 135 $after_logged_in2 = $this->Auth_SQL->isloggedin(); 136 136 $this->assertFalse($after_logged_in2, '6. Wrong user is still logged in but should not be.'); -
trunk/tests/PrefsTest.php
r42 r149 48 48 } 49 49 50 function test_get value()50 function test_getue() 51 51 { 52 $result = $this->Prefs->get value(PARAM);52 $result = $this->Prefs->getue(PARAM); 53 53 $expected = EXPECTED_VAL; 54 54 $this->assertEquals($expected, $result);
Note: See TracChangeset
for help on using the changeset viewer.