PDA

View Full Version : Keeping a domino session alive



dominodeviant
11 Sep 2008, 10:45 PM
I am looking for a way to keep the active Domino user session alive for some users to prevent time outs.

Something like the below:

http://my.advisor.com/doc/18210

http://notesweb2.blogspot.com/2006/08/keep-domino-web-session-alive-with.html

http://roberthanson.blogspot.com/2005/11/prototypejs-periodicalexecuter.html

Is there a way I could use the above with only sticking to Ext.nd?


Thanks in advance

-Darko

jratcliff
12 Sep 2008, 9:21 AM
Hmm, that sounds like a good enhancement to add to Ext.nd. Not sure where to add it but I'll talk it over with Rich. In the meantime take a look at Ext.TaskMgr

http://extjs.com/deploy/dev/docs/?class=Ext.TaskMgr

For the run property you could specify a function that would just make an Ext.Ajax call (be sure to set disableCaching: true) to the server, perhaps to the s.gif icon in the Ext.nd database which you can get from Ext.BLANK_IMAGE_URL since we set it for you. Set your interval so that it will run every few minutes and I would think this would work.

mdm-adph
15 Sep 2008, 7:50 AM
Hey -- if you ask me, timeouts are an important security feature. They'd be painfully easy to remove (just "ping" the server with a Ajax command every 20 minutes or so), but if you ask me, getting rid of them isn't really the answer.

I use a script like this to just put up a login box in whatever Ext application that I'm working with that'll sign the user back in and fire the last Ajax command that was attempted:


/*

DOMINO Server ExtJS "Server Timeout" Script

@author mdm-adph

@release 0.1

@license This script is licensed under the terms of
the Open Source LGPL 3.0 license. Commercial use is permitted to the extent
that the code/component(s) do NOT become part of another Open Source or Commercially
licensed development library or toolkit without explicit permission.

License details: http://www.gnu.org/licenses/lgpl.html

@usage Insert into your overrides file -- script will run automatically whenever
the Domino login page is returned from the server during the course of an
Ajax call. In your original callback, you will need to check for the presence
of a new response variable ("serverTimeout"), because this script will not stop
you original callback from firing.

Automatically tries to fire the last attempted Ajax request upon successful login with
the Domino server.

*/

// Place this variable whereever you want -- it doesn't have to be in the global spec.
// Just make sure to update the script below if you move it.
var AJAXTIMEOUTCTRL = {
VARS: {},
OBJ: {}
};

Ext.Ajax.on({
"requestcomplete": function(conn, response, options){

// Hide progress msg windows here if necessary
// Example: Ext.Msg.hide();

// If "timeout" page has been returned
if (response.responseText.indexOf('action="/names.nsf?Login"') !== -1)
{
// Cache last "true" ajax request, if this failed request isn't a login page
if (options.url != "/names.nsf?Login")
{
AJAXTIMEOUTCTRL.VARS.lastFailedAjaxRequest = options;
}

// Function run after user fills in reauthentication form
function serverLogin() {

AJAXTIMEOUTCTRL.OBJ.dominoLogin.hide();
Ext.Msg.wait("Getting authorization from server...", "Please Wait");
var password = Ext.getCmp("dominoLogin-password").getValue();
var username = Ext.getCmp("dominoLogin-username").getValue();
Ext.getCmp("dominoLogin-password").reset();
Ext.getCmp("dominoLogin-username").reset();

Ext.Ajax.request({
url: "/names.nsf?Login",
params: {
password: password,
username: username
// , RedirectTo: <url>
// an added parameter "RedirectTo" can be added here if necessary
// to direct the Domino server to return a different page than normal
// upon successful login. This can be used to return updated server
// variables, user access levels, etc.
},
callback: function (options, success, response) {
if (success && !response.serverTimeout)
{
// Hide progress msg windows here if necessary
// Example: Ext.Msg.hide();

Ext.Msg.alert("Alert", "Your connection with the server has been reestablished.");

// Try to run the initially requested ajax
Ext.Ajax.request(AJAXTIMEOUTCTRL.VARS.lastFailedAjaxRequest);
}
}
});
}; // end serverLogin()

// Create dominoLogin window object if not already created
if (!AJAXTIMEOUTCTRL.OBJ.dominoLogin)
{
AJAXTIMEOUTCTRL.OBJ.dominoLogin = new Ext.Window({
bodyStyle: "padding: 5px;",
border: false,
closable: false,
height: 160,
layout: "form",
labelAlign: "top",
modal: true,
plain: true,
resizable: false,
title: "Server Authentication Needed",
width: 315,

buttons: [{
text: 'OK',
handler: serverLogin
}],

items: [{
xtype: "textfield",
fieldLabel: "Username",
id: "dominoLogin-username",
width: "100%",
value: "" // Add a variable holding current user's name here if necessary
},{
xtype: "textfield",
fieldLabel: "Password",
id: "dominoLogin-password",
inputType: "password",
width: "100%",
listeners: {
"specialkey": function (theField, e) {
if (e.getKey() == e.ENTER) {
serverLogin();
}
}
}
}]

});
} // end if (!AJAXTIMEOUTCTRL.OBJ.dominoLogin)

AJAXTIMEOUTCTRL.OBJ.dominoLogin.show();

// Delay the focus on the password input box, since the DOM doesn't like focusing while
// it's still manipulating things
Ext.getCmp("dominoLogin-password").focus(false, 500);

// Create additional response flag here so that initial ajax request's callback
// doesn't run
response.serverTimeout = true;

} // end if "timeout" page
}
});

