mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 17:07:03 +03:00
Improved 2fa plugin
This commit is contained in:
parent
906959b2c2
commit
2ed328d07c
1 changed files with 14 additions and 11 deletions
|
|
@ -31,7 +31,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
// $this->addCss('style.less');
|
// $this->addCss('style.less');
|
||||||
$this->addJs('js/TwoFactorAuthSettings.js');
|
$this->addJs('js/TwoFactorAuthSettings.js');
|
||||||
|
|
||||||
$this->addHook('login.success', 'LoginProcess');
|
$this->addHook('login.success', 'DoLogin');
|
||||||
|
|
||||||
$this->addJsonHook('GetTwoFactorInfo', 'DoGetTwoFactorInfo');
|
$this->addJsonHook('GetTwoFactorInfo', 'DoGetTwoFactorInfo');
|
||||||
$this->addJsonHook('CreateTwoFactorSecret', 'DoCreateTwoFactorSecret');
|
$this->addJsonHook('CreateTwoFactorSecret', 'DoCreateTwoFactorSecret');
|
||||||
|
|
@ -56,12 +56,10 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stripped from \RainLoop\Actions::LoginProcess
|
public function DoLogin(\RainLoop\Model\Account $oAccount)
|
||||||
public function LoginProcess(\RainLoop\Model\Account $oAccount)
|
|
||||||
{
|
{
|
||||||
$bSkipTwoFactorAuth = !!$this->Manager()->Actions()->GetAccount();
|
// Stripped from \RainLoop\Actions::LoginProcess
|
||||||
// 2FA
|
if ($this->TwoFactorAuthProvider($oAccount)) {
|
||||||
if (!$bSkipTwoFactorAuth && $this->TwoFactorAuthProvider($oAccount)) {
|
|
||||||
$aData = $this->getTwoFactorInfo($oAccount);
|
$aData = $this->getTwoFactorInfo($oAccount);
|
||||||
if ($aData && isset($aData['IsSet'], $aData['Enable']) && !empty($aData['Secret']) && $aData['IsSet'] && $aData['Enable']) {
|
if ($aData && isset($aData['IsSet'], $aData['Enable']) && !empty($aData['Secret']) && $aData['IsSet'] && $aData['Enable']) {
|
||||||
$sSecretHash = \md5(APP_SALT . $aData['Secret'] . Utils::Fingerprint());
|
$sSecretHash = \md5(APP_SALT . $aData['Secret'] . Utils::Fingerprint());
|
||||||
|
|
@ -104,6 +102,15 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
// Stripped from \RainLoop\Actions\User::DoLogin
|
||||||
|
if (Notifications::AccountTwoFactorAuthRequired === $oException->getCode())
|
||||||
|
{
|
||||||
|
return $this->DefaultResponse(__FUNCTION__, true, array(
|
||||||
|
'TwoFactorAuth' => true
|
||||||
|
));
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DoGetTwoFactorInfo() : array
|
public function DoGetTwoFactorInfo() : array
|
||||||
|
|
@ -257,14 +264,10 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
private $oTwoFactorAuthProvider;
|
private $oTwoFactorAuthProvider;
|
||||||
protected function TwoFactorAuthProvider(\RainLoop\Model\Account $oAccount) : ?TwoFactorAuthInterface
|
protected function TwoFactorAuthProvider(\RainLoop\Model\Account $oAccount) : ?TwoFactorAuthInterface
|
||||||
{
|
{
|
||||||
if (!$this->Manager()->Actions()->GetCapa(false, static::Capa_TWO_FACTOR, $oAccount)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if ($this->Config()->Get('plugin', 'allow_two_factor_auth', 0))
|
// if ($this->Config()->Get('plugin', 'allow_two_factor_auth', 0))
|
||||||
// if ($this->Config()->Get('plugin', 'force_two_factor_auth', 0))
|
// if ($this->Config()->Get('plugin', 'force_two_factor_auth', 0))
|
||||||
|
|
||||||
if (!$this->oTwoFactorAuthProvider) {
|
if (!$this->oTwoFactorAuthProvider && $this->Manager()->Actions()->GetCapa(false, static::Capa_TWO_FACTOR, $oAccount)) {
|
||||||
require __DIR__ . '/providers/interface.php';
|
require __DIR__ . '/providers/interface.php';
|
||||||
require __DIR__ . '/providers/totp.php';
|
require __DIR__ . '/providers/totp.php';
|
||||||
$this->oTwoFactorAuthProvider = new TwoFactorAuthTotp();
|
$this->oTwoFactorAuthProvider = new TwoFactorAuthTotp();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue