Coldandfuzzy wrote:
I have :
<cfif #SESSION.usrlogin# neq "true">
<a href="login.cfm">login</a>
<cfelse>
Page Content
</cfif>
I'd like the cflocation in the login action page to be
generic enough to resuse sitewide so the user, upon logging in from
here, is redirected to the page they were trying to view.
If you're on MX7.x or CF8.x, then there is at least one
solution that fits your three themes of session, login and
requested page. It makes use of Application.cfc.
In Application.cfc
===============
<cffunction name="onRequestStart">
<cfargument name = "targetPage" type="String"
required=true >
<cfif (NOT isDefined("session.isUsrLogggedIn") or NOT
session.isUsrLoggedIn) and (NOT listLast(CF_TEMPLATE_PATH,"\") is
"loginPage.cfm")>
<cfset session.requestedpage=arguments.targetpage>
<cflocation url="loginPage.cfm">
</cfif>
</cffunction>
loginPage.cfm
===============
<h2>login page</h2>
To simulate login, press the button. Then Coldfusion will log
you in and redirect you to the page you originally requested.
<p>
<cfif isDefined("form.loggedIn")>
<!--- validation code goes in here --->
<!--- The following code is the kind that will run if
validation is successful --->
<cfset session.isUsrLoggedIn = true>
<cflocation url="#session.requestedpage#">
</cfif>
<form action="#cgi.script_name#" method="post">
<input name="loggedIn" value="Press to simulate login"
type="Submit">
</form>
edited: changed login boolean to session.isUsrLoggedIn