I'm curious to see if this'll work in others' applications, too, so feel free to try. :D

Joe
1 Apr 2009, 1:33 PM
....
I'm curious to see if this'll work in others' applications, too, so feel free to try. :D

Yes, it works.

Implemented this in a test db and it worked well - very slick.

Thanks for posting that great slice of code!

mdm-adph
2 Apr 2009, 12:58 PM
Thanks! I've actually got an updated version here and there -- will try and steralize it so I can stick it up here.

Joe
3 Apr 2009, 2:33 PM
I really like the Ajax hook. This can even be used to "precheck" before doing non-ajax calls (i.e. open in a frame, but still want to assure you are still connected).

We have a complex app with tabs that can open other forms, etc. After thinking this through I think a nice solution would be to have the system "stay alive" until the user activity stops for a period of time. Then do the countdown timer and "lock the app" (and log out of the server). The page will have the username / password prompt up until they return and log back in. At this point the tabs are still open and security is re-established and will again stay that way until they log out/lock the screen or again, become dormant.

If they just close the browser without a log out - then the app is no longer sends the stay alive pings and will time out naturally.

Just some random thoughts. If we implement such a solution - I'll let you know how it goes. If you can see any potential issues with the above solution, i'd love to hear about it :)

Thanks again for the great code.

mdm-adph
10 Apr 2009, 8:51 AM
I really like the Ajax hook. This can even be used to "precheck" before doing non-ajax calls (i.e. open in a frame, but still want to assure you are still connected).

We have a complex app with tabs that can open other forms, etc. After thinking this through I think a nice solution would be to have the system "stay alive" until the user activity stops for a period of time. Then do the countdown timer and "lock the app" (and log out of the server). The page will have the username / password prompt up until they return and log back in. At this point the tabs are still open and security is re-established and will again stay that way until they log out/lock the screen or again, become dormant.

If they just close the browser without a log out - then the app is no longer sends the stay alive pings and will time out naturally.

Just some random thoughts. If we implement such a solution - I'll let you know how it goes. If you can see any potential issues with the above solution, i'd love to hear about it :)

Thanks again for the great code.

Thanks -- I was really proud of that hook as well. I've actually hooked into the "beforerequest" and "requestexception" listeners, too, in the full code -- I guess I just need to post my entire libraries here one day, or on OpenNTF.org. It's not very easy code to get started with, but if you're working with Domino and ExtJS and already know your way around stuff, I'm sure somebody would find it useful.

About the "stay-alive," though -- is the typical 30-minute session time (if it's not different on your servers) not adequate? I've never really had to bother with stay-alive scripts -- anything like that is a big no-no where I work!

tsetford
6 May 2009, 4:12 PM
I just found this thread and your code worked great! Taking it one step further, how would you go about automatically firing multiple ajax calls after a successfull login? I have certain user driven events that make multiple ajax requests and if the session timeout happens before one of these events, it only fires the last ajax request. Any help would be greatly appreciate.

Joe
7 May 2009, 6:49 AM
If you can't catch / cache the failed ones then you may want to chain your requests. Depending on your process it may be easy to setup to run ajax call 2 on the response of ajax call 1 and so on.

mdm-adph
8 May 2009, 6:16 AM
I just found this thread and your code worked great! Taking it one step further, how would you go about automatically firing multiple ajax calls after a successfull login? I have certain user driven events that make multiple ajax requests and if the session timeout happens before one of these events, it only fires the last ajax request. Any help would be greatly appreciate.

I agree with what Joe said there. I don't know if you'll have to change your code greatly or not, but the only way to do it would be to chain the ajax events together using their callback functions -- that way the "chain" can be stopped and started depending upon the user login script.