House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Is this acceptable or reasonable CFC usage?

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick Faircloth
01/07/2009 09:32 AM

I'm trying to set session variables for login with the code below. It works fine on my local dev pc, but on the production server, no session variables are being set.  Is the code below not appropriate? Thanks, Rick <cfcomponent displayname="manager_data" hint="Contains manager database query" output="false">   <cffunction name = "getmanagerData">        <cfargument name = "email_address"   type="string" required="yes">     <cfargument name = "password"    type="string" required="yes">          <cfquery name="get_manager" datasource="#application.dsn#">            select    manager_id, email_address, password, announcements, res_announcements, rental_properties,           new_communities, agents, featured_properties, open_houses, local_websites, fort_stewart,           our_community, approved_cities, site_managers                    from    site_managers       where    email_address = '#arguments.email_address#'       and    password = '#arguments.password#'            </cfquery>          <cfset managerStruct = structNew()>          <cfif get_manager.recordcount gt 0>            <cfset session.manager_id = get_manager.manager_id>       <cfset session.announcements = get_manager.announcements>       <cfset session.res_announcements = get_manager.res_announcements>       <cfset session.rental_properties = get_manager.rental_properties>       <cfset session.new_communities = get_manager.new_communities>       <cfset session.agents = get_manager.agents>       <cfset session.featured_properties = get_manager.featured_properties>       <cfset session.open_houses = get_manager.open_houses>       <cfset session.local_websites = get_manager.local_websites>       <cfset session.fort_stewart = get_manager.fort_stewart>       <cfset session.our_community = get_manager.our_community>       <cfset session.approved_cities = get_manager.approved_cities>       <cfset session.site_managers = get_manager.site_managers>              <cfset managerStruct.login = "Login Successful">          <cfelse>       <cfif not len(trim(arguments.email_address))>         <cfset managerStruct.emailerror = "Please enter your email address">       </cfif>              <cfif not len(trim(arguments.password))>         <cfset managerStruct.passworderror = "Please enter your password">       </cfif>              <cfset managerStruct.login = "Login Unsuccessful">            </cfif>          <cfreturn managerStruct />        </cffunction> </cfcomponent>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Scott Stewart
01/07/2009 09:50 AM

Do you have enable session management checked  in the ColdFusion admin   on  your production box, and  session management enabled in your Application.cfc? Rick Faircloth wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick Faircloth
01/07/2009 10:09 AM

Hi, Scott, and thanks for the reply... Yes, session variables are enabled in the admininistrator and in the application.cfc:  <cfset this.sessionManagement = true /> That was the first thing I checked on the server. Just can't figure out what could be keeping the session variables from being set.  Firebug tells me all templates are being accessed...and this setup works on my dev pc... Rick ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ian Skinner
01/07/2009 09:51 AM

Rick Faircloth wrote: > I'm trying to set session variables for login with the code below. > It works fine on my local dev pc, but on the production server, > no session variables are being set.  Is the code below not appropriate? > > Thanks, > > Rick ColdFusion does not care, but lots of OOP types will probably point out that it is considered bad practice to reference external scopes inside of a component.  Just for this type of difficulty. ColdFusion's only problem with this is the for sessions to work properly all code referencing the same session must be in the same 'application' as determined with an <cfapplication...> tags with the same 'name' property.  How this affects components is that they are often placed in directories outside the normal web directories and thus are not under the usual Application.cfm|.cfc file that defines that application name.   This is easy to fix by making sure that somehow or the other the component runs an <cfapplication....> tag with the desired application name.  But this can become very complex very quickly if the coponent is meant to be used by different applications running on the system. Thus we are back to the OOP best practice of not referencing external scopes to the the component.  The better idea would be to return a structure of the data you are planning on putting into the session scope.  Then the calling code, that presumably is part of the appropriate 'application' will receive this structure and can simply copy it into the session scope.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick Faircloth
01/07/2009 10:21 AM

OOP... yes, this was my first component, so there's much that can be reworked.  All templates in use are under the same application.cfc. It's the same set up that's working on my dev pc... I tried your idea about putting the necessary data into the result set coming from the method, but I couldn't seem to get the data in there. I'm returning the data in "managerStruct" for the purposes of logging in. The other data just sets permissions for the user. Here's the CFC I'm using.  Do you see any issues?  How would I change it to include the permissions in the struct? One thing that may be complicating this is how this method is being called from another template called "login_processor.cfm" . I didn't write this originally, just modified it, so I'm not entirely sure of how it works.  Here's the code in that one. You can try this setup out at http://sitemanager.fortstewart.com and use these credentials to login:  email:  guest@wsm.com  password:  guest If the login worked properly, you should be the menu on the page change to include about 15 items.  But online, unlike on my dev pc, the menu doesn't change. (And you can see from the cfdump of session variables that none of the perimissions are included. Suggestions?  Thanks, Rick login_processor.cfm -------------------------------------------------------------------------   <cfset mdata = createObject("component","manager_data")>   <cfset thedata = mdata.getmanagerData(form.email_address, form.password)>   <cfset ojson = createObject("component","cfjson")>   <cfset results = ojson.encode(thedata)>   <cfoutput>#results#</cfoutput> manager_data.cfc ----------------------------------------------------------------------------- <cfcomponent displayname="manager_data" hint="Contains manager database query" output="false">   <cffunction name = "getmanagerData">        <cfargument name = "email_address"   type="string" required="yes">     <cfargument name = "password"    type="string" required="yes">          <cfquery name="get_manager" datasource="#application.dsn#">            select    manager_id, email_address, password, announcements, res_announcements, rental_properties,           new_communities, agents, featured_properties, open_houses, local_websites, fort_stewart,           our_community, approved_cities, site_managers                    from    site_managers       where    email_address = '#arguments.email_address#'       and    password = '#arguments.password#'            </cfquery>          <cfset managerStruct = structNew()>          <cfif get_manager.recordcount gt 0>            <cfset session.manager_id = get_manager.manager_id>       <cfset session.announcements = get_manager.announcements>       <cfset session.res_announcements = get_manager.res_announcements>       <cfset session.rental_properties = get_manager.rental_properties>       <cfset session.new_communities = get_manager.new_communities>       <cfset session.agents = get_manager.agents>       <cfset session.featured_properties = get_manager.featured_properties>       <cfset session.open_houses = get_manager.open_houses>       <cfset session.local_websites = get_manager.local_websites>       <cfset session.fort_stewart = get_manager.fort_stewart>       <cfset session.our_community = get_manager.our_community>       <cfset session.approved_cities = get_manager.approved_cities>       <cfset session.site_managers = get_manager.site_managers>              <cfset managerStruct.login = "Login Successful">          <cfelse>       <cfif not len(trim(arguments.email_address))>         <cfset managerStruct.emailerror = "Please enter your email address">       </cfif>              <cfif not len(trim(arguments.password))>         <cfset managerStruct.passworderror = "Please enter your password">       </cfif>              <cfset managerStruct.login = "Login Unsuccessful">            </cfif>          <cfreturn managerStruct />        </cffunction> </cfcomponent> ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jason Fisher
01/07/2009 10:32 AM

Actually, looking at the code, I would say that the user you're logging in as simply doesn't exist in your production database.  The session sets are in a CFIF block ... if there's not a valid record in the login Query, it's not setting the session, right?


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 24, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference