Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 362

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
This example has three ColdFusion pages:
• The Application.cfc page contains the authentication logic that checks whether a user is logged in, requests the
login page if the user is not logged in, and authenticates the data from the login page. If the user is authenticated, it
logs the user in.
This page also includes the one-button form and logic for logging out a user, which appears at the top of each page.
• The loginform.cfm page displays the login form. The code on this page could also be included in Application.cfc.
• The securitytest.cfm page is a sample application page. It displays the logged-in user's roles.
Test the security behavior by adding your own pages to the same directory as the Application.cfc page.
The example gets user information from the LoginInfo table of the cfdocexamples database that is installed with
ColdFusion. You can replace this database with any database containing UserID, Password, and Roles fields. The
sample database contains the following data:
UserID
Password
BobZ
Ads10
JaniceF
Qwer12
RandalQ
ImMe
Because spaces are meaningful in roles strings, do not follow the comma separators in the Roles fields with spaces.
Example: Application.cfc
The Application.cfc page consists of the following:
<cfcomponent>
<cfset This.name = "Orders">
<cfset This.Sessionmanagement="True">
<cfset This.loginstorage="session">
<cffunction name="OnRequestStart">
<cfargument name = "request" required="true"/>
<cfif IsDefined("Form.logout")>
<cflogout>
</cfif>
<cflogin>
<cfif NOT IsDefined("cflogin")>
<cfinclude template="loginform.cfm">
<cfabort>
<cfelse>
<cfif cflogin.name IS "" OR cflogin.password IS "">
<cfoutput>
<h2>You must enter text in both the User Name and Password fields.
</h2>
</cfoutput>
<cfinclude template="loginform.cfm">
<cfabort>
<cfelse>
<cfquery name="loginQuery" dataSource="cfdocexamples">
SELECT UserID, Roles
FROM LoginInfo
WHERE
Roles
Employee,Sales
Contractor,Documentation
Employee,Human Resources,Manager
Last updated 1/20/2012
357

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents