mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03: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,
|
'User' => $sEmail,
|
||||||
'Enable' => false,
|
'Enable' => false,
|
||||||
'Secret' => $sSecret,
|
'Secret' => $sSecret,
|
||||||
|
'QRCode' => static::getQRCode($sEmail, $sSecret),
|
||||||
'BackupCodes' => \implode(' ', $aCodes)
|
'BackupCodes' => \implode(' ', $aCodes)
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
|
|
@ -106,6 +107,18 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
return $this->jsonResponse(__FUNCTION__, $this->getTwoFactorInfo($oAccount));
|
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
|
public function DoShowTwoFactorSecret() : array
|
||||||
{
|
{
|
||||||
$oAccount = $this->getMainAccountFromToken();
|
$oAccount = $this->getMainAccountFromToken();
|
||||||
|
|
@ -117,14 +130,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
$aResult = $this->getTwoFactorInfo($oAccount);
|
$aResult = $this->getTwoFactorInfo($oAccount);
|
||||||
unset($aResult['BackupCodes']);
|
unset($aResult['BackupCodes']);
|
||||||
|
|
||||||
$name = \rawurlencode($oAccount->Email());
|
$aResult['QRCode'] = static::getQRCode($oAccount->Email(), $aResult['Secret']);
|
||||||
// $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();
|
|
||||||
|
|
||||||
return $this->jsonResponse(__FUNCTION__, $aResult);
|
return $this->jsonResponse(__FUNCTION__, $aResult);
|
||||||
}
|
}
|
||||||
|
|
@ -232,7 +238,6 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
'IsSet' => false,
|
'IsSet' => false,
|
||||||
'Enable' => false,
|
'Enable' => false,
|
||||||
'Secret' => '',
|
'Secret' => '',
|
||||||
'UrlTitle' => '',
|
|
||||||
'BackupCodes' => ''
|
'BackupCodes' => ''
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -259,7 +264,7 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
$aResult['Enable'] = isset($mData['Enable']) ? !!$mData['Enable'] : false;
|
$aResult['Enable'] = isset($mData['Enable']) ? !!$mData['Enable'] : false;
|
||||||
$aResult['Secret'] = $mData['Secret'];
|
$aResult['Secret'] = $mData['Secret'];
|
||||||
$aResult['BackupCodes'] = $mData['BackupCodes'];
|
$aResult['BackupCodes'] = $mData['BackupCodes'];
|
||||||
$aResult['UrlTitle'] = $this->Config()->Get('webmail', 'title', '');
|
$aResult['QRCode'] = static::getQRCode($oAccount->Email(), $mData['Secret']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bRemoveSecret)
|
if ($bRemoveSecret)
|
||||||
|
|
@ -269,11 +274,6 @@ class TwoFactorAuthPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
unset($aResult['Secret']);
|
unset($aResult['Secret']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($aResult['UrlTitle']))
|
|
||||||
{
|
|
||||||
unset($aResult['UrlTitle']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($aResult['BackupCodes']))
|
if (isset($aResult['BackupCodes']))
|
||||||
{
|
{
|
||||||
unset($aResult['BackupCodes']);
|
unset($aResult['BackupCodes']);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue