I've written the code below in the onRequestStart method of my Application.cfc. So whenever a request comes before the session value creation it will always redirect to login_action.cfm.
<cfif not IsDefined("session.active")>
<cfinclude template="login_action.cfm">
</cfif>
In the login_action.cfm is code for blocking the access of other pages without a proper authentication:
<cfif NOT (IsDefined ("Form.username") AND IsDefined ("Form.password"))>
<cfinclude template="login.cfm">
<cfabort>
<cfelse>
Now I created a signup page. This page doesn't need an authentication. Everyone should able to go that page by a single click, but now it is not possible without login. Can I change this by checking the targtedPage argument of onRequestStart method somehow?
Can someone help me?
Question:
Can I check with this by the targtedPage (sic) argument of onRequestStart method?
Answer
Yes.
Using your existing code structure and making a presumption of calling your signup page signup_page.cfm you can do the following.
<cffunction
name="OnRequestStart"
access="public"
returntype="boolean"
output="false"
hint="Fires at first part of page processing.">
<!--- Define arguments. --->
<cfargument
name="TargetPage"
type="string"
required="true" />
<cfif FindNoCase( "signup_page.cfm", arguments.TargetPage)>
<!--- User is at the signup page, no need to check for an active session. Do stuff if necessary here. --->
<cfelse>
<cfif not IsDefined("session.active")>
<!--- User's session is inactive, redirect --->
<cfinclude template="login_action.cfm">
<cfreturn false /> <!--- You should add this return in your existing code. --->
</cfif>
<!--- User is logged in with an active session, do other stuff. --->
</cfif>
<!--- Return out. --->
<cfreturn true />
</cffunction>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With