getPlugin is undefined?

I was under the impression that getPlugin was built into the framework, however I get this error when trying to access it from the following component in the models folder:

Error Messages: Variable GETPLUGIN is undefined.

`
/**

  • User Service
    */
    component accessors=“true”{

//Depencency Injection
property name=“dao” inject=“UserDAO”;
property name=“populator” inject=“wirebox:populator”;
property name=“wirebox” inject=“wirebox”;

function init(){
return this;
}

function getLogin(required username){
var q = dao.getLogin(arguments.username);
if(q.recordCount neq 1){
getPlugin(“applicationstorage”).setVar(“loggedin”, 1);
return 0;
}
else{

return 1;
}
}

}
`

Any help is appreciated.

Thank you.
-Chris

It is built into the framework, but if you would like it in your model, you would need to inject it as your models should be as framework independent as possible.

I would inject it like
property name=“appStoragePlugin” inject=“coldbox**:**plugin:applicationstorage”;

Curt Gratz

So confused by all this…Basically I’m trying to authenticate a user via a Database table, and set a session variable that the user is logged in. Here is my old school way of doing it:

`

SELECT * FROM Login WHERE username = '#ARGUMENTS.username#'

<cfif getLogin.RecordCount neq 0>

<cfset comparison = Compare(ARGUMENTS.password, getLogin.password)>
<cfif comparison eq 0>

`

There are obviously many approaches as to how to do this.

I would suggest taking a look at our security sample app or at the “Solitary” module to see how this is done.

https://github.com/ColdBox/coldbox-samples
http://www.coldbox.org/forgebox/view/Solitary

Hope that helps you get a start. Keep asking questions if you are confused, we love to help you out.

Curt Gratz

Solitary download links are all DOA.

Thanks Curt. So a best practice is to not put business logic into event handlers, correct? So when my model asks the database to authenticate a username, should it not update the session scope at that time, or does this function get passed back to the handler and he does it?

Any help is appreciated.
Thank you.
-Chris

A little poking around got me to https://github.com/cfaddict/solitary which works…

I tend to have an object a call something like securityService that I allow to talk to the sessionscope in the model, but that is the only one that does. That way my handler is still thin, but my model isn’t all relying on the sessionscope so that in the future I can change it easily as needed. So my userService does the authentication and talks to the securityService to persist the authentication in session.

Curt