Name
global.PwdResetPageInfo_V2
Description
No description available
Script
var PwdResetPageInfo_V2 = Class.create();
PwdResetPageInfo_V2.prototype = Object.extendsObject(PwdResetPageInfo, {
GOOGLE_AUTH_TYPE: 'c7835ab787773200cfab6dd207cb0b88',
EMAIL_TYPE: '47cf0e830b233200572a6f3ef6673a00',
SOFTPIN_TYPE: 'a67585845302011017c3ddeeff7b1267',
initialize: function() {},
getVerifyPageInfo: function(requestId) {
var trackingMgr = new SNC.PwdTrackingManager();
var grRequest = PwdResetRequestHelper.getRequestRecord(requestId);
var grVer = new GlideRecord("pwd_verification");
var userId = grRequest.getValue('user');
var res = {
info: {
request_id: requestId,
user_id: userId,
verifications: [],
min_selections: 0
}
};
var verificationResult;
try {
verificationResult = PwdVerificationSelectionHelper.getVerificationSelection(grRequest.process, userId, requestId);
} catch (e) {
return {
status: PwdConstants.WIN_STATUS_ERROR,
error: gs.message(e)
};
}
var verifications = [];
var mendatory = verificationResult.mandatory;
for (var i = 0; i != mendatory.length; ++i)
verifications.push(getVerObj(mendatory[i], true));
var optional = verificationResult.optional;
var optionalSize = !optional ? 0 : optional.length;
for (i = 0; i < optionalSize; ++i)
verifications.push(getVerObj(optional[i], false));
var verifyTypeQuestions = {};
var info;
function getVerificationLabel(grVer) {
return grVer.getDisplayValue('label') ? grVer.getDisplayValue('label') : grVer.getDisplayValue('name')
}
function getVerObj(verId, required) {
grVer.get(verId);
return {
id: verId,
label: getVerificationLabel(grVer), // Label and required are needed if optional verification choice form is shown.
required: required
};
}
// the reason we have this variable is because we want to have google auth as the last varification on the page
// for user usability
var googleAuthFound = -1;
for (i = 0; i < verifications.length; i++) {
var verId = verifications[i].id;
grVer.get(verId);
var type = grVer.type;
if (type == this.VERIFY_TYPE) {
var verifyTypeQuestion = new SNC.PwdVerificationManager().getVerificationParamValue(verId, 'label');
verifyTypeQuestions[verId] = gs.getMessage(verifyTypeQuestion);
info = this._getVerifyTypeInfo(verifyTypeQuestions);
verifications[i].info = info;
verifyTypeQuestions = {};
} else if (type == this.QA_TYPE) {
info = this._getQATypeInfo(verId, requestId, userId, res);
verifications[i].info = info;
} else if (type == this.SMS_TYPE) {
info = this._getSMSCodeTypeInfo(verId, userId, requestId);
if (info.error)
res.error = info.error;
verifications[i].info = info;
} else if (type == this.GOOGLE_AUTH_TYPE) {
verifications[i].info = this._getGoogleAuthTypeInfo(verId);
googleAuthFound = i;
} else if (type == this.EMAIL_TYPE) {
verifications[i].info = this._getEmailTypeInfo(verId, userId, requestId);
} else if (type == this.SOFTPIN_TYPE) {
verifications[i].info = this._getSoftPinTypeInfo(verId);
} else {
var verName = getVerificationLabel(grVer);
trackingMgr.createActivity("Error", "Verification", 'Verification "' + verName + '" are not supported in Desktop Integration', requestId);
res.error = gs.getMessage('The "{0}" verification method is not supported.', verName);
}
if (res.error) {
res.status = PwdConstants.WIN_STATUS_ERROR;
return res;
}
}
if (googleAuthFound > -1) {
var temp = verifications[verifications.length - 1];
verifications[verifications.length - 1] = verifications[googleAuthFound];
verifications[googleAuthFound] = temp;
}
res.status = PwdConstants.WIN_STATUS_OK;
res.info.email_reset_url = grRequest.process.email_password_reset_url || false;
res.info.verifications = verifications;
res.verification_selection = verificationResult.verification_selection;
res.min_selections = verificationResult.min_selections;
res.panel_label = {
verification_title: gs.getMessage('Verifications'),
required_ver: gs.getMessage('Mandatory Verifications'),
optional: gs.getMessage('Optional Verifications (You must select {0})'),
no_required_ver: gs.getMessage('There are no mandatory verifications')
};
return res;
},
_getEmailTypeInfo: function(verificationId, userId, requestId) {
var emailAddresses = new PwdDeviceHelper().getDevicesOrEmailAddresses(userId, requestId, 'Email');
var isSubscribed = new PwdNotificationHelper().isUserSubscribedToEmail(userId);
if (isSubscribed) {
emailAddresses = this._getDevicesOrEmailAddresses(userId, 'Email');
}
else if (emailAddresses != null) {
emailAddresses = [PwdMaskHelper.maskEmail(emailAddresses)];
}
if (emailAddresses.length == 0) {
trackingMgr.createActivity("Warning", "Verification", "User needs to authorize at least one email to use the Email type verification", requestId);
return {
error: "invalid_user"
};
}
var subtitle = isSubscribed ? gs.getMessage("Click Send Verification Code to send a code to the following email(s):") :
gs.getMessage("Click Send Verification Code to send a password reset verification code to the email listed on your profile:");
return {
type: "email",
elements: {
title: new SNC.PwdVerification(verificationId).getLabel(),
subtitle: subtitle,
send_code: gs.getMessage('Send Verification Code'),
enter_code: gs.getMessage('Enter verification code'),
resend_code: gs.getMessage('Resend Verification Code'),
mode: isSubscribed ? 'subscription' : 'notEnrolled',
email_addresses: emailAddresses
}
};
},
_getGoogleAuthTypeInfo: function(verificationId) {
return {
type: "google_auth",
elements: {
title: new SNC.PwdVerification(verificationId).getLabel(),
subtitle: gs.getMessage('Enter the code generated by your authenticator app'),
enter_code: gs.getMessage('Enter verification code')
}
};
},
_getSoftPinTypeInfo: function(verificationId) {
var subtitle = new SNC.PwdVerificationManager().getVerificationParamValue(verificationId, 'question');
return {
type: "softpin",
elements: {
title: new SNC.PwdVerification(verificationId).getLabel(),
subtitle: gs.getMessage(subtitle)
}
};
},
/**
* Get either the devices (phone numbers) or email addresses associated with a user. If they are below
* a length threshold then they will be masked.
* @param {string} userId
* @param {string} type - SMS | Email
* @returns {Array<String>} [xxxx1234, xxxx5678] or [exa****ple@domain.com, ...]
* @private
*/
_getDevicesOrEmailAddresses: function(userId, type) {
var devices = [];
var gr = new GlideRecord('cmn_notif_device');
gr.addActiveQuery();
gr.addQuery('user', userId);
gr.addQuery('type', type);
gr.orderBy('name');
gr.query();
while (gr.next()) {
var grNM = GlideRecord('cmn_notif_message');
grNM.addQuery('device', gr.getValue('sys_id'));
grNM.addActiveQuery();
grNM.query();
while (grNM.next()) {
var filter = grNM.getValue('notification_filter'); // unsubscribe = c1bfa4040a0a0b8b001eeb0f3f5ee961
var notif = grNM.getValue('notification');
// only return subscribed
if (filter == null && notif == this.PWD_MESSAGE) {
if (type == 'Email')
devices.push(PwdMaskHelper.maskEmail(gr.getValue('email_address')));
else
devices.push(PwdMaskHelper.maskPhone(gr.getValue('phone_number')));
}
}
}
//If autoenroll enabled for email verification then get the email_address from user profile
if (type == 'Email') {
if (devices.length == 0) {
var pwdVerTypGr = new GlideRecord('pwd_verification_type');
pwdVerTypGr.get(this.EMAIL_TYPE);
if (pwdVerTypGr.getValue('auto_enroll')) {
var emailOnProfile = new PwdNotificationHelper().getEmailFromProfile(userId);
if (emailOnProfile) {
devices.push(PwdMaskHelper.maskEmail(emailOnProfile));
}
}
}
}
return devices;
},
_getQATypeInfo: function(verificationId, requestId, userId, res, addId) {
var qObj = this._getQuestions(verificationId, requestId, userId);
if (qObj.error) {
res.error = qObj.error;
return;
}
var info = {
type: "qa",
elements: {
title: new SNC.PwdVerification(verificationId).getLabel(),
questions: qObj.questions
}
};
return info;
},
_getSMSCodeTypeInfo: function(verificationId, userId, requestId) {
var sysPhone = new PwdDeviceHelper().getDevicesOrEmailAddresses(userId, requestId, 'SMS');
if (new PwdNotificationHelper().isUserSubscribed(userId)) {
var devices = this._getDevicesOrEmailAddresses(userId, 'SMS');
var mode = 'subscription';
} else if (sysPhone != null) {
var providers = [];
mode = 'mobile';
devices = [PwdMaskHelper.maskPhone(sysPhone)];
// If notify is enabled, everything will appear the same as if they're enrolled. If not enabled, we need
// to offer a selection of providers for the user to choose from
if (!GlidePluginManager.isRegistered('com.snc.notify')) {
var provGr = new GlideRecord('cmn_notif_service_provider');
provGr.addActiveQuery();
provGr.addQuery('type', 'SMS');
provGr.orderBy('name');
provGr.query();
while (provGr.next()) {
providers.push({
name: provGr.getValue('name'),
sys_id: provGr.getUniqueValue()
});
}
}
} else {
trackingMgr.createActivity("Warning", "Verification", "User needs to authorize at least one device to use the SMS type verification", requestId);
return {
error: "invalid_user"
};
}
var info = {
type: "sms",
elements: {
title: new SNC.PwdVerification(verificationId).getLabel(),
subtitle: gs.getMessage('Click the Send Verification Code button to send a verification code to the following devices'),
send_code: gs.getMessage('Send Verification Code'),
enter_code: gs.getMessage('Enter verification code'),
resend_code: gs.getMessage('Resend Verification Code'),
device_numbers: devices,
mode: mode,
providers: providers,
providers_label: gs.getMessage('Provider:'),
provider_placeholder: gs.getMessage("Select a provider")
}
};
return info;
},
type: 'PwdResetPageInfo_V2'
});
Sys ID
8dbee16b530203003248cfa018dc349e