Datatribe Softwerks, Ltd.

<< LotusScript: Thinking Class | Home | Tip: Quick and Dirty Search Export>>

Design: Ajax Powered Login

Wed 8 Mar 2006

Prepared just for Show and Tell Thursday!
By Mark Barton with Jerry Carter

Getting tired of ugly Domino login forms or faceless browser pop up dialogs? Once again showing a flair for melding various techniques, Mark Barton brings us an elegant, cutting edge modal login interface utilizing DHTML, Ajax, and JSON JavaScript notation.

Updated Jan 14 2009 - our apologies, the demo is no longer available for download.

Introduction

This article will explain how to have a cross browser modal Domino login form which will gracefully inform the user if they have not successfully logged in. This is not a new topic, and many of our peers have discussed it before. But with the growing popularity of robust, cross browser JavaScript libraries, we have an opportunity to do this in a really beautiful way without much effort.

Jake has already mentioned before about the need for an embedded login form. It's true our options are limited with stock Domino, but this technique provides a way that Jake can have his embedded login but gives us the option to go a slight bit further.

Building on top of Yogis example and utilizing the power of the Prototype script library, along with the visual simplicity of the extended Lightbox script written by Particletree we arrive at our demo page

How it works

The technique relies on the following prerequisites:

  • The server is running Session based authentication for the required domain
  • The code relies on the Prototype script library
  • Assumes the standard error message returned by a failed authentication is in English (I will explain why below).

AJAX Login

We'll need a few pieces to put this all together, starting with the Login Page (in this case, literally a page design element. We've been using a lot more pages in our designs to get the control over Domino we want.) It just has your basic UI bits showing the user where to click to login to the application.

When the user clicks the login link this calls the login method from the login Object - this JavaScript object can be found in the JavaScript library - login.js.

NB I should point out the JavaScript code is written in JSON format - which has many advantages to procedural JavaScript - for more info on this read JSON for the masses either way it should still make sense

The first thing this code does is display a processing graphic (just unhides it) - this is good practice when performing any AJAX calls as it lets the user know something is happening.

Next it will URL escape the username and password and then, using Prototype's AJAX request method, perform a HTTP Post to - http://DominoServer/Names.nsf?login with our users login credentials.

NB In case you're new to logins and authentication, passwords and ID's are always passed as clear text over http:// whether using GET or POST. The only way to address this is to use SSL, which gets you https:// (s for secure). You can get SSL certificates for your server fairly cheap these days, but getting one and applying one to your server are both beyond the scope of this article.

This will result in the Domino server either returning some HTML informing the user of a any potential login problem. This response content is passed to the onComplete handler which looks, specifically, for the text "Invalid username or password was specified." This is where internationalisation may be an issue - you just need to make sure the boolean test conditions correspond to what your Domino server returns.

NB Check out the DomBulletin template on OpenNTF for some crafty ideas on internationalising web interfaces with js libraries.

If the string is found (meaning a login error), the user is informed via an alert, the input fields are cleared and the "processing" graphic is hidden again.

If the string was not found, then we have a successful login and we're free to accommodate the user with access to secured features or content. In my case I just reload the current page, but you could route them to a new page, trigger an email, make the screen colors flash like a Vegas slot machine, you're call. Handling the response through our Ajax mechanism means our outcome is JavaScript driven, which means the options are wide open.

Lightbox

To get the login box to display in a modal fashion - rather than embedding the whole form in the current page we use the Particletree script.

NB Yes, you can embed the form. But, we're all about unambiguous functionality, so making the login form the center of focus and shading the rest of the page seems about as straight forward and unambiguous as you can get, to us anyway. One could argue usability but it's really a pure look and feel issue. Do as you like (or as are requested by your customer!)

The script that comes with Lihtbox is very simple but has a limitation in that its not set up to resize the container DIV which holds the modal form without some modification. This might be addressed in later versions, but for now it suits our purpose anyway.

The original demo also has styling for a specific use: popping-over photos. This may not really be suitable for your idea of a modal form, so take heart that modifications are not too difficult. In this case, the CSS file that comes with the Lightbox demo was modified to make the content DIV have a transparent background to suit Mark's taste - the choice of how you integrate these elements is of course yours.

Once you have included or linked the script library and CSS file in your page all you need to do is make sure the "Login" link has a class of lbOn (short for Lightbox On), you can have multiple classes as in the example.

e.g.

Login to the Application

What the script does, when clicking on the above, is pull in the contents of the response via an AJAX call and then display it in a pseudo modal dialogue.

