<cfreturn>

After a function is invoked and the return type is boolean.
How can I check for that?

This is what I have:


<cffunction name="get_userLogin" hint="Check if login user exists" returntype="boolean">
      <cfargument name="loginName" type="string" required="true">
      <cfargument name="password" type="string" required="true">
      
      <cfquery datasource="A9968_genuine" name="exists">
        select * from tblgenuine_login
      where login_name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.logiNname#"/>
      and password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#"/>
      </cfquery>
      <cfreturn exists>
</cffunction>


<cfinvoke component="components.genuine" method="get_userLogin" argumentcollection="#form#">
      <cfinvokeargument name="loginName" value="#loginName#"/>
      <cfinvokeargument name="password" value="#password#"/>
</cfinvoke>


<!--- If user exists, create a session. --->

<CFIF #exists.recordcount# eq 1>
      <!--- Create Session Structure --->
      <CFSET session.genuine = StructNew()>
      <CFSET session.genuine.fname = #exists.fname#>
      <CFSET session.genuine.lname = #exists.lname#>
      <cflocation url="viewComment.cfm">
<CFELSE>
      <!--- If user does not exist, redirect to login page --->
      <cfset session.genuine.login = "no">
      <cflocation url="genuineLogin.cfm">      
</CFIF>

What I am trying to do is check to see if the query above executed to just one record (someone exists for the loginName and password).

This is the error I get:

Error Occurred While Processing Request  
The value returned from function get_userLogin() is not of type boolean.  
If the component name is specified as a return type, the reason for this error might be that a definition file for such component cannot be found or is not accessible.  
 
LVL 5
IsaacSharePoint Client Side DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mosphatCommented:
Try this one:
Notice the setting of the session vars occurs in the function as well.

<cffunction name="get_userLogin" hint="Check if login user exists" returntype="boolean">
     <cfargument name="loginName" type="string" required="true">
     <cfargument name="password" type="string" required="true">
     <cfset var exists = 0>
     <cfquery datasource="A9968_genuine" name="exists">
       select * from tblgenuine_login
      where login_name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.logiNname#"/>
      and password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#"/>
     </cfquery>
    <cfif exists.recordcount eq 1>
      <CFSET session.genuine = StructNew()>
      <CFSET session.genuine.fname = exists.fname>
      <CFSET session.genuine.lname = exists.lname>
      <cfreturn true>
    <cfelse>
      <cfreturn false>
    </cfif>
</cffunction>
0
mosphatCommented:
Some (off-topic) tips:
Notice the <cfset var exists = 0> in my previous post. That is to make sure the variable 'exists' is local to the function. If you don't use the 'var' keyword, you could be overwriting a variable outside the function having the same name. And that is not an easy one to debug. Therefore it is a good habit to always var any variable used within a function.

Second, you don't have to use # within a tag (unless it's in a string).
<CFSET session.genuine.fname = #exists.fname#> should be <CFSET session.genuine.fname = exists.fname>
And <CFIF #exists.recordcount# eq 1> should be <CFIF exists.recordcount eq 1>
Looks a bit cleaner too, I think.

0
kkhippleCommented:
why dont you do the check within your component?

<cffunction name="get_userLogin" hint="Check if login user exists" returntype="boolean">
     <cfargument name="loginName" type="string" required="true">
     <cfargument name="password" type="string" required="true">
     
     <cfquery datasource="A9968_genuine" name="exists">
       select * from tblgenuine_login
      where login_name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.logiNname#"/>
      and password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#"/>
     </cfquery>

     <!--- if one record is returned, then return true --->
     <CFIF exists.recordcount EQ 1>
         <CFRETURN true>
      <CFELSE>
          <CFRETURN false>
      </CFIF>

</cffunction>


OR .. u can even chg ur query to...

<!---- add and specify "1" to the MAXROWS attribute to the CFQUERY tag --->
     <cfquery datasource="A9968_genuine" name="exists" MAXROWS="1">
       select * from tblgenuine_login
      where login_name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.logiNname#"/>
      and password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#"/>
     </cfquery>
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

mosphatCommented:
kkhipple,

Using maxrows won't help a lot, since you either find no rows or 1 row.
It is a bit unlikely that there are multiple users having the same loginname and password. ;)

0
Tacobell777Commented:
<cffunction name="get_userLogin" hint="Check if login user exists" returntype="boolean">
     <cfargument name="loginName" type="string" required="true">
     <cfargument name="password" type="string" required="true">
     
     <cfquery datasource="A9968_genuine" name="exists">
       select * from tblgenuine_login
      where login_name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.logiNname#"/>
      and password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#"/>
     </cfquery>
     <cfreturn exists>
</cffunction>

exists is not boolean, its a query, so if you wanted the above to work you would change  the return type to query, i.e. returntype="query">

Also, I would not put
<CFIF exists.recordcount EQ 1>
         <CFRETURN true>
      <CFELSE>
          <CFRETURN false>
      </CFIF>
in the same function, the function is called get_userLogin, and thats all it should do - you should write another function to which you pass the result from the function and then check if the login is correct.
0
Tacobell777Commented:
another thing, I would not actually check if there is a recordcount, I would actually check if the values returned are actually the username and password entered - just some extra security against SQL Injection..
0
IsaacSharePoint Client Side DeveloperAuthor Commented:

I'm getting a new error now:

Error Occurred While Processing Request  
The value returned from function get_userLogin() is not of type boolean.  
If the component name is specified as a return type, the reason for this error might be that a definition file for such component cannot be found or is not accessible.  
 
What about this.  Can you all help me, I'm just trying to create a login page that only lets you view a few pages.  Maybe my approach is way off.
Anyway Tacobell777, I saw your evocash site, how did you do the login there?  Are there certain steps I need to take.  I'm willing to learn from anybody who know's what they are doing.

-TI-
0
mosphatCommented:
The error reads: The value returned from function get_userLogin() is not of type boolean.

That means in your get_userLogin() function there's a <cfreturn xxx> where xxx is not a boolean. Have you correctly changed that function according to the proposed options in this thread?
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
Yes, I made the appropriate change that you suggested.
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
This is what I have.

<cffunction name="get_userLogin" hint="Check if login user exists" returntype="boolean">
      <cfargument name="loginName" type="string" required="true">
      <cfargument name="password" type="string" required="true">
      
      <cfquery datasource="A9968_genuine" name="exists">
        select * from tblgenuine_login
      where login_name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.logiNname#"/>
      and password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#"/>
      </cfquery>
      <cfreturn exists>
      
      <!--- If user exists, create a session. --->

<CFIF exists.recordcount eq 1>
      <!--- Create Session Structure --->
      <CFSET session.genuine = StructNew()>
      <CFSET session.genuine.fname = exists.fname>
      <CFSET session.genuine.lname = exists.lname>
      <cflocation url="viewComment.cfm">
<CFELSE>
      <!--- If user does not exist, redirect to login page --->
      <cfset session.genuine.login = "no">
      <cflocation url="genuineLogin.cfm">      
</CFIF>
</cffunction>
0
mosphatCommented:
Then there must be a typo in either my or your code...
Could you post what your current version of get_userLogin looks like?
0
mosphatCommented:
Hmm, you were quicker :)

You are doing a cflocation now. That means the function is not returning anything. Change returntype="boolean" to returntype="void".

0
IsaacSharePoint Client Side DeveloperAuthor Commented:
With the code below, I get this error:

Error Occurred While Processing Request  
Element RECORDCOUNT is undefined in EXISTS.  

I made the returntype=query

<cffunction name="get_userLogin" hint="Check if login user exists" returntype="query">
     <cfargument name="loginName" type="string" required="true">
     <cfargument name="password" type="string" required="true">
     
     <cfquery datasource="A9968_genuine" name="exists">
       select * from tblgenuine_login
      where login_name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.logiNname#"/>
      and password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#"/>
     </cfquery>
     <cfreturn exists>
     
     <!--- If user exists, create a session. --->

</cffunction>

"INVOKE PAGE"

<cfinvoke component="components.genuine" method="get_userLogin" argumentcollection="#form#" returnvariable="exist">
      <cfinvokeargument name="loginName" value="#loginName#"/>
      <cfinvokeargument name="password" value="#password#"/>
</cfinvoke>


<!--- If user exists, create a session. --->

<CFIF #exists.recordcount# eq 1>
      <!--- Create Session Structure --->
      <CFSET session.genuine = StructNew()>
      <CFSET session.genuine.fname = #exists.fname#>
      <CFSET session.genuine.lname = #exists.lname#>
      <cflocation url="viewComment.cfm">
<CFELSE>
      <!--- If user does not exist, redirect to login page --->
      <cfset session.genuine.login = "no">
      <cflocation url="genuineLogin.cfm">      
</CFIF>


 
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
with the void, I get this error:

Error Occurred While Processing Request  
The function get_userLogin defined as void tried to return a value.  
Void functions must not return any values.  
 
0
kkhippleCommented:
in the code below.. if this is waht you are using.... dont specify the CFLOCATION ... instead just return TRUE or FALSE

<cffunction name="get_userLogin" hint="Check if login user exists" returntype="boolean">
     <cfargument name="loginName" type="string" required="true">
     <cfargument name="password" type="string" required="true">
     
     <cfquery datasource="A9968_genuine" name="exists">
       select * from tblgenuine_login
      where login_name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.logiNname#"/>
      and password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#"/>
     </cfquery>
     <cfreturn exists>
     
     <!--- If user exists, create a session. --->

<CFIF exists.recordcount eq 1>
     <!--- Create Session Structure --->
     <CFSET session.genuine = StructNew()>
     <CFSET session.genuine.fname = exists.fname>
     <CFSET session.genuine.lname = exists.lname>
     <cflocation url="viewComment.cfm">
<CFELSE>
     <!--- If user does not exist, redirect to login page --->
     <cfset session.genuine.login = "no">
     <cflocation url="genuineLogin.cfm">    
</CFIF>
</cffunction>
0
kkhippleCommented:
and in this bit of code..

<CFIF exists.recordcount eq 1>
     <!--- Create Session Structure --->
     <CFSET session.genuine = StructNew()>
     <CFSET session.genuine.fname = exists.fname>
     <CFSET session.genuine.lname = exists.lname>
     <cflocation url="viewComment.cfm">
<CFELSE>
     <!--- If user does not exist, redirect to login page --->
     <cfset session.genuine.login = "no">
     <cflocation url="genuineLogin.cfm">    
</CFIF>
</cffunction>



change it to

<CFIF exists.recordcount eq 1>
     <CFRETURN true>
<CFELSE>
     <CFRETURN FALSE>
</CFIF>
</cffunction>





after that... set your session variables and what not
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
What do you mean kkhipple?

In replace of this '<cflocation url="viewComment.cfm">', I do this '<cfreturn true>'
Is that what you mean?
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
kkhipple,

If I do it the way you said above with the true or false, how would it know where to redirect it, because the cflocation is not there anymore.
0
mosphatCommented:
The cflocation should be in the code calling that function:

<cfset genuineCFC = createObject("component", "components.genuine")>
<cfif genuineCFC.get_userLogin()>
  <cflocation url="viewComment.cfm">
<cfelse>
  <cflocation url="genuineLogin.cfm">
</cfif>
0
mosphatCommented:
Make that:

<cfset genuineCFC = createObject("component", "components.genuine")>
<cfif genuineCFC.get_userLogin(form.loginName, form.password)>
  <cflocation url="viewComment.cfm">
<cfelse>
  <cflocation url="genuineLogin.cfm">
</cfif>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kkhippleCommented:
that's exactly how you do it... ... thx mosphat...
get_userLogin ...  should only authenticate the user .. from my understanding of what you wanna do.
if u want.. u can rename it ... authenticateUser .. or validUser... just something that speaks more clearly  about what  you are trying to do...


i hope the help that mosphat has provided was beneficial...
0
Tacobell777Commented:
Forget evocash, its history ;-)

<cfcomponent>

      <cffunction
            name="getUser"
            hint="Returns a user"
            returntype="query">
      
            <cfargument
                  name="loginName"
                  type="string"
                  required="true" />
            <cfargument
                  name="password"
                  type="string"
                  required="true" />
      
            <cfquery
                  datasource="A9968_genuine"
                  name="qUser">
            SELECT            login_name,
                              password      
            FROM            tblgenuine_login
            WHERE            login_name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.logiNname#"/>
            AND                  password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#"/>
            </cfquery>
      
            <cfreturn qUser />
      
      </cffunction>

   
      <cffunction
            name="isValidUser"
            hint="Checks the login details"
            returntype="boolean">

            <cfargument
                  name="loginName"
                  type="string"
                  required="true" />
            <cfargument
                  name="password"
                  type="string"
                  required="true" />
      
            <cfscript>
            var result getUser( loginName = arguments.loginName, password = arguments.password );
            if ( result.login_name IS arguments.loginName AND result.password IS arguments.password )
            {
                  return true;
            }
            else
            {
                  return false;
            }
            </cfscript>

      </cffunction>

</cfcomponent>

<cfscript>
obj = createObject( "component", "whateverthename" );
</cfscript>

<cfif obj.isValidUser( loginName = 'xxxx', password = 'xxxx' ) >
      <cflocation url="do the relocation here because its a valid user" />
<cfelse>
      Bad login
</cfif>
0
Tacobell777Commented:
just a note: if you really wanted it OO then you would probably get the user from the db, set it in the this scope, create a getter and then do isValidUser() getting the values from the THIS scope (you would probably go further than that, but I won't go there ;-)
but the above is broken down more then before anyway, the whole idea of CFCs is that you allow a function to perform only one action, this way you can create loosely coupled code.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.