Refactoring SessionHelper and SessionComponent

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4512 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-02-12 21:46:17 +00:00
parent 2847ba7f82
commit 53254d9a0f
3 changed files with 28 additions and 29 deletions

View file

@ -81,13 +81,13 @@ class SessionComponent extends CakeSession {
if ($this->__active === true) {
if(is_array($name)) {
foreach($name as $key => $value) {
if ($this->writeSessionVar($key, $value) === false) {
if (parent::write($key, $value) === false) {
return false;
}
}
return true;
}
if ($this->writeSessionVar($name, $value) === false) {
if (parent::write($name, $value) === false) {
return false;
}
return true;
@ -106,7 +106,7 @@ class SessionComponent extends CakeSession {
*/
function read($name = null) {
if ($this->__active === true) {
return $this->readSessionVar($name);
return parent::read($name);
}
return false;
}
@ -120,7 +120,7 @@ class SessionComponent extends CakeSession {
*/
function del($name) {
if ($this->__active === true) {
return $this->delSessionVar($name);
return parent::del($name);
}
return false;
}
@ -148,7 +148,7 @@ class SessionComponent extends CakeSession {
*/
function check($name) {
if ($this->__active === true) {
return $this->checkSessionVar($name);
return parent::check($name);
}
return false;
}
@ -161,7 +161,7 @@ class SessionComponent extends CakeSession {
*/
function error() {
if ($this->__active === true) {
return $this->getLastError();
return parent::getLastError();
}
return false;
}
@ -242,7 +242,7 @@ class SessionComponent extends CakeSession {
*/
function valid() {
if ($this->__active === true) {
return $this->isValid();
return parent::isValid();
}
return false;
}
@ -253,7 +253,7 @@ class SessionComponent extends CakeSession {
*/
function destroy() {
if ($this->__active === true) {
$this->destroyInvalid();
parent::destroy();
}
}
}

View file

@ -157,7 +157,7 @@ class CakeSession extends Object {
* @return boolean True if variable is there
* @access public
*/
function checkSessionVar($name) {
function check($name) {
$var = $this->__validateKeys($name);
if (empty($var)) {
return false;
@ -192,8 +192,8 @@ class CakeSession extends Object {
* @return boolean Success
* @access public
*/
function delSessionVar($name) {
if ($this->checkSessionVar($name)) {
function del($name) {
if ($this->check($name)) {
$var = $this->__sessionVarNames($name);
if (empty($var)) {
return false;
@ -247,7 +247,7 @@ class CakeSession extends Object {
* @return mixed The value of the session variable
* @access public
*/
function readSessionVar($name = null) {
function read($name = null) {
if (is_null($name)) {
return $this->returnSessionVars();
}
@ -282,7 +282,7 @@ class CakeSession extends Object {
* @param string $value
* @return void
*/
function writeSessionVar($name, $value) {
function write($name, $value) {
$var = $this->__validateKeys($name);
if (empty($var)) {
@ -321,7 +321,7 @@ class CakeSession extends Object {
* @return void
* @access private
*/
function destroyInvalid() {
function destroy() {
$sessionpath = session_save_path();
if (empty($sessionpath)) {
$sessionpath = "/tmp";
@ -442,20 +442,20 @@ class CakeSession extends Object {
*
*/
function __checkValid() {
if ($this->readSessionVar("Config")) {
if ($this->_userAgent == $this->readSessionVar("Config.userAgent") && $this->time <= $this->readSessionVar("Config.time")) {
$this->writeSessionVar("Config.time", $this->sessionTime);
if ($this->read("Config")) {
if ($this->_userAgent == $this->read("Config.userAgent") && $this->time <= $this->read("Config.time")) {
$this->write("Config.time", $this->sessionTime);
$this->valid = true;
} else {
$this->valid = false;
$this->__setError(1, "Session Highjacking Attempted !!!");
$this->destroyInvalid();
$this->destroy();
}
} else {
srand ((double)microtime() * 1000000);
$this->writeSessionVar("Config.userAgent", $this->_userAgent);
$this->writeSessionVar("Config.time", $this->sessionTime);
$this->writeSessionVar('Config.rand', rand());
$this->write("Config.userAgent", $this->_userAgent);
$this->write("Config.time", $this->sessionTime);
$this->write('Config.rand', rand());
$this->valid = true;
$this->__setError(1, "Session is valid");
}

View file

@ -72,7 +72,7 @@ class SessionHelper extends CakeSession {
*/
function read($name = null) {
if ($this->__active === true) {
return $this->readSessionVar($name);
return parent::read($name);
}
return false;
}
@ -86,7 +86,7 @@ class SessionHelper extends CakeSession {
*/
function check($name) {
if ($this->__active === true) {
return $this->checkSessionVar($name);
return parent::check($name);
}
return false;
}
@ -99,7 +99,7 @@ class SessionHelper extends CakeSession {
*/
function error() {
if ($this->__active === true) {
return $this->getLastError();
return parent::getLastError();
}
return false;
}
@ -114,16 +114,15 @@ class SessionHelper extends CakeSession {
*/
function flash($key = 'flash') {
if ($this->__active === true) {
if ($this->checkSessionVar('Message.' . $key)) {
e($this->readSessionVar('Message.' . $key));
$this->delSessionVar('Message.' . $key);
if (parent::check('Message.' . $key)) {
e(parent::read('Message.' . $key));
parent::del('Message.' . $key);
} else {
return false;
}
}
return false;
}
/**
* Used to check is a session is valid in a view
*
@ -131,7 +130,7 @@ class SessionHelper extends CakeSession {
*/
function valid() {
if ($this->__active === true) {
return $this->isValid();
return parent::isValid();
}
}
}