Link to home
Start Free TrialLog in
Avatar of rudodoo
rudodoo

asked on

Converting an Application.cfm to Application.CFC

I'm having trouble converting 2 application.cfm files to an application.cfc.  I have put comments in my code snippet to help in asking the questions.

The first application.cfm file is the main root of my web application and the 2nd one has to do with the login directory.  

I'm also having trouble setting up an error handling framework using the code already created (FYI - I didn't help create it)

I'll attach the first application.cfm file on the snippet in this post and I'll post the 2nd application.cfm file right after it so you'll be able to tell which ones are which

My goal is to set up the error handling framework as well as have my web app work the way its supposed to when a user logs in.

Can someone please point me in the right direction I'm having a little trouble.  I know what to do regarding the onApplicationStart but its the other functions (ie onSession and onRequest) that I'm having trouble with
<!--- HERE IS THE FIRST AND MAIN APPLICATION.CFM FILE -------------->
<!--- go get the global vars PRETTY CERTAIN THIS GOES IN THE OnApplicationStart Function--->
<cfset request.MY_Datasource = "MY_Datasource">
	<cfset request.MY_Datasource2 = "MY_Datasource2">
	<cfset request.MY_Datasource3 = "MY_Datasource3">
	<cfset request.MY_Datasource4 = "MY_Datasource4">
	<cfset request.MY_Datasource5 = "MY_Datasource5">
	<cfset request.time=20>
         <cfset request.default_email=myEmailAddress
<!--- is the DB alive? This checks to make sure the database is working correctly however I'm not sure if it works anymore --->
<cfif not( CGI.SERVER_NAME EQ "MyIP" ) and request.debug EQ 0>
	<cfmodule template="includes/customtags/dbcheck.cfm">
</cfif>
 
<!--- setup the session vars via an application instance --->
<!--- Should make note to users, cookies are required --->
<cfapplication name="MyApp" 
			sessionmanagement="Yes"
            sessiontimeout="#createtimespan(0,0,request.time,0)#">
 
<!--- this is supposed to make the cfid/cftoken cookie expire when the browser closes--->
<cfset Variables.cfid_local = Cookie.CFID>
<cfset Variables.cftoken_local = Cookie.CFTOKEN>
<cfcookie name="CFID" value="#Variables.cfid_local#">
<cfcookie name="CFTOKEN" value="#Variables.cftoken_local#">
 
<!--- Move Session to Request FOR READS ONLY!!!--->
<cflock timeout="30" throwontimeout="No" type="READONLY" scope="SESSION">
	<cfset structappend(request,Duplicate(session))>
</cflock>
 
 
<cfparam name="request.show_js_message" default=true>
<cfif NOT isdefined("request.login")>
	<cflocation url="#request.root#/login/index.cfm" addtoken="no">
<cfelseif request.login NEQ "yes">
	<cflocation url="#request.root#/login/index.cfm" addtoken="no">
<cfelseif request.show_js_message eq true>
	<!---script>This isn't used anymore');</script>
	<cfset request.show_js_message = false--->
</cfif>
 
<cfset curr_time = timeformat( now(), "HHmmss" )>
<cfset start_down_time = "220000">
<cfset end_down_time = "070000">
<!---Not sure what this really does but left in code to make sure it doesn't mess anything up--->
<cfquery name="status" datasource="#request.DATASOURCE#">
	select * from table where commrun = (select max(commrun) from commruns)
</cfquery> 
 
<!--- if the time is during the down time or cycles are running, display the message --->
<cfif (((curr_time GT start_down_time or curr_time LT end_down_time)) or (commrunstatus.status NEQ "C" and commrunstatus.status NEQ "Z")) and FindNoCase('OCS/',cgi.PATH_INFO,1) and cgi.SERVER_NAME neq 'liwzs31b'>
	<cflocation url="#request.root#/dsp_ocsdown.cfm" addtoken="no">
	<cfabort>
</cfif>
 
<!--- This is an error template.  I don't think it works anymore Is there a way to make it work? --->
<cfif request.debug NEQ 1>
	<cferror type="EXCEPTION" template="#request.root#/includes/customtags/errortemplate_excp.cfm" mailto="#request.default_email#">
	<cferror type="REQUEST" template="#request.root#/includes/customtags/errortemplate.cfm" mailto="#request.default_email#">
</cfif>
<!---  global container for oft used queries/SQL --->
<!--- store the cycles query in the request scope...wchich goes into the session scope too --->
<cfif NOT IsDefined("request.cycledates")>
	<cfquery name="GETCYCLEdata" datasource="#request.DATASOURCE#" cachedwithin="#CreateTimeSpan(0,1,0,0)#">
		SELECT		*
		FROM		table
		ORDER BY 	cyclecode, cd DESC
	</cfquery>
	<cfset request.cycledates = GETCYCLEdata>
