Contents[hide] |
Let's assume the entry point to your application is index.asp, and it is structured as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <link rel="stylesheet" type="text/css" href="/igs/includes/ext/resources/css/ext-all.css"> <script type="text/javascript" src="/igs/includes/ext/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="/igs/includes/ext/ext-all.js"></script> <script type="text/javascript" src="login.js"></script> </head> <body></body> </html>
Obviously, modify the paths to your EXT directory accordingly. See the source for Login.js below
Next comes login.js. This guy handles all the heavy lifting, and for me, has all the pieces I was missing coming from a more traditional way of thinking about user authentication. It creates the form, renders it to a popup window, presents the window to the user, sends the submission via ajax, and handles the success and failure response depending on whether your user entered successful credentials.
Here is the server processing for your login. I'm going to paste the following overly simplistic code to show the responses that go back, and ultimately determine which function in login.js fires (success or failure). However, this is where you would make the call to the database with the username/password variables, do your authentication, and then send either of these responses depending on whether or not what the user provided a valid set of credentials.
<% if request.form("loginUsername") = "f" then response.write "{ success: true}" else response.write "{ success: false, errors: { reason: 'Login failed. Try again.' }}" end if %>
<?php $loginUsername = isset($_POST["loginUsername"]) ? $_POST["loginUsername"] : ""; if($loginUsername == "f"){ echo "{success: true}"; } else { echo "{success: false, errors: { reason: 'Login failed. Try again.' }}"; } ?>
<cfsetting showdebugoutput="No"> <cfif form.loginUsername eq "f"> <cfset result = "{success: true}"> <cfelse> <cfset result="{success: false, errors: { reason: 'Login failed. Try again.' }}"> </cfif> <cfoutput>#result#</cfoutput>
You will notice a line in login.js that redirects to Test.asp if a successful login happens. This can obviously be whatever page your main application will be. In my situation, users can have any number of combinations of navigation options, so the next step would be to validate with whatever session management mecahanism you use, that the person accessing test.asp is authenticated to do so. Further, I would pull down whatever navigation options are assigned to that user and build my toolbar accordingly. Since I'm still trying to figure that part out, that will be another tutorial :)
Hopefully this is somewhat helpful and thanks again to crafter for most of the js code.