Avatar of brianmfalls
brianmfallsFlag for United States of America

asked on 

cflogin - Struct cannot be cast

<cfif structKeyExists(form,"username")>
	
	<cfset userLogin = application.admin.login(users_name=form.username,users_pass=form.password) />
	
	<cfdump var="#userLogin#" label="user login data output" expand="no" />
	
    <cfif len(userLogin.users_name) AND len(userLogin.users_pass)>
        <cflogin idletimeout="1800">
            <cfloginuser name = "#userLogin.users_name#" password ="#userLogin.users_pass#" roles = "#userLogin.users_admin#" />
        </cflogin>
    <cfelse>
        <cfset invalid_login = 1>
    </cfif>

</cfif>

Open in new window


The code (above) throws the following error:
Error casting an object of type coldfusion.runtime.Struct cannot be cast to coldfusion.runtime.Scope to an incompatible type. This usually indicates a programming error in Java, although it could also mean you have tried to use a foreign object in a different way than it was designed.
coldfusion.runtime.Struct cannot be cast to coldfusion.runtime.Scope

I can't for the life of me figure out why...  Any help would be appreciated.
ColdFusion Language

Avatar of undefined
Last Comment
brianmfalls
Avatar of gdemaria
gdemaria
Flag of United States of America image

Look at the definition of the function "login" in your "admin" cfc... the return type is probably not STRUCT, but you are returning a structure.   You can change the return type to "struct" or "any"

Avatar of gdemaria
gdemaria
Flag of United States of America image

To be more specific, I was referring to this line...

<cffunction name="login" returnType="xxxxx" ....
Avatar of _agx_
_agx_
Flag of United States of America image

> The code (above) throws the following error:

on which line ? can you include full error message?

> <cfdump var="#userLogin#" label="user login data output" expand="no" />

what type of object does application.admin.login return?
Avatar of _agx_
_agx_
Flag of United States of America image

Whoops... didn't see any responses before posting.

> the return type is probably not STRUCT, but you are returning a structure.

It's possible, but I'd expect a different error.
Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

Function Being referenced:
<!--------updateElement-(inception)------->
<cffunction name="updateElement" returntype="any" output="true" hint="updates data for products/services">
	
	<cfargument name="id" required="yes">
	<cfargument name="content" required="yes">
	
	<cfquery name="updateElement" datasource="#this.dsn#">
		UPDATE		prodServ
		SET			prodServ_html = #arguments.content#
		WHERE		prodServ_id = #arguments.id#
	</cfquery>
	
</cffunction>
<!--------updateElement-(completion)------->

Open in new window


I am not attempting to return anything, so I don't think that's it.

I thought that maybe it didn't like the directory structure.  I rearranged that a bit, and still I get the same error.  I am trying some other things now.
Avatar of _agx_
_agx_
Flag of United States of America image

Brian - I think you posted the wrong function.  
Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

I'm mixing up my posts...  
Hold one.
Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

Here's the function:
	<cffunction name="login" access="public" returntype="any" output="true" hint="returns login">
		
		<cfargument name="users_name" required="yes" />
		<cfargument name="users_pass" required="yes" />
		
		<cfquery name="loginData" datasource="#this.dsn#">
			SELECT	users_name, users_pass, users_admin
			FROM	users
			WHERE	users_name = '#arguments.users_name#'
			AND		users_pass = '#arguments.users_pass#'
		</cfquery>
		
		<cfreturn loginData>

	</cffunction>

Open in new window

Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

Here's the code:
<cfparam name="url.logout" default="0">
<cfparam name="invalid_login" default="0">

<cfif structKeyExists(form,"username")>
	
	<cfset userLogin = application.admin.login(users_name=form.username,users_pass=form.password) />
	
	<cfdump var="#userLogin#" label="user login data output" expand="no" />
	
    <cfif len(userLogin.users_name) AND len(userLogin.users_pass)>
        <cflogin idletimeout="1800">
            <cfloginuser name = "#userLogin.users_name#" password ="#userLogin.users_pass#" roles = "#userLogin.users_admin#" />
        </cflogin>
    <cfelse>
        <cfset invalid_login = 1>
    </cfif>

</cfif>

<cfif url.logout>
    <cflogout>
    <cflocation url="index.cfm">
</cfif>

<cfif NOT len(GetAuthUser())>
	<div class="loginForm">
		<form name="userLogin" method="post" action="index.cfm">
			<label for="username">User Name</label><input name="username" type="text" id="username">
			<label for="password">Password</label><input name="password" type="text" id="password">
			<input type="submit" name="login" value="Login">
		</form>
	</div>
<cfelse>
    <p>User: <cfoutput>#GetAuthUser()#</cfoutput></p>
    <a href="index.cfm?logout=1">Logout</a>
</cfif>

Open in new window

Avatar of _agx_
_agx_
Flag of United States of America image

Works for me. Can you post the complete error message? It'd help to see the line number...
Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

If I comment out the cflogin, there is no error.

