Dear Friend
I found the solution.
But I hope there may be better solutions.
1.In main configuration file declare authTimeout.
main.php
'components'=>array(
'user'=>array(
'allowAutoLogin'=>true,
'authTimeout'=>300, // 5 minutes.
),
2.In main layout file add a container to display flash messages.Preferrably before the main contents.
main.php
........................
<div id="timeout"></div>
<?php echo $content; ?>
........................
3.Register the following script at the bottom of main layout file.
If we specifically set the authTimeout in CWebUser, CWebUser::updateAuthStatus regenerates
the authTimeout for every request for authenticated user.
We catch the authTimeout and updating it in the following script.
If user becomes idle, authTimeout will not be updated.
Then we are going to throw flash message 10 seconds before the specified timeout.It counts down to 0 second.
main.php
<?php
$user=Yii::app()->user;
if(!$user->getIsGuest())
{
$time= ($user->getState(CWebUser::AUTH_TIMEOUT_VAR) - time()-10)*1000;//converting to millisecs
Yii::app()->clientScript->registerSCript('timeoutAlert','
setTimeout(function()
{
var n=10;
setInterval(function()
{
if(n>0)$("#timeout").addClass("flash-error").text("Your session will expire in "+n+" seconds");
if(n==0) {
$("#timeout").text("Your session has expired!");clearInterval();
}
--n;
},1000)
},
'.$time.')
',CClientScript::POS_END);
}
?>
I added the alert message to the class flash-error.
Pop up windows with disabled background are much better option.
I hope somebody can make it better.
Regards.