0

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>
Jeromy French
  • 11,812
  • 19
  • 76
  • 129
suleman khan
  • 97
  • 1
  • 1
  • 9
  • Because the id variable on the line doesn't exist in the variables, form, or URL scope. Where are you defining that value? Should it be user.id? – Dan Short Mar 05 '13 at 20:49
  • yeah it is in user.id. – suleman khan Mar 05 '13 at 21:11
  • Have you tested this in Coldfusion 9 and Coldfusion 10. If you have then please say so in the question, otherwise please pick a Coldfusion version that your having the problem on. – Vincent P Mar 06 '13 at 06:27

3 Answers3

5

You will save yourself (and other future devs) a lot of headaches by scoping your variables.

<cfset session.auth.id = User.id>  

If User is a query or struct then you can also reference your record with dot notation

<cfset session.auth.id = User.id[1]>  
Matt Busche
  • 14,216
  • 5
  • 36
  • 61
  • 3
    "save yourself (and other future devs) a lot of headaches by scoping your variables." - So true – AlexP Mar 06 '13 at 13:52
3

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

Dan Short
  • 9,598
  • 2
  • 28
  • 53
1

I don't see where you are defining ID. If you don't define it before you try to access it, you will get an error.

<cfset session.auth.id = id>
Evik James
  • 10,335
  • 18
  • 71
  • 122