$saveHandler = Zend_Session::getSaveHandler();
$saveHandler->setLifetime($this->_globalConfig->session->params->remember_me_seconds)
->setOverrideLifetime(true);
In a global base file I start the session first:
/**
* Tell Zend_Session to use your Save Handler
*/
$sessionDbTbl = new Zend_Session_SaveHandler_DbTable($sessionConfig);
Zend_Session::setSaveHandler($sessionDbTbl);
Zend_Session::start();
AuthController/LoginAction:
/**
* do the authentication
*/
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
/**
* Check and see if the user wants to me remembered. If they are then
* their session is valid for 1 year. If not then the session dies
* when the user closes their browser.
*/
$this->_logger->debug("Remember me value {$this->_getParam('rememberme')}");
if ($this->_hasParam('rememberme') && $this->_getParam('rememberme')) {
/**
* 'remeberMe' setting is defined it the global config
*/
Zend_Session::rememberMe();
$saveHandler = Zend_Session::getSaveHandler();
$saveHandler->setLifetime($this->_globalConfig->session->params->remember_me_seconds)
->setOverrideLifetime(true);
}
$data = array();
$data['role'] = 'user';
$data['username'] = $authAdapter->getUsername();
$data['roles'] = $authAdapter->getAdRoles();
$data['displayName'] = $authAdapter->getDisplayName();
$data['email'] = $authAdapter->getEmail();
$auth->getStorage()->write($data);
On Sun, Mar 22, 2009 at 9:26 PM, kadams <kadams@gmail.com> wrote:
Thanks for the reply... I've tried a lot of permutations of this, with and
without the Zend_Session::start() lines.
Are you saying I'm inadvertently changing the namespace here? If so, I'm
guessing there is a way to assign the config to the 'Zend_Auth' session? I
haven't been able to find an example of this in any of several tutorials on
the matter.
kwylez wrote:
>
> Is there a reason why you are setting the auth adapter values into a new
> session. Zend_Auth uses it's own namespace in Zend_Session.
>
> On Sun, Mar 22, 2009 at 6:49 PM, kadams <kadams@gmail.com> wrote:
>
>>
>> Hello, I have some code like this and I'm trying to configure the Zend
>> Session created within Zend auth and so far, I've had no luck doing it:
>>
>> $db =
>> Zend_Db::factory($configuration->database); //Connection to the
>> database
>> $authAdapter = new
>> Zend_Auth_Adapter_DbTable($db);
>> $authAdapter->setTableName('users');
>>
>> $authAdapter->setIdentityColumn('user_email');
>>
>> $authAdapter->setCredentialColumn('user_password'); //Verify
>> table values with form values
>> $authAdapter->setIdentity($email);
>> $authAdapter->setCredential($password);
>> $auth = Zend_Auth::getInstance();
>> $result =
>> $auth->authenticate($authAdapter);
>> //Authenticate
>> using the adapter
>> if ($result->isValid())
>> {
>> // store the identity as an object
>> where only the username and
>> // real_name have been returned
>>
>> Zend_Session::setOptions($configuration->session->toArray());
>> Zend_Session::start ();
>> $storage = $auth->getStorage();
>> //Store all user table data except
>> password as session variables
>>
>> $storage->write($authAdapter->getResultRowObject(null, 'password'));
>> $this->view->user =
>> Zend_Auth::getInstance()->getIdentity();
>> $this->view->title = 'Welcome';
>>
>> $this->_helper->layout->setLayout('dynamiclayout');
>>
>> $this->_helper->redirector('index');
>>
>> //$this->_helper->redirector->gotoUrl('/project/project/index');
>> }
>>
>> In my config.ini file, I have:
>> session.remember_me_seconds=7200
>>
>> If I create a session using Zend_Session, without Auth, this works fine.
>> Any ideas what I am doing wrong?
>>
>> Thanks,
>> Kevin
>> --
>> View this message in context:
>> http://www.nabble.com/Configuring-Session-in-Zend_Auth-tp22652278p22652278.html
>> Sent from the Zend Auth mailing list archive at Nabble.com.
>>
>>
>
>
> --
> Cory Wiles
> kwylez@gmail.com
> http://www.corywiles.com/
> http://www.randomthoughtprocess.com/
>
>
--
View this message in context: http://www.nabble.com/Configuring-Session-in-Zend_Auth-tp22652278p22653391.html
Sent from the Zend Auth mailing list archive at Nabble.com.
--
Cory Wiles
kwylez@gmail.com
http://www.corywiles.com/
http://www.randomthoughtprocess.com/
没有评论:
发表评论