Like So:
    <cfif len(userLogin.users_name) AND len(userLogin.users_pass)>
		Valid Login
        <!---<cflogin idletimeout="1800">
            <cfloginuser name = "#userLogin.users_name#" password ="#userLogin.users_pass#" roles = "#userLogin.users_admin#" />
        </cflogin>--->
    <cfelse>
        <cfset invalid_login = 1>
    </cfif>

Open in new window

Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

I cannot.  My host doesn't allow robust debug output.
Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

Output, the cfloginuser line looks like this:
cfloginuser name = "brian" password ="jesus" roles = "1"
Avatar of _agx_
_agx_
Flag of United States of America image

> cfloginuser name = "brian" password ="jesus" roles = "1"

Does it work with a hard coded string instead of the query variables ? Maybe it's the query cflogin doesn't like.

> I cannot.  My host doesn't allow robust debug output.
Wrap it in a try/catch then.

<cftry>
     .... all of your code here

     <cfcatch><cfdump var="#cfcatch#"></cfcatch>
</cftry>
Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

I hard coded it, still get the error.  I'll wrap it int the catch.
Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

Here's the dump from the catch:

struct
Message       coldfusion.runtime.Struct cannot be cast to coldfusion.runtime.Scope
StackTrace       java.lang.ClassCastException: coldfusion.runtime.Struct cannot be cast to coldfusion.runtime.Scope at coldfusion.tagext.security.AuthenticateTag.doStartTag(AuthenticateTag.java:80) at cflogin2ecfm1821806886.runPage(D:\brianmfalls\www\goodThrift\admin\login.cfm:9) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416) at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2722) at cfApplication2ecfm2026658558.runPage(D:\brianmfalls\www\goodThrift\admin\Application.cfm:12) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416) at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65) at coldfusion.filter.CfincludeFilter.include(CfincludeFilter.java:33) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:279) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:94) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62) at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:126) at coldfusion.CfmServlet.service(CfmServlet.java:200) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at jrun.servlet.FilterChain.doFilter(FilterChain.java:86) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at jrun.servlet.FilterChain.doFilter(FilterChain.java:94) at jrun.servlet.FilterChain.service(FilterChain.java:101) at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106) at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42) at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286) at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543) at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203) at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320) at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428) at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266) at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
TagContext       
array
1       
struct
COLUMN       0
ID       CFAUTHENTICATE
LINE       9
RAW_TRACE       at cflogin2ecfm1821806886.runPage(D:\brianmfalls\www\goodThrift\admin\login.cfm:9)
TEMPLATE       D:\brianmfalls\www\goodThrift\admin\login.cfm
TYPE       CFML
2       
struct
COLUMN       0
ID       CFINCLUDE
LINE       12
RAW_TRACE       at cfApplication2ecfm2026658558.runPage(D:\brianmfalls\www\goodThrift\admin\Application.cfm:12)
TEMPLATE       D:\brianmfalls\www\goodThrift\admin\Application.cfm
TYPE       CFML
Type       java.lang.ClassCastException
Avatar of _agx_
_agx_
Flag of United States of America image

> I hard coded it, still get the error.

Hm... if it doesn't work with simple values then that suggests the cflogin code is wrong.  Not sure.  I rarely use cflogin ...
Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

I copied and pasted it directly from Adobe's documentation.  I think it's something on the server (settings).  We'll see.
Avatar of _agx_
_agx_
Flag of United States of America image

Could be.  Sorry, I don't use cflogin. So I'm out of suggestions unfortunately.
Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

No worries.  I have the admin's looking at the server.  I'll post if that turns out to be the case.
Avatar of gdemaria
gdemaria
Flag of United States of America image


I also don't use cflogin... so here's a very easy alternative.

Just set a session variable:

<cfset session.login.user_id = userLogin.user_id>
<cfset session.login.userName = userLogin.userName>

That's all you have to do..

Check to see if it's not populated and send the user to login...

<cfif NOT isDefined("session.login.user_id") or val(session.login.user_id) eq 0>
   .... login
</cfif>


I never userstood what cflogin provided that a few simple lines of code do not... except the cflogin stuff tends to mysteriously not work every now and then and there's no debugging it...

Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

That's usually what I do, I just wanted to try cflogin out.  It's no wonder why no one uses it...  Way to go Adobe!  lol
Avatar of _agx_
_agx_
Flag of United States of America image

   > except the cflogin stuff tends to mysteriously not work every now
    > and then and there's no debugging it...

But don't we all need a little mystery in our lives every now and then? ;-)
Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

No.  No we do not.  I'd prefer things work they way they are supposed to.  First time, and every time...  Which is more of a fantasy???
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of brianmfalls
brianmfalls
Flag of United States of America image

ASKER

The verdict....  scrap all attempts to use cflogin
ColdFusion Language
ColdFusion Language

ColdFusion is a server-side rapid application development platform originally created by Allaire and now sold by Adobe, implementing the dynamic general purpose CFML programming language. The term ColdFusion is sometimes colloquially used to refer to the CFML language (Cold Fusion Markup Language), but can also include discussions of the server software implementation. ColdFusion runs using a customised version of Apache Tomcat. Earlier versions are bundled with JRun.

11K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo