mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-02 21:12:02 +08:00
TOTP plugin improved QRCode view
This commit is contained in:
parent
fded75e3f4
commit
375f715b78
1 changed files with 15 additions and 15 deletions
|
@ -99,6 +99,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
'User' => $sEmail,
|
||||
'Enable' => false,
|
||||
'Secret' => $sSecret,
|
||||
'QRCode' => static::getQRCode($sEmail, $sSecret),
|
||||
'BackupCodes' => \implode(' ', $aCodes)
|
||||
))
|
||||
);
|
||||
|
@ -106,6 +107,18 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
return $this->jsonResponse(__FUNCTION__, $this->getTwoFactorInfo($oAccount));
|
||||
}
|
||||
|
||||
private static function getQRCode(string $email, string $secret) : string
|
||||
{
|
||||
$email = \rawurlencode($email);
|
||||
// $issuer = \rawurlencode(\RainLoop\API::Config()->Get('webmail', 'title', 'SnappyMail'));
|
||||
$QR = \SnappyMail\QRCode::getMinimumQRCode(
|
||||
// "otpauth://totp/{$issuer}:{$email}?secret={$secret}&issuer={$issuer}",
|
||||
"otpauth://totp/{$email}?secret={$secret}",
|
||||
\SnappyMail\QRCode::ERROR_CORRECT_LEVEL_M
|
||||
);
|
||||
return $QR->__toString();
|
||||
}
|
||||
|
||||
public function DoShowTwoFactorSecret() : array
|
||||
{
|
||||
$oAccount = $this->getMainAccountFromToken();
|
||||
|
@ -117,14 +130,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$aResult = $this->getTwoFactorInfo($oAccount);
|
||||
unset($aResult['BackupCodes']);
|
||||
|
||||
$name = \rawurlencode($oAccount->Email());
|
||||
// $issuer = \rawurlencode(\RainLoop\API::Config()->Get('webmail', 'title', 'SnappyMail'));
|
||||
$QR = \SnappyMail\QRCode::getMinimumQRCode(
|
||||
// "otpauth://totp/{$issuer}:{$name}?secret={$aResult['Secret']}&issuer={$issuer}",
|
||||
"otpauth://totp/{$name}?secret={$aResult['Secret']}",
|
||||
\SnappyMail\QRCode::ERROR_CORRECT_LEVEL_M
|
||||
);
|
||||
$aResult['QRCode'] = $QR->__toString();
|
||||
$aResult['QRCode'] = static::getQRCode($oAccount->Email(), $aResult['Secret']);
|
||||
|
||||
return $this->jsonResponse(__FUNCTION__, $aResult);
|
||||
}
|
||||
|
@ -232,7 +238,6 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
'IsSet' => false,
|
||||
'Enable' => false,
|
||||
'Secret' => '',
|
||||
'UrlTitle' => '',
|
||||
'BackupCodes' => ''
|
||||
);
|
||||
|
||||
|
@ -259,7 +264,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$aResult['Enable'] = isset($mData['Enable']) ? !!$mData['Enable'] : false;
|
||||
$aResult['Secret'] = $mData['Secret'];
|
||||
$aResult['BackupCodes'] = $mData['BackupCodes'];
|
||||
$aResult['UrlTitle'] = $this->Config()->Get('webmail', 'title', '');
|
||||
$aResult['QRCode'] = static::getQRCode($oAccount->Email(), $mData['Secret']);
|
||||
}
|
||||
|
||||
if ($bRemoveSecret)
|
||||
|
@ -269,11 +274,6 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
unset($aResult['Secret']);
|
||||
}
|
||||
|
||||
if (isset($aResult['UrlTitle']))
|
||||
{
|
||||
unset($aResult['UrlTitle']);
|
||||
}
|
||||
|
||||
if (isset($aResult['BackupCodes']))
|
||||
{
|
||||
unset($aResult['BackupCodes']);
|
||||
|
|
Loading…
Reference in a new issue