Name
sn_anon_rc.ARCCaptchaUtils
Description
Utility for captcha in ARC portal
Script
var ARCCaptchaUtils = Class.create();
ARCCaptchaUtils.prototype = {
initialize: function() {
this._CAPTCHA_CACHE = 'CaptchaToken'; // this is OOB data in sys_scoped_cache table
this._TTL = 1; //time to live in minutes
this._SESSION = gs.getSession().getSessionToken();
},
verifyCaptcha: function(captchaText) {
if (gs.getProperty('sn_anon_rc.arc.captcha.google.enabled', 'false') == 'false' && captchaText) {
var captchaCheck = new sn_pwdreset_api.PwdImageCaptcha().validateCaptchaValue(captchaText);
if (captchaCheck && !sn_scoped_cache.ScopedCacheManager.get(this._CAPTCHA_CACHE, this._SESSION))
sn_scoped_cache.ScopedCacheManager.put(this._CAPTCHA_CACHE, this._SESSION, new GlideDateTime().getNumericValue()+'');
return captchaCheck;
}
},
verifyGoogleCaptcha: function(captchaResponse) {
try {
var captchaCheck = new global.GoogleCaptcha().verifyCaptcha(captchaResponse);
if (captchaCheck && !sn_scoped_cache.ScopedCacheManager.get(this._CAPTCHA_CACHE, this._SESSION))
sn_scoped_cache.ScopedCacheManager.put(this._CAPTCHA_CACHE, this._SESSION, new GlideDateTime().getNumericValue()+'');
return captchaCheck;
} catch (ex) {
gs.error(ex);
return "false";
}
},
isCachedCaptchaValid: function() {
var timestamp = sn_scoped_cache.ScopedCacheManager.get(this._CAPTCHA_CACHE, this._SESSION);
this._TTL = this._TTL * 60 * 1000; // convert TTL from minutes to milliseconds to match getNumericValue from GlideDateTime
var goodThru = this._TTL + parseInt(timestamp);
//clear the cache as we have fetched it once
sn_scoped_cache.ScopedCacheManager.flushScopedCache(this._CAPTCHA_CACHE, this._SESSION);
if (timestamp && timestamp < goodThru)
return true;
return false;
},
type: 'ARCCaptchaUtils'
};
Sys ID
5432f1840c021110f87729f2620f7416