Users are warned about expiring session.
This is simple implementation of session timeout warning. Plugin does not make any ajax calls, otherwise it would not work with many projects. Components like RBAC are using user identity all time and auth session is renewed every request.
This plugin writes and reads cookies.
It supports multiple tabs. Plugin will not work if user is logged out from server side, or sessions are cleared from database.
If user session is expired, page will be reloaded.
Either run
$ php composer.phar require mg-code/yii2-session-timeout-warning "@dev"
or add
"mg-code/yii2-session-timeout-warning": "@dev"
to the require
section of your composer.json
file.
- Register bootstrap class in application config.
[
'bootstrap' => [
[
'class' => \mgcode\sessionWarning\components\SessionWarningBootstrap::className(),
'initMessages' => true,
]
],
];
initMesscompoages
property initializes translations.
Currently only English and Latvian languages are supported.
Please contribute and add your language.
- Add controller to controllerMap in application config.
[
'controllerMap' => [
'session-warning' => [
'class' => 'mgcode\sessionWarning\controllers\SessionWarningController',
],
],
];
Note: If you are using RBAC, you should allow all visitors to access this controller.
- Insert widget in layout view.
<?= \mgcode\sessionWarning\widgets\SessionWarningWidget::widget([
//... Properties ...
]); ?>
Properties:
logoutUrl
- if is set, logout button will be shown before Continue button. Default: nullextendUrl
- url where ajax request is sent, when continue button is clicked. Default: ['/session-warning/extend']warnBefore
- time in seconds before user is warned about expiring session. Default: 300 (5min)