Concrete Services

/**
* Service to handle author operations.
*/
component extends="cborm.models.VirtualEntityService" accessors="true" singleton{
// User hashing type
property name="hashType";
AuthorService function init(){
// init it via virtual service layer
super.init( entityName="bbAuthor", useQueryCaching=true );
setHashType( "SHA-256" );
return this;
}
function search(criteria){
var params = {criteria="%#arguments.criteria#%"};
var r = executeQuery(query="from bbAuthor where firstName like :criteria OR lastName like :criteria OR email like :criteria",params=params,asQuery=false);
return r;
}
function saveAuthor(author,passwordChange=false){
// hash password if new author
if( !arguments.author.isLoaded() OR arguments.passwordChange ){
arguments.author.setPassword( hash(arguments.author.getPassword(), getHashType()) );
}
// save the author
save( author );
}
boolean function usernameFound(required username){
var args = {"username" = arguments.username};
return ( countWhere(argumentCollection=args) GT 0 );
}
}Last updated
Was this helpful?