PDA

View Full Version : Automatically logout



blade226
4 Nov 2013, 10:47 PM
Hi,

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

Farish
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.

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

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

Farish
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.

Farish
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.

blade226
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() {
updateStatus(seconds);
if (seconds === 300){
Ext.getBody().mask();
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(){
myAjax.request({
url: 'php/weiterleben.php'
});
seconds=1440;

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

}
seconds--;
}

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

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

myCounter.start();

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

http://www.sencha.com/forum/showthread.php?155346

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.