Removing goofy protected field that didn't work all the time.

Making AuthComponent::loggedIn() check the current user status.
Fixes #1694
This commit is contained in:
mark_story 2011-05-09 21:54:59 -04:00
parent 0026a6ac54
commit 339db4033f
2 changed files with 6 additions and 20 deletions

View file

@ -40,13 +40,6 @@ class AuthComponent extends Component {
const ALL = 'all';
/**
* Maintains current user login state.
*
* @var boolean
*/
protected $_loggedIn = false;
/**
* Other components utilized by AuthComponent
*
@ -511,16 +504,14 @@ class AuthComponent extends Component {
*/
public function login($user = null) {
$this->__setDefaults();
$this->_loggedIn = false;
if (empty($user)) {
$user = $this->identify($this->request, $this->response);
}
if ($user) {
$this->Session->write(self::$sessionKey, $user);
$this->_loggedIn = true;
}
return $this->_loggedIn;
return $this->loggedIn();
}
/**
@ -535,7 +526,6 @@ class AuthComponent extends Component {
$this->__setDefaults();
$this->Session->delete(self::$sessionKey);
$this->Session->delete('Auth.redirect');
$this->_loggedIn = false;
return Router::normalize($this->logoutRedirect);
}
@ -679,23 +669,19 @@ class AuthComponent extends Component {
* @param object $controller Instantiating controller
*/
public function shutdown($controller) {
if ($this->_loggedIn) {
if ($this->loggedIn()) {
$this->Session->delete('Auth.redirect');
}
}
/**
* Sets or gets whether the user is logged in
* Check whether or not the current user has data in the session, and is considered logged in.
*
* @param boolean $logged sets the status of the user, true to logged in, false to logged out
* @return boolean true if the user is logged in, false otherwise
* @access public
*/
public function loggedIn($logged = null) {
if (!is_null($logged)) {
$this->_loggedIn = $logged;
}
return $this->_loggedIn;
public function loggedIn() {
return $this->user() != array();
}
/**

View file

@ -1007,7 +1007,7 @@ class AuthTest extends CakeTestCase {
* @return void
*/
function testShutDown() {
$this->Controller->Auth->initialize($this->Controller, array('_loggedIn' => true));
$this->Auth->Session->write('Auth.User', 'not empty');
$this->Auth->Session->write('Auth.redirect', 'foo');
$this->Controller->Auth->loggedIn(true);