NB WC3 allows multi-classing with a blank space delimiter. This is a great way to modularize your CSS, in case you'd never seen it (Jerry just abused this technique liberally on a large project for speed and ease of control over many styles and pages). Most modern browsers support this functionality. If you need to support NS4 or IE5, you may want to do some testing first.

The Lightbox script can pull any HTML content into the Lightbox also making it useful for help or instructional pop-overs. Just make sure your display DIVs have an overflow property so a scroll bar can be displayed if its too large (e.g.: overflow:auto.)

Conclusion

The techniques displayed here propose a way to utilize the latest and greatest scripts to enhance your Domino applications in an accessible and usable (not to mention pleasing) way without exerting great effort. No doubt, with the blazing speed at which new and more powerful libraries are being brought to public notice, achieving similar effect in the near future will have more variations and options. But, for the moment, this offers very slick presentation with ease of implementation. Sounds good, eh?

Updated Jan 14 2009 - our apologies, the demo is no longer available for download.

P.S. don't forget to have at look at the JSON method of writing JavaScript.

Comments are currently disabled. Feel free to use the contact form.

Reader Contributions:

Alastair (09/03/2006 14:21)

Mark, Some your doing some great work in this area. Have you looked at Sarissa as well instead of prototype.js, regards, Alastair

Jerry (03/09/2006 04:35 PM)

For those who are curious about Sarissa, here is a link to it on sourceforge. I havn't had a look yet so can make no recommendation or warranty. :-)

http://sourceforge.net/projects/sarissa

jens (25.03.2007 18:49) e-mail

hello mark and jerry,

thanks for this solution. short question: is it possible to reload the page underneath the lightbox, while the lightbox is open?

Jerry (27/03/2007 17:20)

Hello Jens!

If you put your lightbox and page contents in different divs, you can use ajax to reload the page in the background by loading it, getting the html from the ajax responder and setting the innerHTML of the page div equal to the returned html.

A structure like this would do it.

<body>
<div id=page>
reloaded with ajax on command x or event y from source z, perhaps an event in the lightbox itself
</div>
<div id=lihtbox>
</div>
</body>

so, no special magic, just careful arrangement of elements.

I should note I have not tried this myself, but since our modal dialog with the lightbox is really just an illusion, I see no reason it would not work.

Mark (03/28/2007 12:25 AM)

Hi Jens,

I agree with Jerry. In fact in the 'old' days this would be a frameset ;-)

But watch out the same cavets apply to framesets as with this technique i.e. Page history and navigation.

Mark

Dietrich (05/09/2007 05:14 PM) e-mail

Excellent article. I used it in my latest project.

I made two additions.

1. When querying names.nsf, take account of the type of server it is on,

var hostname=location.hostname;
var url = location.protocol + '//'+location.hostname +'/names.nsf?login';

2. To deal with situations where there is no slash as the last character in the url address, the return location adds a slash when necessary.

lenHttp = window.location.href.length;
lastLetter = window.location.href.charAt(lenHttp-1);

if (lastLetter != "/") {
if (window.location.href.match(".nsf") == ".nsf") {
window.location = window.location+ "/"
} else {
window.location = window.location
}
} else {
window.location = window.location
}

Jerry (05/09/2007 17:29)

Cheers Dietrich. Glad to hear of it being put to use! Nice addition also. Can you tell us what type of server omits the / ?

Dietrich (12/09/2007 06:47 PM) e-mail

I've noticed it at the company I have just been working for and another company I was previously working for. They both ran a version of 6.5.

I've tried duplicating it at home but failed. As well as the 6.5 version, I tried it on versions 7 and 8. Both showed no problems.

What I did discover was that the login failed response has changed as of version 7.

In version 6.5, the response is, "You provided an invalid username or password".

In versions 7 and 8, the response is "Invalid username or password was specified".

Notice the i of invalid has been capitalised.

So, the code,

test=originalRequest.responseText.indexOf("invalid username or password");


will always give -1 in versions 7 and 8.

I chose to delete the i of invalid. Otherwise, you could transform originalRequest.responseText to lowercase

cheers

Mark Manwaring (09/18/2007 07:33 AM) e-mail

Hi

The link isn't working for the demo database

Can someone please send me the link

Thanks

Jerry (18/09/2007 17:27)

I've sent for updated links from the hosting provider (our dear Mr. Barton). I'll get the links fixed up as soon as possible.




March, 2006
SMTWTFS
   01 02 03 04
05 06 07 08 09 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Articles by Month
Articles by Category
Features Downloads
Recommended