Ability to show secret or backup codes
This commit is contained in:
parent
8802ae24ba
commit
29e0c8f790
|
@ -34,6 +34,11 @@ const MciViewIds = {
|
||||||
customRangeStart : 10, // 10+ = customs
|
customRangeStart : 10, // 10+ = customs
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DefaultMsg = {
|
||||||
|
otpNotEnabled : '2FA/OTP is not currently enabled for this account.',
|
||||||
|
noBackupCodes : 'No backup codes remaining or set.',
|
||||||
|
};
|
||||||
|
|
||||||
exports.getModule = class User2FA_OTPConfigModule extends MenuModule {
|
exports.getModule = class User2FA_OTPConfigModule extends MenuModule {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
|
@ -42,6 +47,12 @@ exports.getModule = class User2FA_OTPConfigModule extends MenuModule {
|
||||||
this.menuMethods = {
|
this.menuMethods = {
|
||||||
showQRCode : (formData, extraArgs, cb) => {
|
showQRCode : (formData, extraArgs, cb) => {
|
||||||
return this.showQRCode(cb);
|
return this.showQRCode(cb);
|
||||||
|
},
|
||||||
|
showSecret : (formData, extraArgs, cb) => {
|
||||||
|
return this.showSecret(cb);
|
||||||
|
},
|
||||||
|
showBackupCodes : (formData, extraArgs, cb) => {
|
||||||
|
return this.showBackupCodes(cb);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -101,33 +112,61 @@ exports.getModule = class User2FA_OTPConfigModule extends MenuModule {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
showQRCode(cb) {
|
displayDetails(details, cb) {
|
||||||
const otp = otpFromType(this.client.user.getProperty(UserProps.AuthFactor2OTP));
|
const modOpts = {
|
||||||
let qrCodeAscii = '';
|
extraArgs : {
|
||||||
if(!otp) {
|
artData : iconv.encode(`${details}\r\n`, 'cp437'),
|
||||||
qrCodeAscii = '2FA/OTP is not currently enabled for this account';
|
}
|
||||||
|
};
|
||||||
|
this.gotoMenu(
|
||||||
|
this.menuConfig.config.user2FAOTP_ShowDetails || 'user2FAOTP_ShowDetails',
|
||||||
|
modOpts,
|
||||||
|
cb
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showQRCode(cb) {
|
||||||
|
const otp = otpFromType(this.client.user.getProperty(UserProps.AuthFactor2OTP));
|
||||||
|
|
||||||
|
let qrCode;
|
||||||
|
if(!otp) {
|
||||||
|
qrCode = this.config.otpNotEnabled || DefaultMsg.otpNotEnabled;
|
||||||
|
} else {
|
||||||
const qrOptions = {
|
const qrOptions = {
|
||||||
username : this.client.user.username,
|
username : this.client.user.username,
|
||||||
qrType : 'ascii',
|
qrType : 'ascii',
|
||||||
};
|
};
|
||||||
qrCodeAscii = createQRCode(
|
qrCode = createQRCode(
|
||||||
otp,
|
otp,
|
||||||
qrOptions,
|
qrOptions,
|
||||||
this.client.user.getProperty(UserProps.AuthFactor2OTPSecret)
|
this.client.user.getProperty(UserProps.AuthFactor2OTPSecret)
|
||||||
).replace(/\n/g, '\r\n');
|
).replace(/\n/g, '\r\n');
|
||||||
|
|
||||||
const modOpts = {
|
|
||||||
extraArgs : {
|
|
||||||
artData : iconv.encode(`${qrCodeAscii}\r\n`, 'cp437'),
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
this.gotoMenu(
|
return this.displayDetails(qrCode, cb);
|
||||||
this.menuConfig.config.mainMenuUser2FAOTP_ShowQR || 'mainMenuUser2FAOTP_ShowQR',
|
}
|
||||||
modOpts,
|
|
||||||
cb
|
showSecret(cb) {
|
||||||
);
|
const info =
|
||||||
|
this.client.user.getProperty(UserProps.AuthFactor2OTPSecret) ||
|
||||||
|
this.config.otpNotEnabled || DefaultMsg.otpNotEnabled;
|
||||||
|
return this.displayDetails(info, cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
showBackupCodes(cb) {
|
||||||
|
let info;
|
||||||
|
const noBackupCodes = this.config.noBackupCodes || DefaultMsg.noBackupCodes;
|
||||||
|
if(!this.isOTPEnabledForUser()) {
|
||||||
|
info = this.config.otpNotEnabled || DefaultMsg.otpNotEnabled;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
info = JSON.parse(this.client.user.getProperty(UserProps.AuthFactor2OTPBackupCodes) || '[]').join(', ');
|
||||||
|
info = info || noBackupCodes;
|
||||||
|
} catch(e) {
|
||||||
|
info = noBackupCodes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.displayDetails(info, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
isOTPEnabledForUser() {
|
isOTPEnabledForUser() {
|
||||||
|
@ -140,8 +179,8 @@ exports.getModule = class User2FA_OTPConfigModule extends MenuModule {
|
||||||
|
|
||||||
enableToggleUpdate(idx) {
|
enableToggleUpdate(idx) {
|
||||||
const key = {
|
const key = {
|
||||||
0 : '2faDisabled',
|
0 : 'disabled',
|
||||||
1 : '2faEnabled',
|
1 : 'enabled',
|
||||||
}[idx];
|
}[idx];
|
||||||
this.updateCustomViewTextsWithFilter('menu', MciViewIds.customRangeStart, { infoText : this.getInfoText(key) } );
|
this.updateCustomViewTextsWithFilter('menu', MciViewIds.customRangeStart, { infoText : this.getInfoText(key) } );
|
||||||
}
|
}
|
||||||
|
@ -164,7 +203,7 @@ exports.getModule = class User2FA_OTPConfigModule extends MenuModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
typeSelectionUpdate(idx) {
|
typeSelectionUpdate(idx) {
|
||||||
const key = '2faType_' + this.otpTypeFromTypeSelectionIndex(idx);
|
const key = this.otpTypeFromTypeSelectionIndex(idx);
|
||||||
this.updateCustomViewTextsWithFilter('menu', MciViewIds.customRangeStart, { infoText : this.getInfoText(key) } );
|
this.updateCustomViewTextsWithFilter('menu', MciViewIds.customRangeStart, { infoText : this.getInfoText(key) } );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue