View Full Version : Automatically logout

4 Nov 2013, 10:47 PM

I have an idea and do not know how to implement them.

In my web-tool an user logged in (a session is created) and i want to show him a countdown, when he has been automatically logged out. When user clicked somewhere in menu or in the tabs the countdown should be restart.

I'am grateful for any ideas

4 Nov 2013, 11:38 PM
I do it by listening to events on the body:

Ext.getBody().on('click', doKeepAlive);
Ext.getBody().on('keypress', doKeepAlive);

in doKeepAlive, you can e.g. send a request to your backend to keep the session alive. You can also handle it using timers and reset the timers whenever a click or keypress occurs. See setTimeout and setInterval functions of Javascript.

5 Nov 2013, 2:27 AM
This works, but the countdown is missing.

Ext.getBody().on('click', function(){
url: 'php/weiterleben.php'

5 Nov 2013, 2:33 AM
the session management is done by the backend in my case. I send requests regularly after click and keypress events. This keeps the session from expiring on the backend and if there is no request sent for e.g. in 5 minutes, then the session has expired on the backend and on the next click or keypress, that request will return false.

5 Nov 2013, 2:34 AM
for counter etc. look at setTimeout and setInterval functions. with these, you can call some function at regular intervals to decrement a counter or do anything else.

5 Nov 2013, 11:03 PM
Thx for the replies!

I realliest it so:

function Countdown(options) {
var timer,
instance = this,
seconds = options.seconds || 10,
updateStatus = options.onUpdateStatus || function () {},
counterEnd = options.onCounterEnd || function () {};

function decrementCounter() {
if (seconds === 300){
Ext.Msg.alert('Hinweis', 'In 5 Minuten werden sie automatisch ausgeloggt.
Drücken Sie OK, um den Vorgang abzubrechen.',
function(btn, text){ if (btn == 'ok'){seconds=1440;Ext.getBody().unmask();}});
//Ext.getBody().on('click', doKeepAlive);
Ext.getBody().on('click', function(){
url: 'php/weiterleben.php'

if (seconds === 0) {
var redirect = 'login.html';
window.location = redirect;


this.start = function () {
timer = 0;
seconds = options.seconds;
timer = setInterval(decrementCounter, 1000);

this.stop = function () {
var myCounter = new Countdown({
seconds:1440, // number of seconds to count down


7 Nov 2013, 8:24 PM
I essentially had this same requirement recently, and decided to use a ux I found on these forums.


You get the monitor started on login, and stop it on logout; and provide it a function to run when a specific inactivity threshold has been reached, in this case .. you want to send the user a notice.

Worked great for my needs.