[coldbox-5.5.0] User login - basic understanding missing?


I think I’m missing something fundamental.

I’ve created myself an interceptor “preProcess” to check for security credentials which then:
setNextEvent( event=“security.login”, prePostExempt=true)
…and displays a login page.

When a login is attempted (again by my “preProcess” interceptor), this leads to:

runEvent( event=“security.loginattempt”);

The loginAttempt function, then performs the check:

prc.User = UserService.newCriteria().isTrue(“Active”).eq(“Username”,rc._username).eq(“Password”,rc._password).get();

This all appears to be operating correctly
[However, at this point I would like to say, please let me know anything that’s incorrect.]

I then prepare a non-ORM model called AJAXReturn (essentially just a structure) to send the details back to the browser in a standard form. In this instance, I don’t actually want to send the user details back to the browser - I just want to test the technique of loading data coming from a query into a structure and returning it.

However, prc.User seems to be far too big - Java heap error. This seems to be true as the log shows that serialize(prc.User) contains an property called “”$FORMATTER_CUSTOM"" which starts a very long string:


My first idea was to create a User.cfc and copy all the relevant variables across from prc.User. But I didn’t think there was any need for this, when using the Virtual Service layer.
Any suggestions - or is this completely the wrong tree to be barking up?

AJAXReturn.cfc (816 Bytes)

security.cfc (2.98 KB)

BaseEntity.cfc (785 Bytes)

UserService.cfc (1.04 KB)

[I’m going to rephrase]
My question boils down to this; if index is called in the normal way (/users/index), it results in a list (accessible via prc), but calling the same function as JSON (/users/index.json) the result is a Java heap error:

function index( event, rc, prc ){
prc.title = “Users”;
prc.users = UserService.newCriteria().isTrue(“Active”).list();
event.renderData( data=prc.users, formats=“xml,json,html,pdf” );

Hi John,

I had quick peek at your code. I could be wrong, but I suspect that your ‘UserService’ object has a deep class hierarchy or complicated dependencies that it trying to serialize. Have you omitted any code from the cfcs you provided?

I tested it on one of my applications and everything seems to be working correctly. Just to add to the discussion. You seem to be getting confused between entities and services, or maybe you just have an odd naming scheme.

In the code you provided, ‘UserService.cfc’ seems to be an entity (a class that models a user) but you have named it UserService. A service is a class that as a communication layer between your domain model (User entity) and your handlers (in your case, security.cfc). Coldbox provides the ability to create services on the fly so you dont have to code them yourself.

As an example I have attached some snippets of my code.

If you made available some more of your code I could prehaps try debug the more a bit more.


BaseEntity.cfc (904 Bytes)

User.cfc (1.87 KB)

Main.cfc (2.16 KB)

Hi Ryan,

Thanks the snippets. Yours are probably a bit more complicated than mine - so I copied a few bits! Yes, UserService should be User. After working through the tutorials some items didn’t get renamed as they should have done.

I started a new ColdBox project but I’m still getting Java heap space errors for any JSON request - including your version of /users/test2.json.

Similarly to your setup, I have User extending BaseEntity. I’ve attached the latest versions of these - but again, they’re very similar to your versions.

Dumping out the users list on users/index (), there is a lot of ‘stuff’ in addition to the getters and setters. Each member of the users array also contains properties like $buildNestedMementoList, $FORMATTER_CUSTOM, $FORMATTER_ISO8601, $injectMixin, $mementifierSettings, CONSTRAINTS, exposeMixin…The BaseEntity is not extending anything else.

User.cfc (1.63 KB)

BaseEntity.cfc (1.72 KB)

Hi Ryan,

I think I’ve got it sorted. I got the idea (possibly from the main docs) that I should be able to simply return:
…for all requests.

But for JSON requests (and probably others) I would need to use your custom function from the BaseEntity


Thanks for your help - and thanks for your toStruct function!

Thought I’d post another reply to myself, just in case anyone stumbles upon this.

Instead of writing toStruct() functions…I’ve just got Mementifier working:

It cascades through your CBORM, entityService, injected models creating nice little nested structures of the information you want.

Once again, thanks to the Ortus - ColdBox guys!