2009年9月13日星期日

[fw-auth] Odd behaviour with storage cookie.

<p>Hi</p>
<p>I'm using a Storage_Cookie like
http://metaversedeveloper.com/2009/01/03/logging-in-users-via-zend_auth-without-sessions-in-php-zend-framework/
http://metaversedeveloper.com/2009/01/03/logging-in-users-via-zend_auth-without-sessions-in-php-zend-framework/
I only add json_encode/decode
to manage the not scalar data.</p>
<p>I've had trouble with the logout method because the
$auth->hasIdentity() was still true after the logout action.<p>
<p>I end up with this code and it works but I seem to see just a little odd
</p>
<pre>
public function clear()
{
if (!setcookie($this->_cookieName,
false, // clears the cookie
time()-$this->_expire,
$this->getBasedir())) {
throw new Zend_Auth_Storage_Exception('Failed to clear cookie');
}
/* odd ! */
unset($_SESSION[$this->_cookieName]);
unset($_COOKIE[$this->_cookieName]);
}

<p>In my bootstrap</p>
<pre>
protected function _initAuth()
{
$auth = Zend_Auth::getInstance();
if(null !== W_Cookie::get('wh')){
$auth->setStorage(new W_Auth_Storage_Cookie(md5('ayn'),
md5('ayn')));
}
else{
$auth->setStorage(new Zend_Auth_Storage_Session(md5('ayn')));
}
Zend_Registry::set('auth', $auth);
}
<p>In my controller</p>
<pre>
LOGIN
W_Cookie::deleteCookie('wh');
if(!empty($remember)){
W_Cookie::setCookie('wh',md5(time()));
$this->auth->setStorage(new
W_Auth_Storage_Cookie(md5('ayn'), md5('ayn')));
}
$this->auth->getStorage()->write($data);

LOGOUT
W_Cookie::deleteCookie('wh');
$this->auth->clearIdentity();
$this->_helper->redirector('index','index','default');


<p>Does anyone know why ?</p>
<p>Thanks in advance</p>
<p>Bye</p>
--
View this message in context: http://www.nabble.com/Odd-behaviour-with-storage-cookie.-tp25422786p25422786.html
Sent from the Zend Auth mailing list archive at Nabble.com.

没有评论: