Yii 1.1: timeout-dialog

Displays a timeout popover after a certain period of time.
24 followers

Timeout-dialog is a JQuery plugin that displays a timeout popover after a certain period of time. The timeout dialog should be used whenever you want to display to the user that the logged in session is about to expire. It creates a light box with a countdown and options to stay signed in or sign out.

Requirements

Yii 1.1.x, jQuery.ui core script

Usage

In your layout view:

<?php
    $this->widget('ext.timeout-dialog.ETimeoutDialog', array(
        // Get timeout settings from session settings.
        'timeout' => Yii::app()->getSession()->getTimeout(),
        // Uncomment to test.
        // Dialog should appear 20 sec after page load.
        //'timeout' => 80,
        'keep_alive_url' => $this->createUrl('/site/keepalive'),
        'logout_redirect_url' => $this->createUrl('/site/logout'),
    ));
?>

In your SiteController:

/**
 * Keep the session alive, called by timeout-dialog.
 */
public function actionKeepAlive()
{
    echo 'OK';
    Yii::app()->end();
}

Resources

Credit

timeout-dialog.js was developed by rigoneri.

Version History

  • 1.2 — 2013-02-27
    • Fix for Yii 1.1.13 jQuery UI update.
  • 1.1 — 2012-08-03
    • Make the widget inherit from CJuiWidget class for better integration.
    • Fixes and updates to CSS.
  • 1.0 — 2012-07-05
    • Initial release.

Total 6 comments

#15640 report it
Daniel at 2013/12/02 11:41pm
many open tabs can automatically logout the session

Thank you for great extension.

I am using this extension on all of my projects. However, being web based, I sometimes utilize browser tab for user to get information on some places. User can open different information on different tabs.

Some of my users reported that when opening the app on more than one tab (at least two tabs), they occasionally logged out and need to re-login to continue their works. It should not reached the time out since they were still working (entrying data or just clicking some buttons). While, it did not happen to user that only open the app in one tab.

Can you help me with this?

Cheers,

Daniel

#14453 report it
speaki at 2013/08/13 12:42am
settings.restarted

i dont know but i cant get this to work whitout adding settings.restarted and move window.clearInterval(self.countdown);

Like:

startCountdown: function() {
        var self = this,
            counter = settings.countdown;
            settings.restarted = true;
 
        this.countdown = window.setInterval(function() {
          counter -= 1;
          counterDisplay = counter + ' sekunder';
          if(counter>60){ counterDisplay = Math.round(counter/60) + ' minuter'; }
 
          $("#timeout-countdown").html(counterDisplay);
 
 
          if (counter <= 0 && settings.restarted) {
           self.signOut(false);
          }
 
        }, 1000);
      },
 
      keepAlive: function() {
        var self = this;
        this.destroyDialog();
        $.get(settings.keep_alive_url, function(data) {
        data = $.trim(data);
          if (data == "OK") {
            if (settings.restart_on_yes) {
                settings.restarted = false;
                window.clearInterval(self.countdown);
                self.setupDialogTimer();
            }
          }
          else {
            self.signOut(false);
          }
        });
      },

otherwise it will logout even if i have klicked "Keep me logged in"

#14390 report it
speaki at 2013/08/08 03:44am
timeout

should timeout not contain of both:

Yii::app()->user->authTimeout
Yii::app()->getSession()->getTimeout()

Like:

$timeout = Yii::app()->user->authTimeout > Yii::app()->getSession()->getTimeout() ? Yii::app()->getSession()->getTimeout() : Yii::app()->user->authTimeout;
#14381 report it
speaki at 2013/08/07 10:17am
$.trim(data)

I was forced to add data = $.trim(data) on:

keepAlive: function() {
        var self = this;
        this.destroyDialog();
        $.get(settings.keep_alive_url, function(data) {
        data = $.trim(data);
          if (data == "OK") {
            if (settings.restart_on_yes) {
              self.setupDialogTimer();
            }
          }
          else {
            self.signOut(false);
          }
        });
      },

when using:

public function actionKeepAlive()
{
    echo 'OK';  
    Yii::app()->end();
}
#8910 report it
Daniel at 2012/07/06 07:23pm
Link to session expired?

Nice extension.

Could you help me on link this with yii built in session expired?

what should I put in here ???

<?php $this->widget('ext.timeout-dialog.ETimeoutDialog', array( 'timeout' => ???, 'keep_alive_url' => $this->createUrl('/site/keepalive'), 'logout_redirect_url' => $this->createUrl('/site/logout'), )); ?>

Cheers

#8894 report it
Junior - df9 at 2012/07/06 07:15am
Cool

thanks very much for sharing! =))

Leave a comment

Please to leave your comment.

Create extension