ColdFusion TIPS PLUS
Issue 00085 http://www.cftipsplus.com
I. My CommentsII. ColdFusion In Context: Support Login with AutoPost
By R. Martin Ladner
martin.ladner@knology.net
I. Comments:
Hope you have a Happy New Year.
Keep Coding,
Nathan Stanford
President/CEO
C.F. Concepts, Inc.
http://www.coldfusionmonthly.com
http://www.cftipsplus.com
If you have suggestions for articles send them to us.
If you would like to write for cftipsplus.com
send us an email to:
admin@cftipsplus.com
IF YOU WANT TO BE AN AUTHOR SEND IN YOUR COLDFUSION TIPS.
Remember this is a great way to get your name known in the
ColdFusion Community.
Advanced, Intensive ColdFusion Training!Visit this site. If you have plans to get training here is a company that provides Advanced, Intensive ColdFusion Training. Check them out.
http://www.coldfusiontraining.com/index.cfm?ref=cftipsplus
CFM - The ColdFusion Monthly!
http://www.ColdFusionMonthly.com
By becoming a .CFM subscriber, you'll receive. ColdFusion information you will not find anywhere else:
Tips, tricks, techniques, strategies, and a wealth of knowledge you will be able to apply immediately to your work, all from established developers.
Monthly access to new articles written by industry-leading ColdFusion experts. A fully-functional application that accompanies each issue.
Full access to all issues, past and present (with a one year paid subscription). The chance to be seen in our "Community Spotlight" corner, which showcases new writers and emerging talent
If you have any suggestions please email me at
cftips@nsnd.com.
II. ColdFusion in Context: Support Login with AutoPost
By R. Martin Ladner
martin.ladner@knology.net
Suppose you want to change pages automatically during the login process and pass information to the target page. If you're bouncing the user back to the login page, how will you do it? You could write it to a cookie, but you probably don't want to. You could stick it in a URL, but that might interfere with trying to log in again. You could leave an identifier alone that you automatically used at login (a cookie or URL, for example) and use that identifier to pull data from the server, but you probably don't want to let someone who failed to log in retain an identifier pointing to server resources. One answer to this dilemma is to use javascript to automatically submit a form to your target page.
Make a Home Page
Make a trivial login page that displays a message if the login was bad and accepts a username and password; call it home.cfm. The message, if any, will come from the page used to check the login attempt.
<cfif isDefined("form.msg")>
<cfoutput>#form.msg#</cfoutput><p>
</cfif>
(The username and password must each start with "f" for this example.)<br>
<form name="Entry" action="gate.cfm" method="post">
Username <input type="text" name="Username">
Password <input type="Password" name="Password">
<input type="submit" name="doit" value="Log in">
</form>
Make the Gate with AutoPost
Make a page that will check the login attempt and route the user accordingly; call it gate.cfm. Set variables to the full URL of the pages you might want to go to. Create an almost trivial form for javascript to work with. Then write javascript appropriate to the context: login OK or not OK. Have the javascript submit the form after filling in form variables as desired.
<cfset request.homepage="http://www.futureec.com/context/autopost/login.cfm">
<cfset request.workpage="http://www.futureec.com/context/autopost/work.cfm">
<form name="myFlag" method="post">
<input type="hidden" name="msg">
</form>
<cfset Problem=""> <!--- start with none --->
<script language="javascript">
<cfif not isDefined("form.Username") or (len(form.Username) lt 1)>
<cfset Problem="Missing Username">
<cfelseif not isDefined("form.Password") or (len(form.Password) lt 1)>
<cfset Problem="Missing Password">
<cfelseif (ucase(left(form.Username,1)) is not "F") or (ucase(left(form.Password,1)) is not "F")>
<cfset Problem="Login is not correct">
<cfelse>
document.myFlag.action=<cfoutput>"#request.workpage#"</cfoutput>;
document.myFlag.submit();
</script>
</cfif>
document.myFlag.msg.value=<cfoutput>"#Problem#"</cfoutput>;
document.myFlag.action=<cfoutput>"#request.homepage#"</cfoutput>;
document.myFlag.submit();
</script>
Make a Work Page
It doesn't matter what this page contains as long as it's not empty. Call it work.cfm.
This represents the first work page inside your application.
Try it Out; Use the Concept
Go to login.cfm. Try logging in wrong to see what happens. Try logging in right.
Once you're sure this works, include the idea in your sites. Replace the trivial login test with database queries. Set cookies for site navigation and protection. Let the login page pass variables such as page loading time or the refering page to the gate for logging. Let the gate pass such information through to the heart of your site as form variables. The sky's the limit.
=Marty=
Publisher and Creator:
Nathan Stanford,
admin@cftipsplus.com
http://www.cftipsplus.com
Macromedia and ColdFusion are U.S. registered trademarks.
Copyright (c) 2000 - 2001
CFTIPSPLUS.COM and NSND.COM
Permission is granted to circulate this publication via
MANUAL forwarding by email to friends provided that the text is
forwarded in its entirety and no fee is charged.