diff --git a/composer.json b/composer.json index 38afe23..ac71430 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,8 @@ "require": { "php": ">=5.6", "oxid-esales/oxideshop-metapackage-ce": "~6.0.3 || ~6.1.0", - "spomky-labs/otphp": "^8.3 || ^9.0" + "spomky-labs/otphp": "^8.3 || ^9.0", + "bacon/bacon-qr-code": "^1.0 || ^2.0" }, "autoload": { "psr-4": { diff --git a/src/Application/Model/d3totp.php b/src/Application/Model/d3totp.php index 782decf..38c256a 100644 --- a/src/Application/Model/d3totp.php +++ b/src/Application/Model/d3totp.php @@ -15,6 +15,10 @@ namespace D3\Totp\Application\Model; +use BaconQrCode\Renderer\Image\SvgImageBackEnd; +use BaconQrCode\Renderer\ImageRenderer; +use BaconQrCode\Renderer\RendererStyle\RendererStyle; +use BaconQrCode\Writer; use D3\ModCfg\Application\Model\d3database; use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException; use Doctrine\DBAL\DBALException; @@ -138,7 +142,7 @@ class d3totp extends BaseModel $this->totp = TOTP::create($seed ? $seed : $this->getSavedSecret()); $this->totp->setLabel($this->getUser()->getFieldData('oxusername') ? $this->getUser()->getFieldData('oxusername') - : null + : '' ); } $this->totp->setIssuer(Registry::getConfig()->getActiveShop()->getFieldData('oxname')); @@ -165,6 +169,21 @@ class d3totp extends BaseModel return $this->getTotp()->getQrCodeUri(); } + /** + * @return string + */ + public function getQrCodeElement() + { + /** @var ImageRenderer $renderer */ + $renderer = oxNew(ImageRenderer::class, + oxNew(RendererStyle::class, 200), + oxNew(SvgImageBackEnd::class) + ); + /** @var Writer $writer */ + $writer = oxNew(Writer::class, $renderer); + return $writer->writeString($this->getTotp()->getProvisioningUri()); + } + /** * @return string */ diff --git a/src/Application/views/admin/tpl/d3user_totp.tpl b/src/Application/views/admin/tpl/d3user_totp.tpl index 59af97a..959fa98 100644 --- a/src/Application/views/admin/tpl/d3user_totp.tpl +++ b/src/Application/views/admin/tpl/d3user_totp.tpl @@ -48,7 +48,7 @@ [{oxmultilang ident="D3_TOTP_QRCODE"}]  - + [{$totp->getQrCodeElement()}] [{oxinputhelp ident="D3_TOTP_QRCODE_HELP"}]