School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,406 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,635 people online right now. Registration is fast and FREE... Join Now!




Trying to pass a variable from cflogin

 

Trying to pass a variable from cflogin

cumupkid

10 May, 2009 - 06:39 PM
Post #1

D.I.C Head
**

Joined: 22 Jan, 2008
Posts: 61

What I am trying to do is login from a form and have the user name from that form then be passed as a variable to my next application.cfc to be used to name my application.datasource.
If this can be done with one cfc file that would be great, but just figuring it out would be great too.

The reason I have cfset application.datasource listed twice, in the scond code block, is because I have another section of the site that usese cfset application.datasource, and I could not get one to clear when moving from one section of the site to the next, so I was trying to get that cfc to load an new application.datasource everytime

Application.cfc code
CODE

<cfcomponent>

<cflogin>
    <cfif isdefined("form.userName")>
                <cfquery datasource="mysqlcf_dtcrm" name="[b]quser[/b]">
                    select *
                    from users
                    Where userName = '#form.userName#' AND
                       Password = '#form.password#'
                </cfquery>
              
                <cfif quser.recordcount IS 1>
                    <cfloginuser name="#quser.userName#"
                    password="#quser.password#"
                    roles="#quser.userrole#">                  
                <cfelse>
                    <cfinclude template="Login/loginform.cfm">
                    <cfabort>
                </cfif>    
                
                  <cfelse>
                    <cfinclude template="Login/loginform.cfm">
                    <cfabort>
    </cfif>    
</cflogin>


</cfcomponent>


users/application.cfc code
CODE

<cfcomponent>
        

            <cfquery name="quserByUserID" datasource="mysqlcf_dtcrm">
            SELECT *
            FROM users
            WHERE userName = <cfqueryparam value="#[b]quser.userName[/b]#">
            </cfquery>

    <cffunction name="onRequestStart" access="public" returntype="void">
      <cfargument name="thisRequest" required="true"/>
        <cfif IsDefined("application.datasource")>            
        <cfoutput>
        <cfset application.datasource="jstickel73_accesscf_#quserByUserID.userName#">
        </cfoutput>
        </cfif>


        <cfif NOT IsDefined("application.datasource")>            
        <cfoutput>
        <cfset application.datasource="jstickel73_accesscf_#quserByUserID.userName#">
        </cfoutput>
        </cfif>
     </cffunction>  



</cfcomponent>



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 10:48PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month