diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index 6e02e13d37f..7dd94840ea7 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -21,6 +21,7 @@ App::import('Core', 'Router', false); App::import('Core', 'Security', false); +App::import('Core', 'CakeSession', false); App::import('Component', 'auth/base_authorize'); /** @@ -159,7 +160,7 @@ class AuthComponent extends Component { * @var string * @link http://book.cakephp.org/view/1276/sessionKey */ - public $sessionKey = 'Auth.User'; + public static $sessionKey = 'Auth.User'; /** * If using action-based access control, this defines how the paths to action @@ -445,7 +446,7 @@ public function constructAuthorize() { * * You can use allow with either an array, or var args. * - * `$this->Auth->allow(array('edit', 'add'));` + * `$this->Auth->allow(array('edit', 'add'));` or * `$this->Auth->allow('edit', 'add');` * * allow() also supports '*' as a wildcard to mean all actions. @@ -475,7 +476,7 @@ public function allow() { * * You can use deny with either an array, or var args. * - * `$this->Auth->deny(array('edit', 'add'));` + * `$this->Auth->deny(array('edit', 'add'));` or * `$this->Auth->deny('edit', 'add');` * * @param mixed $action Controller action name or array of actions @@ -534,7 +535,7 @@ public function login($user = null) { $user = $this->identify($this->request); } if ($user) { - $this->Session->write($this->sessionKey, $user); + $this->Session->write(self::$sessionKey, $user); $this->_loggedIn = true; } return $this->_loggedIn; @@ -550,7 +551,7 @@ public function login($user = null) { */ public function logout() { $this->__setDefaults(); - $this->Session->delete($this->sessionKey); + $this->Session->delete(self::$sessionKey); $this->Session->delete('Auth.redirect'); $this->_loggedIn = false; return Router::normalize($this->logoutRedirect); @@ -563,16 +564,15 @@ public function logout() { * @return mixed User record. or null if no user is logged in. * @link http://book.cakephp.org/view/1264/user */ - public function user($key = null) { - $this->__setDefaults(); - if (!$this->Session->check($this->sessionKey)) { + public static function user($key = null) { + if (!CakeSession::check(self::$sessionKey)) { return null; } if ($key == null) { - return $this->Session->read($this->sessionKey); + return CakeSession::read(self::$sessionKey); } else { - $user = $this->Session->read($this->sessionKey); + $user = CakeSession::read(self::$sessionKey); if (isset($user[$key])) { return $user[$key]; } diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 94f3b8d7b84..1f3a2a49b4d 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -1178,8 +1178,7 @@ function testComponentSettings() { 'Auth' => array( 'fields' => array('username' => 'email', 'password' => 'password'), 'loginAction' => array('controller' => 'people', 'action' => 'login'), - 'userModel' => 'AuthUserCustomField', - 'sessionKey' => 'AltAuth.AuthUserCustomField' + 'userModel' => 'AuthUserCustomField' ), 'Session' ); @@ -1212,14 +1211,12 @@ function testComponentSettings() { 'fields' => array('username' => 'email', 'password' => 'password'), 'loginAction' => array('controller' => 'people', 'action' => 'login'), 'logoutRedirect' => array('controller' => 'people', 'action' => 'login'), - 'userModel' => 'AuthUserCustomField', - 'sessionKey' => 'AltAuth.AuthUserCustomField' + 'userModel' => 'AuthUserCustomField' ); $this->assertEqual($expected['fields'], $this->Controller->Auth->fields); $this->assertEqual($expected['loginAction'], $this->Controller->Auth->loginAction); $this->assertEqual($expected['logoutRedirect'], $this->Controller->Auth->logoutRedirect); $this->assertEqual($expected['userModel'], $this->Controller->Auth->userModel); - $this->assertEqual($expected['sessionKey'], $this->Controller->Auth->sessionKey); } /**