Link to home
Start Free TrialLog in
Avatar of mahpog
mahpog

asked on

OnRequestStart - Security Sign on and Request Page Setup together

I have made use of the Application.cfc and the OnRequestStart to require a security signon. I have a new application that uses the OnRequestStart to setup the Request argument for each page processes.

I need to add the security feature but I do not know how to get both to work under OnRequestStart. I tried to copy one with the other and got error saying "missing /cffunction" . I also tried naming one as "OnRequestStart" and the other as "OnRequest"  Result: I either get the secuirty screen working but it will no longer go to the index.cfm page. Or I get to my index.cfm without a needed security signon.

How do I get both to work>>>??????

Here is my code:

<cfcomponent
      output="false"
      hint="Handles the application-level event handlers and application settings.">
      
      
      <!--- Define application settings. --->
           <cfset THIS.Name = "events" />
        <cfset THIS.sessionmanagement="Yes">
        <cfset THIS.clientmanagement="Yes">
        <cfset THIS.setclientcookies="Yes">
        <cfset THIS.loginstorage="session">
        <cfset THIS.sessiontimeout="#createtimespan(0,1,0,0)#">
        <cfset THIS.applicationtimeout="#createtimespan(0,4,0,0)#">

        <cfset REQUEST.Source = "RQITest" />

      <!--- Define page request settings. --->
      <cfsetting
            showdebugoutput="true"
            requesttimeout="20"
            />

      
  <cffunction name="onApplicationStart" returnType="boolean" output="false">
    <!--- When did the application start? --->
    <cfset APPLICATION.appStarted = now()>

    <cfreturn true>
  </cffunction>

  <cffunction name="onApplicationEnd" returnType="void" output="false">
    <cfargument name="appScope" required="true">

    <!--- Log how many minutes the application stayed alive --->
    <cflog file="#THIS.name#" text=
"App ended after #dateDiff('n',ARGUMENTS.appScope.appStarted,now())# minutes.">

  </cffunction>


      <cffunction
            name="OnRequest">
            
                  <!--- If user is not logged in, force them to now --->
      <cfif NOT IsDefined("Session.Auth.IsloggedIn")>
      <!--- If the user is now submitting "login" form, include Login Check" code to validate user --->
                  <cfif IsDefined("Form.UserLogin")>
                              <cfinclude template="home/LoginCheck.cfm">
                  </cfif>
            
            <cfinclude template="home/Login.cfm">
       <cfabort>
      </cfif>
  </cffunction>      
 


<cffunction
            name="OnRequestStart"
            access="public"
            returntype="boolean"
            output="false"
            hint="Fires the initial pre-page processing event.">
            
            <!--- Define arguments. --->
            <cfargument
                  name="Page"
                  type="string"
                  required="true"
                  hint="The ColdFusion script who's execution has been requested."
                  />
            

            <cfset REQUEST.DSN = StructNew() />
            <cfset REQUEST.DSN.Source = "RQITest" />
            <cfreturn true />
      </cffunction>

      
            
</cfcomponent>
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America 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
Avatar of mahpog
mahpog

ASKER

Both examples worked great. I am happy to see a solution. I have all the Coldfusion Books, and there are no examples of combined situations as mine. Thanks!