2021-07-23 19:36:38 +08:00
|
|
|
|
|
|
|
(rl => {
|
|
|
|
|
2022-04-29 19:23:04 +08:00
|
|
|
const
|
|
|
|
forceTOTP = () => {
|
|
|
|
if (rl.settings.get('SetupTwoFactor')) {
|
|
|
|
setTimeout(() => document.location.hash = '#/settings/two-factor-auth', 50);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-04-25 22:21:16 +08:00
|
|
|
addEventListener('rl-view-model', e => {
|
2022-04-29 19:23:04 +08:00
|
|
|
if ('Login' === e.detail.viewModelTemplateID) {
|
2021-07-23 19:36:38 +08:00
|
|
|
const container = e.detail.viewModelDom.querySelector('#plugin-Login-BottomControlGroup'),
|
2022-04-25 22:21:16 +08:00
|
|
|
placeholder = 'PLUGIN_2FA/LABEL_TWO_FACTOR_CODE';
|
2021-07-23 19:36:38 +08:00
|
|
|
if (container) {
|
2021-07-23 21:58:54 +08:00
|
|
|
container.prepend(Element.fromHTML('<div class="controls">'
|
2021-11-16 19:35:11 +08:00
|
|
|
+ '<span class="fontastic">⏱</span>'
|
|
|
|
+ '<input name="totp_code" type="text" class="input-block-level"'
|
|
|
|
+ ' pattern="[0-9]*" inputmode="numeric"'
|
2022-09-20 18:26:12 +08:00
|
|
|
+ ' autocomplete="off" autocorrect="off" autocapitalize="none"'
|
2021-11-16 19:35:11 +08:00
|
|
|
+ ' data-bind="textInput: totp, disable: submitRequest" data-i18n="[placeholder]'+placeholder
|
|
|
|
+ '" placeholder="'+rl.i18n(placeholder)+'">'
|
2021-07-23 19:36:38 +08:00
|
|
|
+ '</div>'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-04-25 22:21:16 +08:00
|
|
|
// https://github.com/the-djmaze/snappymail/issues/349
|
2022-04-29 19:23:04 +08:00
|
|
|
addEventListener('sm-show-screen', e => {
|
|
|
|
if ('settings' !== e.detail && rl.settings.get('SetupTwoFactor')) {
|
|
|
|
e.preventDefault();
|
|
|
|
forceTOTP();
|
2022-04-25 22:21:16 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-23 19:36:38 +08:00
|
|
|
})(window.rl);
|