mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-10 15:08:28 +03:00
Changes for #349
This commit is contained in:
parent
80eed213d9
commit
a06b59784a
3 changed files with 27 additions and 16 deletions
|
|
@ -8,8 +8,8 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
const
|
||||
NAME = 'Two Factor Authentication',
|
||||
VERSION = '2.15.0',
|
||||
RELEASE = '2022-04-25',
|
||||
REQUIRED = '2.15.0',
|
||||
RELEASE = '2022-04-29',
|
||||
REQUIRED = '2.15.1',
|
||||
CATEGORY = 'Login',
|
||||
DESCRIPTION = 'Provides support for TOTP 2FA';
|
||||
|
||||
|
|
@ -47,7 +47,13 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
public function FilterAppData($bAdmin, &$aResult)
|
||||
{
|
||||
if (!$bAdmin && \is_array($aResult)/* && isset($aResult['Auth']) && !$aResult['Auth']*/) {
|
||||
$aResult['RequireTwoFactor'] = $this->Config()->Get('plugin', 'force_two_factor_auth', false);
|
||||
$aResult['RequireTwoFactor'] = (bool) $this->Config()->Get('plugin', 'force_two_factor_auth', false);
|
||||
|
||||
$aResult['SetupTwoFactor'] = false;
|
||||
if ($aResult['RequireTwoFactor'] && !empty($aResult['Auth'])) {
|
||||
$aData = $this->getTwoFactorInfo($this->getMainAccountFromToken());
|
||||
$aResult['SetupTwoFactor'] = empty($aResult['IsSet']) || empty($mData['Enable']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +61,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
{
|
||||
if ($this->TwoFactorAuthProvider($oAccount)) {
|
||||
$aData = $this->getTwoFactorInfo($oAccount);
|
||||
if ($aData && isset($aData['IsSet'], $aData['Enable']) && !empty($aData['Secret']) && $aData['IsSet'] && $aData['Enable']) {
|
||||
if (isset($aData['IsSet'], $aData['Enable']) && !empty($aData['Secret']) && $aData['IsSet'] && $aData['Enable']) {
|
||||
$sCode = \trim($this->jsonParam('totp_code', ''));
|
||||
if (empty($sCode)) {
|
||||
$this->Logger()->Write("TFA: Code required for {$oAccount->Email()}");
|
||||
|
|
|
|||
|
|
@ -1,8 +1,15 @@
|
|||
|
||||
(rl => {
|
||||
|
||||
const
|
||||
forceTOTP = () => {
|
||||
if (rl.settings.get('SetupTwoFactor')) {
|
||||
setTimeout(() => document.location.hash = '#/settings/two-factor-auth', 50);
|
||||
}
|
||||
};
|
||||
|
||||
addEventListener('rl-view-model', e => {
|
||||
if (e.detail && 'Login' === e.detail.viewModelTemplateID) {
|
||||
if ('Login' === e.detail.viewModelTemplateID) {
|
||||
const container = e.detail.viewModelDom.querySelector('#plugin-Login-BottomControlGroup'),
|
||||
placeholder = 'PLUGIN_2FA/LABEL_TWO_FACTOR_CODE';
|
||||
if (container) {
|
||||
|
|
@ -19,13 +26,10 @@
|
|||
});
|
||||
|
||||
// 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';
|
||||
addEventListener('sm-show-screen', e => {
|
||||
if ('settings' !== e.detail && rl.settings.get('SetupTwoFactor')) {
|
||||
e.preventDefault();
|
||||
forceTOTP();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -56,11 +56,12 @@ class TwoFactorAuthSettings
|
|||
value = !!value;
|
||||
if (value && this.twoFactorTested()) {
|
||||
this.viewEnable_(value);
|
||||
Remote.enableTwoFactor(fn, value);
|
||||
Remote.enableTwoFactor(iError => {
|
||||
fn(iError);
|
||||
rl.settings.get('RequireTwoFactor') && rl.settings.set('SetupTwoFactor', !!iError);
|
||||
}, value);
|
||||
} else {
|
||||
if (!value) {
|
||||
this.viewEnable_(value);
|
||||
}
|
||||
value || this.viewEnable_(value);
|
||||
Remote.enableTwoFactor(fn, false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue