Search code examples
coldfusioncoldfusion-9cfml

Variable ID is undefined


Can anyone review this code and tell me why I am getting variable ID undefined error?

<cffunction name="login" access="public" returntype="void">
  <cfargument name="rc" type="struct" required="true">
  <cfset user = getUserService().login(arguments.rc.Username,arguments.rc.password)>
  <cfif isDefined('User')>
    <cfset session.auth = structNew()>
    <cfset session.auth.isLoggedin = "yes"/>
    <cfset session.auth.user = user />
    <cfset session.auth.id = id>  
    <cfset session.auth.username = UserName />
    <cfset session.auth.password = password />
  <cfelse>
    <cfset rc.message = createMessage('error','','entered password is wrong')>
    <cfset variables.fw.redirect('login.default','message')>
  </cfif>
  <cfset variables.fw.redirect('')>
</cffunction>

Solution

  • You need to properly scope your variable (as I stated in my comment). Change = id to = user.id