Adobe COLDFUSION 9 Manual page 360

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
<cfcomponent>
<cfset This.name = "Orders">
<cffunction name="OnRequestStart">
<cfargument name = "request" required="true"/>
<cflogin>
<cfif IsDefined("cflogin")>
<cfif cflogin.name eq "admin">
<cfset roles = "user,admin">
<cfelse>
<cfset roles = "user">
</cfif>
<cfloginuser name = "#cflogin.name#" password = "#cflogin.password#"
roles = "#roles#" />
<cfelse>
<!--- This should never happen. --->
<h4>Authentication data is missing.</h4>
Try to reload the page or contact the site administrator.
<cfabort>
</cfif>
</cflogin>
</cffunction>
</cfcomponent>
Reviewing the code
The Application.cfc
onRequestStart
more information on the Application.cfc page and when it is executed, see
Application" on page 235.
The following table describes the CFML code in Application.cfc and its function:
Code
<cfcomponent>
<cfset This.name = "Orders">
<cffunction name="OnRequestStart">
<cfargument name = "request" required="true"/>
<cflogin>
<cfif IsDefined("cflogin")>
<cfif cflogin.name eq "admin">
<cfset roles = "user,admin">
<cfelse>
<cfset roles = "user">
</cfif>
<cfloginuser name = "#cflogin.name#" password =
"#cflogin.password#" roles = "#roles#" />
<cfelse>
<!--- This should never happen. --->
<h4>Authentication data is missing.</h4>
Try to reload the page or contact the site
administrator.
<cfabort>
</cfif>
</cflogin>
</cffunction>
</cfcomponent>
method executes before the code in each ColdFusion page in an application. For
Description
Identifies the application and starts the
runs at the starts of each request. The login information on this page only
applies to this application.
Executes if there is no logged-in user.
Makes sure that the user is correctly logged in by the web server.
(Otherwise, there would be no cflogin variable.)
Sets a roles variable based on the user's ID. Assigns users named "admin"
to the admin role. Assigns all other users to the users role.
Logs the user into the ColdFusion security system and specifies the user's
password, name, and roles. Gets the password and name directly from the
cflogin structure.
This code should never run, but if the user somehow got to this page
without logging in to the web server, this message would display and
ColdFusion would stop processing the request.
Ends the if/else block.
Ends the
cflogin
Ends the
onRequestStart
Ends the Application component.
Last updated 8/5/2010
"Designing and Optimizing a ColdFusion
onRequestStart
tag body.
method.
355
method that

Advertisement

Table of Contents
loading

Table of Contents