</cfif>
 
<!--- store the cycles query in the request scope...wchich goes into the session scope too --->
<cfif NOT IsDefined("request.markets")>
	<cfquery name="GetData" datasource="#request.DATASOURCE#" cachedwithin="#CreateTimeSpan(0,1,0,0)#">
		SELECT		*
		FROM		table
		ORDER BY 	COLUMN
	</cfquery>
	<cfset request.markets = GetData>
</cfif>
<!--- People in particular groups get a longer session --->
<CFQUERY name="get_normal_Groups" datasource="#request.DATASOURCE#" cachedwithin="#CreateTimeSpan(0,15,0,0)#">
	select * from table
	where groupid  in (myGroupIDs) and groupname = '#request.groupname#'
</CFQUERY>
<!--- People in particular groups get a longer session --->
<CFQUERY name="get_Special_Groups" datasource="#request.DATASOURCE#" cachedwithin="#CreateTimeSpan(0,15,0,0)#">
	select * from table
	where groupid  in (myGroupIDs) and groupname = '#request.groupname#'
</CFQUERY>
<!--- Determines which users receive which session time out limits --->
<CFIF get_normal_Groups.recordcount GTE 1>
	<CFSET request.time = 240>
<CFELSEIF get_Special_Groups.recordcount GTE 1>
	<CFSET request.time = 60>
<cfelseif FindNoCase('something',cgi.path_info )>
	<CFSET request.time = 60>
<cfelse>
	<CFSET request.time = 20>
</CFIF>
 
<cfapplication name="MyApp" 
			sessionmanagement="Yes"
            sessiontimeout="#createtimespan(0,0,request.time,0)#">
 
<!---HERE IS THE 2ND APPLICATION.CFM FILE THAT HANDLES I BELIEVE THE LOGIN PROCESS I'M WONDERING IF I CAN JUST EXTEND THIS FROM THE MAIN APPLICATION.CFM FILE WHEN I CONVERT IT TO AN APPLICATION.CFC-------->
 
 
<!----------------------------------------------------------------------->
<!--- I BELIEVE THIS CAN BE EXTENDED FROM THE ORIGINAL APPLICATION.CFC
 
Purpose:  This is the application.cfm file for the login dir.  Do not do a 
		login check in here.  This dir will not be secure, so don't put 
			anything good in it.
--->
<!----------------------------------------------------------------------->
<!--- go get the global vars These is used on the main application.cfm file so do I even need this here --->
<cfinclude template="GlobalVars.cfm">
 
<!---End of Setting global variables--->
 
<!--- is the DB alive? --->
<cfif not( CGI.SERVER_NAME EQ 'DEV_ServerName' OR CGI.SERVER_NAME EQ "Dev_IP" ) and request.debug EQ 0>
	<cfmodule template="../includes/customtags/dbcheck.cfm">
</cfif>
 
<!--- setup the session vars via an application instance --->
<!--- Should make note to users, cookies are required --->
<cfapplication name="MY_APP"
               sessionmanagement="Yes"
               setclientcookies="Yes"
               sessiontimeout="#createtimespan(0,0,request.time,0)#">
 
<!--- this is supposed to make the cfid/cftoken cookie expire when the browser closes--->
<cfset Variables.cfid_local = Cookie.CFID>
<cfset Variables.cftoken_local = Cookie.CFTOKEN>
<cfcookie name="CFID" value="#Variables.cfid_local#">
<cfcookie name="CFTOKEN" value="#Variables.cftoken_local#">
 
<!--- These are used on act_login.cfm to allow admins to log in as anyone --->
<cfif CGI.SERVER_NAME EQ 'DEV_ServerName' OR CGI.SERVER_NAME EQ "Dev_IP">
	
	<CFSET admin_ssn = "USER_SSN">
	<CFSET admin_pin = "USER_pin">	
</CFIF>
			   
<!--- Move Session to Request Not sure what to do with this--->
<cflock timeout="30" throwontimeout="No" type="READONLY" scope="SESSION">
	<cfset structappend(request,Duplicate(session))>
</cflock>
 
<!--- This is another error handling template How should I handle this if I want to convert these 2 Application.cfc to a CFC
 
If you notice the mailto values equal variables from the main application.cfm file.  Do I really need them here as well--->
<cfif request.debug NEQ 1>
	<cferror type="EXCEPTION" template="#request.root#/includes/customtags/errortemplate_excp.cfm" mailto="#request.default_email#">
	<cferror type="REQUEST" template="#request.root#/includes/customtags/errortemplate.cfm" mailto="#request.default_email#">
</cfif>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of azadisaryev
azadisaryev
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial