-
-
Save nolandubeau/ea63fe09ccd92a502e74 to your computer and use it in GitHub Desktop.
verify_credentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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