1 Reply Latest reply on Feb 26, 2007 10:33 AM by Newsgroup_User

    HELP ME with CFLogin and Application.cfc

    fbs70
      I am trying to get a login scenario that is similar in functionality to what adobe.com has. When you click on account it takes you to a login page where you enter your username and password. once you login you are directed to you a “YOUR ACCOUNT PAGE” which is in a secure directory. All of this I can do with the login scenario that I have created using an application.cfc within my personal directory.

      But what I am having a hard time doing is when the user returns to the home page of the site, I would like to display that the user is logged in with a “Welcome Username” and a link to their “Account” page as well as a logout link.

      What I have in my root application.cfc is this

      <webroot>/Application.cfc
      <cfcomponent>
      <!--- set Application settings --->
      <cfset this.name="OurCompany">
      <cfset this.loginStorage="session">
      <cfset this.sessionManagement="true">
      <cfset this.setClientCookies="false">
      <cfset this.sessionTimeout = createTimeSpan(0,0,30,0)> <!--- 30 minutes --->
      <cfset this.applicationTimeout=CreateTimeSpan(0,0,30,0)> <!--- 30 minutes --->

      <cferror type="request" template="/error/errorrequest.cfm" mailto="me@OurCompany.com">
      <cferror type="exception" template="/error/errorexception.cfm" mailto=" me@ OurCompany.com ">
      <cferror type="validation" template="/error/errorvalidation.cfm" mailto=" me@ OurCompany .com ">


      <cffunction name="OnApplicationStart" output="false" returntype="void">
      <cfset Application.dataSource = "ourDB">
      <cfset Application.companyname="Company Name">
      </cffunction>

      <cffunction name="onRequestStart" returnType="boolean" output="true">

      <cfreturn true>
      </cffunction>

      <cffunction name="onError" returntype="void" output="false">
      <cfargument name="exception" required="yes">
      <cfargument name="eventName" type="string" required="yes">

      <!--- use the cflog tag to record info on the error --->
      <cfif arguments.eventName is "">
      <cflog file="#this.name#" type="error" text="#arguments.exception.message#">
      <cfelse>
      <cflog file="#this.name#" type="error" text="Error in Method [#arguments.eventname#] #arguments.exception.message#">
      </cfif>

      <!--- Let the <cferror> tags to their job --->
      <cfthrow object="#arguments.exception#">
      </cffunction>
      </cfcomponent>

      I also have an ApplicationProxy.cfc which just extends my Application.cfc
      <webroot>/ApplicationProxy.cfc
      <cfcomponent extends="Application">
      </cfcomponent>


      Personal/Application.cfc (directory that i want secured)
      <cfcomponent extends="ApplicationProxy">
      <cfset this.name=" OurCompany_personal">

      <cffunction name="onRequestStart" returnType="boolean" output="true">
      <cfinclude template="/forceuserlogin.cfm">
      <cfreturn true>
      </cffunction>
      </cfcomponent>
        • 1. Re: HELP ME with CFLogin and Application.cfc
          Level 7
          fbs70 wrote:
          > I am trying to get a login scenario that is similar in functionality to what
          > adobe.com has. When you click on account it takes you to a login page where
          > you enter your username and password. once you login you are directed to you a
          > ?YOUR ACCOUNT PAGE? which is in a secure directory. All of this I can do with
          > the login scenario that I have created using an application.cfc within my
          > personal directory.
          >
          > But what I am having a hard time doing is when the user returns to the home
          > page of the site, I would like to display that the user is logged in with a
          > ?Welcome Username? and a link to their ?Account? page as well as a logout link.
          >
          > What I have in my root application.cfc is this
          >
          > <webroot>/Application.cfc
          > <cfcomponent>
          > <!--- set Application settings --->
          > <cfset this.name="OurCompany">
          > <cfset this.loginStorage="session">
          > <cfset this.sessionManagement="true">
          > <cfset this.setClientCookies="false">
          > <cfset this.sessionTimeout = createTimeSpan(0,0,30,0)> <!--- 30 minutes --->
          > <cfset this.applicationTimeout=CreateTimeSpan(0,0,30,0)> <!--- 30 minutes --->
          >
          > <cferror type="request" template="/error/errorrequest.cfm"
          > mailto="me@OurCompany.com">
          > <cferror type="exception" template="/error/errorexception.cfm" mailto=" me@
          > OurCompany.com ">
          > <cferror type="validation" template="/error/errorvalidation.cfm" mailto=" me@
          > OurCompany .com ">
          >
          >
          > <cffunction name="OnApplicationStart" output="false" returntype="void">
          > <cfset Application.dataSource = "ourDB">
          > <cfset Application.companyname="Company Name">
          > </cffunction>
          >
          > <cffunction name="onRequestStart" returnType="boolean" output="true">
          >
          > <cfreturn true>
          > </cffunction>
          >
          > <cffunction name="onError" returntype="void" output="false">
          > <cfargument name="exception" required="yes">
          > <cfargument name="eventName" type="string" required="yes">
          >
          > <!--- use the cflog tag to record info on the error --->
          > <cfif arguments.eventName is "">
          > <cflog file="#this.name#" type="error" text="#arguments.exception.message#">
          > <cfelse>
          > <cflog file="#this.name#" type="error" text="Error in Method
          > [#arguments.eventname#] #arguments.exception.message#">
          > </cfif>
          >
          > <!--- Let the <cferror> tags to their job --->
          > <cfthrow object="#arguments.exception#">
          > </cffunction>
          > </cfcomponent>
          >
          > I also have an ApplicationProxy.cfc which just extends my Application.cfc
          > <webroot>/ApplicationProxy.cfc
          > <cfcomponent extends="Application">
          > </cfcomponent>
          >
          >
          > Personal/Application.cfc (directory that i want secured)
          > <cfcomponent extends="ApplicationProxy">
          > <cfset this.name=" OurCompany_personal">
          >
          > <cffunction name="onRequestStart" returnType="boolean" output="true">
          > <cfinclude template="/forceuserlogin.cfm">
          > <cfreturn true>
          > </cffunction>
          > </cfcomponent>
          >
          >

          you can store the login values in session variables:
          inside your login code set some session vars, i.e.
          session.userdata.username = "xxx", etc (if you are using the cflogin
          framework, set these before the <cfloginuser> tag). in your main
          Application.cfc in OnRequestStart check for existance of
          session.userdata structure -> if it exists, then display
          session.userdata.username linked to personal account page; if it doesn't
          display a Log In link to the login page...


          --
          Azadi Saryev
          Sabai-dee.com
          Vientiane, Laos
          http://www.sabai-dee.com