Add support for global 2FA enforcement #349

This commit is contained in:
the-djmaze 2022-04-25 16:21:16 +02:00
parent 375f715b78
commit 8b3cfc7a67
15 changed files with 85 additions and 54 deletions

View file

@ -1,10 +1,10 @@
(rl => {
rl && addEventListener('rl-view-model', e => {
addEventListener('rl-view-model', e => {
if (e.detail && 'Login' === e.detail.viewModelTemplateID) {
const container = e.detail.viewModelDom.querySelector('#plugin-Login-BottomControlGroup'),
placeholder = 'LOGIN/LABEL_TWO_FACTOR_CODE';
placeholder = 'PLUGIN_2FA/LABEL_TWO_FACTOR_CODE';
if (container) {
container.prepend(Element.fromHTML('<div class="controls">'
+ '<span class="fontastic">⏱</span>'
@ -18,4 +18,15 @@
}
});
// https://github.com/the-djmaze/snappymail/issues/349
let code;
addEventListener('sm-user-login', e => {
code = e.detail.get('totp_code');
});
addEventListener('sm-user-login-response', e => {
if (e.detail && !e.detail.error && rl.settings.get('RequireTwoFactor') && !code) {
document.location.hash = '#/settings/two-factor-auth';
}
});
})(window.rl);

View file

@ -70,12 +70,12 @@ class TwoFactorAuthSettings
// translatorTrigger();
return this.twoFactorTested() || this.viewEnable_()
? ''
: rl.i18n('POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_TEST_BEFORE_DESC');
: rl.i18n('PLUGIN_2FA/TWO_FACTOR_SECRET_TEST_BEFORE_DESC');
},
viewTwoFactorStatus: () => {
// translatorTrigger();
return rl.i18n('POPUPS_TWO_FACTOR_CFG/TWO_FACTOR_SECRET_'
return rl.i18n('PLUGIN_2FA/TWO_FACTOR_SECRET_'
+ (this.twoFactorStatus() ? '' : 'NOT_')
+ 'CONFIGURED_DESC'
);
@ -202,7 +202,7 @@ class TwoFactorAuthTestPopupView extends rl.pluginPopupView {
rl.addSettingsViewModel(
TwoFactorAuthSettings,
'TwoFactorAuthSettings',
'POPUPS_TWO_FACTOR_CFG/LEGEND_TWO_FACTOR_AUTH',
'PLUGIN_2FA/LEGEND_TWO_FACTOR_AUTH',
'two-factor-auth'
);