Timeout Dialog Doesnot Popup At The Set Time While Using Session

Hi All,

I am using the timeout-dialog plugin to create a 1 min timeout for each user who is logged into the system. I have used session to achieve the same. The code I am using is as below:

Layout/main.php




<?php

if(yii::app()->user->hasState('userSessionTimeout')){

	$this->widget('ext.timeout-dialog.ETimeoutDialog', array(

            'timeout' => Yii::app()->user->getState('userSessionTimeout') - time(),

            'countdown' => 5,

            'title' => 'Timeout',

            'logout_redirect_url' => $this->createUrl('/site/SessionTimeout'),

            'keep_alive_url' => $this->createUrl('/site/keepAlive'),

            'keep_alive_button_text' => 'Keep',

            'sign_out_button_text' => 'Signout',

            'restart_on_yes' => true,

	));

}



The session is set once the user is logged into the system.

Yii::app()->user->setState(‘userSessionTimeout’, time()+60); sets the session to 1 min

Components/UserIdentity.php




public function authenticate()

	{

		$users=array(

			// username => password

			'demo'=>'demo',

			'admin'=>'admin',

		);

		if(!isset($users[$this->username]))

			$this->errorCode=self::ERROR_USERNAME_INVALID;

		elseif($users[$this->username]!==$this->password)

			$this->errorCode=self::ERROR_PASSWORD_INVALID;

		else{

			$this->errorCode=self::ERROR_NONE;

                        Yii::app()->user->setState('userSessionTimeout', time()+60']);

                }

		return !$this->errorCode;

	}



At all times, the user should only be allowed to use the system for 1 min at which time the dialog pops up and gives option to stay logged in or logout.

Now first time when the session expires, the control is transferred to sitecontroller/actionKeepAlive() if user still wants to continue using the system and sitecontroller/actionSessionTimeout() if the user wants to logout.

SiteController:




public function actionKeepAlive() {

        Yii::app()->user->setState('userSessionTimeout', time()+60);

   

        echo 'ok';

        Yii::app()->end();

    }




public function actionSessionTimeout()

        {

                unset(Yii::app()->session['userSessionTimeout']);

                Yii::app()->user->logout();

                $this->render('sessiontimeout');

        }



Now here is the scenario:

The website has many menu options. the file where the timeout dialog widget is used is in main.php which means it is called when you press different menu options in the webpage at which time it has to calulate the timeout value dyanmically which fails in my case.

However, if you stay idle by just logging into the system and not using any menu option in the webpage, the value is set correctly and the dialog appears every 1 min correctly.\

So basically its all messed up when the value has to be calculated dynamically and assigned to timeout.

Anyone who has used the timeout dialog, please do help.

Thanks.