Skip to content

Instantly share code, notes, and snippets.

@nolandubeau
Created July 10, 2012 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolandubeau/ea63fe09ccd92a502e74 to your computer and use it in GitHub Desktop.
Save nolandubeau/ea63fe09ccd92a502e74 to your computer and use it in GitHub Desktop.
verify_credentials
function verify_credentials(event){
var rc = event.getCollection();
var prc = event.getCollection();
//user profile cacheKey
var cacheKey = "user-#rc.authorizedUserID#-profile";
//Check if data exists
if(cache.lookup( cacheKey ) ){
rc.results.setData(cache.get(cacheKey));
rc.results.setStatus(304);
//log.warn('returning cached user',rc.results);
return;
}else{
//query for the user
//log.warn('user is not in the cache');
local.user = userService.getUser(rc.authorizedUserID,getcoldBoxOCM().get('activePartners'));
}
//validate user is not empty
if(structIsEmpty(local.user)){
rc.results.setStatus(404);
rc.results.addError(404,"Invalid User Request");
if( log.canWarn() ){
log.warn("Invalid Credential Verification",getHTTPRequestData());
}
}else{
rc.results.setData(local.user);
//log.warn('setting user into the cache');
cache.set(cacheKey, local.user, 120, 20);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment