Hunt
Hunt

Reputation: 8425

Implement session in yii and extjs

I am implementing login and logout functionality in Yii and Ext JS. So far I guess I have done that. But I want to maintain a session too so that when a user refresh the ExtJS page I want to stay on a current page if a user is still logged in and if the time passed user will logged out again.

Note: I am using ajax request for login and logout

I tried reading articles but didn't figure out how to do it

http://www.yiiframework.com/forum/index.php?/topic/12124-how-to-implement-session-timeout/

I am new to yii so can anyone suggest me a roadway how to implement this functionality.

So far I have enable it in a config.php file

'session' => array (
    'class' => 'system.web.CDbHttpSession',
    'connectionID' => 'db',
    'sessionTableName' => 'sessions',
),

Upvotes: 2

Views: 141

Answers (2)

Kevin Labécot
Kevin Labécot

Reputation: 1995

I implemeted a custom login in Yii and the only thing I've to do is to "tell" to the App that someone is logged.

        $identity = new UserIdentity("login","pwd");
        // Check auth...
        // ...
        // if logging successful :
        Yii::app()->user->login($identity,3600);

Upvotes: 2

Sam Dark
Sam Dark

Reputation: 5291

In Yii "remeber me" functionality is implemented via cookies that are OK with extjs as well. So when logging in you should do something like the following:

$identity = new UserIdentity($this->username, $this->password);
if ($identity->authenticate() && $identity->errorCode === UserIdentity::ERROR_NONE) {
    $duration = 3600*24*30; // 30 days
    Yii::app()->user->login($this->_identity, $duration); // <----- here!
}

Most probably you already using Yii::app()->user->login somewhere so find it and add second argument.

Upvotes: 3

Related Questions