From cea9e246ba7324ddf2f8e1d153f7e8d0b5cea072 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 2 Aug 2019 23:58:20 +0200 Subject: [PATCH] initial implementation for frontend account area --- .../Controller/d3_account_totp.php | 114 ++++++++++++++++ .../translations/de/d3_totp_lang.php | 24 +++- .../views/admin/de/d3totp_lang.php | 4 +- .../blocks/page/account/inc/account_menu.tpl | 2 +- src/Application/views/tpl/d3_account_totp.tpl | 127 ++++++++++++++++++ .../Application/Model/d3_totp_user.php | 15 +++ src/metadata.php | 11 +- 7 files changed, 289 insertions(+), 8 deletions(-) create mode 100644 src/Application/Controller/d3_account_totp.php create mode 100644 src/Application/views/tpl/d3_account_totp.tpl diff --git a/src/Application/Controller/d3_account_totp.php b/src/Application/Controller/d3_account_totp.php new file mode 100644 index 0000000..bdeec95 --- /dev/null +++ b/src/Application/Controller/d3_account_totp.php @@ -0,0 +1,114 @@ +getUser(); + if (!$oUser) { + dumpvar(__LINE__); + dumpvar($this->_sThisLoginTemplate); + return $this->_sThisTemplate = $this->_sThisLoginTemplate; + } + + $this->addTplParam('user', $this->getUser()); + + return parent::render(); + } + + /** + * @param $aCodes + */ + public function setBackupCodes($aCodes) + { + $this->aBackupCodes = $aCodes; + } + + /** + * @return string + */ + public function getBackupCodes() + { + return implode(PHP_EOL, $this->aBackupCodes); + } + + /** + * @return int + * @throws DatabaseConnectionException + */ + public function getAvailableBackupCodeCount() + { + $oBackupCodeList = oxNew(d3backupcodelist::class); + return $oBackupCodeList->getAvailableCodeCount($this->getUser()->getId()); + } + + public function create() + { + if (Registry::getRequest()->getRequestEscapedParameter('totp_use') === '1') { + try { + /** @var d3_totp_user $oUser */ + $oUser = $this->getUser(); + + /** @var d3totp $oTotp */ + $oTotp = oxNew(d3totp::class); + $oTotpBackupCodes = oxNew(d3backupcodelist::class); + + $aParams = [ + 'd3totp__usetotp' => 1, + 'd3totp__oxuserid' => $oUser->getId() + ]; + $seed = Registry::getRequest()->getRequestEscapedParameter("secret"); + $otp = Registry::getRequest()->getRequestEscapedParameter("otp"); + + $oTotp->saveSecret($seed); + $oTotp->assign($aParams); + $oTotp->verify($otp, $seed); + $oTotpBackupCodes->generateBackupCodes($oUser->getId()); + $oTotp->setId(); + + $oTotp->save(); + $oTotpBackupCodes->save(); + } catch (Exception $oExcp) { + Registry::get(UtilsView::class)->addErrorToDisplay($oExcp); + } + } + } + + /** + * @throws DatabaseConnectionException + * @throws DBALException + */ + public function delete() + { + if (Registry::getRequest()->getRequestEscapedParameter('totp_use') != 1) { + + $oUser = $this->getUser(); + /** @var d3totp $oTotp */ + $oTotp = oxNew(d3totp::class); + if ($oUser && $oUser->getId()) { + $oTotp->loadByUserId($oUser->getId()); + $oTotp->delete(); + } + } + } +} \ No newline at end of file diff --git a/src/Application/translations/de/d3_totp_lang.php b/src/Application/translations/de/d3_totp_lang.php index a35d67b..78c204d 100644 --- a/src/Application/translations/de/d3_totp_lang.php +++ b/src/Application/translations/de/d3_totp_lang.php @@ -21,10 +21,32 @@ $aLang = [ 'charset' => 'UTF-8', 'D3_TOTP_INPUT' => 'Authentisierungscode', - 'D3_TOTP_INPUT_HELP' => 'Das Einmalpasswort erhalten Sie von der Zweifaktorauthentisierung-App auf Ihrem Gerät.', + 'D3_TOTP_INPUT_HELP' => 'Das Einmalpasswort erhalten Sie von der Zwei-Faktor-Authentisierungs-App auf Ihrem Gerät.', 'D3_TOTP_SUBMIT_LOGIN' => 'Anmelden', 'D3_TOTP_CANCEL_LOGIN' => 'Anmeldung abbrechen', 'D3_TOTP_BREADCRUMB' => 'Einmalpasswort-Anmeldung', 'D3_TOTP_ERROR_UNVALID' => 'Das Einmalpasswort ist ungültig.', 'D3_TOTP_ACCOUNT' => '2-Faktor-Authentisierung', + + 'D3_TOTP_ACCOUNT_USE' => '2-Faktor-Authentisierung verwenden', + + 'D3_TOTP_REGISTERNEW' => 'neue Registrierung erstellen', + 'D3_TOTP_QRCODE' => 'QR-Code', + 'D3_TOTP_QRCODE_HELP' => 'Scannen Sie diesen QR-Code mit Ihrer Authentisierungs-App, um dieses Benutzerkonto dort zu hinterlegen.', + 'D3_TOTP_SECRET' => 'QR-Code kann nicht gescannt werden?', + 'D3_TOTP_SECRET_HELP' => 'Setzen Sie keine App ein, die den QR-Code scannen kann, können Sie diese Zeichenkette auch in Ihr Authentisierungstool kopieren. Stellen Sie bitte zusätzlich die Passwortlänge auf 6 Zeichen und das Zeitinterval auf 30 Sekunden ein.', + 'D3_TOTP_CURROTP' => 'Bestätigung mit Einmalpasswort', + 'D3_TOTP_CURROTP_HELP' => 'Haben Sie dieses Kundenkonto in Ihrer Authentisierungs-App registriert, generieren Sie damit ein Einmalpasswort, tragen Sie es hier ein und senden das Formular direkt darauf hin ab.', + + 'D3_TOTP_REGISTEREXIST' => 'vorhandene Registrierung', + 'D3_TOTP_REGISTERDELETE_DESC' => 'Um die Registrierung zu ändern, löschen Sie diese bitte vorerst. Sie können sofort im Anschluss eine neue Registrierung anlegen.
Wenn Sie die Registrierung löschen, ist das Konto nicht mehr durch die Zwei-Faktor-Authentisierung geschützt.', + 'D3_TOTP_REGISTERDELETE_CONFIRM' => 'Soll die bestehende 2-Faktor-Authentisierung gelöscht werden?', + + 'D3_TOTP_BACKUPCODES' => 'Backupcodes', + 'D3_TOTP_BACKUPCODES_DESC' => 'Mit diesen Backupcodes können Sie sich anmelden, wenn die Generierung des Einmalpasswortes nicht möglich ist (z.B. Gerät verloren oder neu installiert). Sie können dann die Einstellungen zur Verwendung der 2-Faktor-Authentisierung ändern oder einen neuen Zugang erstellen. Speichern Sie sich diese Codes bitte in diesem Moment sicher ab. Nach Verlassen dieser Seite können diese Codes nicht erneut angezeigt werden.', + 'D3_TOTP_AVAILBACKUPCODECOUNT' => 'noch %1$s Backupcodes verfügbar', + 'D3_TOTP_AVAILBACKUPCODECOUNT_DESC' => 'Um neue Backupcodes zu erstellen, löschen Sie die bestehende Registrierung und legen diese bitte neu an.', + + 'D3_TOTP_ACCOUNT_SAVE' => 'Einstellungen übernehmen', + ]; diff --git a/src/Application/views/admin/de/d3totp_lang.php b/src/Application/views/admin/de/d3totp_lang.php index 186f7b9..be7d798 100644 --- a/src/Application/views/admin/de/d3totp_lang.php +++ b/src/Application/views/admin/de/d3totp_lang.php @@ -21,7 +21,7 @@ $aLang = [ 'charset' => 'UTF-8', 'TOTP_INPUT' => 'Authentisierungscode', - 'TOTP_INPUT_HELP' => 'Das Einmalpasswort erhalten Sie von der Zweifaktorauthentisierung-App auf Ihrem Gerät.', + 'TOTP_INPUT_HELP' => 'Das Einmalpasswort erhalten Sie von der Zwei-Faktor-Authentisierungs-App auf Ihrem Gerät.', 'TOTP_CANCEL_LOGIN' => 'Anmeldung abbrechen', 'd3mxuser_totp' => '2-Faktor-Authentisierung', @@ -38,7 +38,7 @@ $aLang = [ 'D3_TOTP_REGISTEREXIST' => 'vorhandene Registrierung', 'D3_TOTP_REGISTERDELETE' => 'Registrierung löschen', - 'D3_TOTP_REGISTERDELETE_DESC' => 'Um die Registrierung zu ändern, löschen Sie diese bitte vorerst. Sie können sofort im Anschluss eine neue Registrierung anlegen.
Wenn Sie die Registrierung löschen, ist das Konto nicht mehr durch die Zweifaktorauthentisierung geschützt.', + 'D3_TOTP_REGISTERDELETE_DESC' => 'Um die Registrierung zu ändern, löschen Sie diese bitte vorerst. Sie können sofort im Anschluss eine neue Registrierung anlegen.
Wenn Sie die Registrierung löschen, ist das Konto nicht mehr durch die Zwei-Faktor-Authentisierung geschützt.', 'D3_TOTP_BACKUPCODES' => 'Backupcodes', 'D3_TOTP_BACKUPCODES_DESC' => 'Mit diesen Backupcodes können Sie sich anmelden, wenn die Generierung des Einmalpasswortes nicht möglich ist (z.B. Gerät verloren oder neu installiert). Sie können dann die Einstellungen zur Verwendung der 2-Faktor-Authentisierung ändern oder einen neuen Zugang erstellen. Speichern Sie sich diese Codes bitte in diesem Moment sicher ab. Nach Verlassen dieser Seite können diese Codes nicht erneut angezeigt werden.', diff --git a/src/Application/views/blocks/page/account/inc/account_menu.tpl b/src/Application/views/blocks/page/account/inc/account_menu.tpl index 15c8821..a7c2723 100644 --- a/src/Application/views/blocks/page/account/inc/account_menu.tpl +++ b/src/Application/views/blocks/page/account/inc/account_menu.tpl @@ -1,4 +1,4 @@ [{$smarty.block.parent}] - \ No newline at end of file diff --git a/src/Application/views/tpl/d3_account_totp.tpl b/src/Application/views/tpl/d3_account_totp.tpl new file mode 100644 index 0000000..a945883 --- /dev/null +++ b/src/Application/views/tpl/d3_account_totp.tpl @@ -0,0 +1,127 @@ +[{capture append="oxidBlock_content"}] + +

[{oxmultilang ident="D3_TOTP_ACCOUNT"}]

+ + [{assign var="totp" value=$user->d3GetTotp()}] + + + + [{block name="d3_account_totp"}] +
+ + +

+ getId()}] checked[{/if}] [{if false == $totp->getId()}]onclick="$('.registerNew').toggle(); $('.submitBtn').toggle();"[{/if}]> + +

+ + [{if false == $totp->getId()}] +
+
+ [{oxmultilang ident="D3_TOTP_REGISTERNEW"}] +
+
+

+ [{oxmultilang ident="D3_TOTP_QRCODE"}]  + + [{$totp->getQrCodeElement()}] +

+

+ [{oxmultilang ident="D3_TOTP_QRCODE_HELP"}] +

+ +
+ +

+ + + +

+

+ [{oxmultilang ident="D3_TOTP_SECRET_HELP"}] +

+ +
+ +

+ + + +

+

+ [{oxmultilang ident="D3_TOTP_CURROTP_HELP"}] +

+
+
+ [{/if}] + + [{if $totp->getId()}] + [{block name="d3_account_totp_deletenotes"}] +
+
+ [{oxmultilang ident="D3_TOTP_REGISTEREXIST"}] +
+
+ [{oxmultilang ident="D3_TOTP_REGISTERDELETE_DESC"}] +
+
+ [{/block}] + + [{block name="d3_account_totp_backupcodes"}] +
+
+ [{oxmultilang ident="D3_TOTP_BACKUPCODES"}] +
+
+ [{if $oView->getBackupCodes()}] + [{block name="d3_account_totp_backupcodes_list"}] + + + [{/block}] + [{else}] + [{block name="d3_account_totp_backupcodes_info"}] + [{oxmultilang ident="D3_TOTP_AVAILBACKUPCODECOUNT" args=$oView->getAvailableBackupCodeCount()}]
+ [{oxmultilang ident="D3_TOTP_AVAILBACKUPCODECOUNT_DESC"}] + [{/block}] + [{/if}] +
+
+ [{/block}] + [{/if}] + +

+ +

+
+ [{/block}] +[{/capture}] + +[{capture append="oxidBlock_sidebar"}] + [{include file="page/account/inc/account_menu.tpl" active_link="d3totp"}] +[{/capture}] +[{include file="layout/page.tpl" sidebar="Left"}] \ No newline at end of file diff --git a/src/Modules/Application/Model/d3_totp_user.php b/src/Modules/Application/Model/d3_totp_user.php index d260c4b..eefce77 100644 --- a/src/Modules/Application/Model/d3_totp_user.php +++ b/src/Modules/Application/Model/d3_totp_user.php @@ -16,6 +16,8 @@ namespace D3\Totp\Modules\Application\Model; use D3\Totp\Application\Model\d3totp; +use Doctrine\DBAL\DBALException; +use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Registry; class d3_totp_user extends d3_totp_user_parent @@ -28,4 +30,17 @@ class d3_totp_user extends d3_totp_user_parent return $return; } + + /** + * @return d3totp + * @throws DatabaseConnectionException + * @throws DBALException + */ + public function d3getTotp() + { + $oTotp = oxNew(d3totp::class); + $oTotp->loadByUserId($this->getId()); + + return $oTotp; + } } \ No newline at end of file diff --git a/src/metadata.php b/src/metadata.php index 77f30cc..8e5077e 100644 --- a/src/metadata.php +++ b/src/metadata.php @@ -16,6 +16,7 @@ */ use D3\Totp\Application\Controller\Admin\d3user_totp; +use D3\Totp\Application\Controller\d3_account_totp; use D3\Totp\Application\Controller\d3totplogin; use D3\Totp\Modules\Application\Component\d3_totp_UserComponent; use D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController; @@ -71,11 +72,13 @@ $aModule = [ ], 'controllers' => [ 'd3user_totp' => d3user_totp::class, - 'd3totplogin' => d3totplogin::class + 'd3totplogin' => d3totplogin::class, + 'd3_account_totp' => d3_account_totp::class, ], - 'templates' => [ - 'd3user_totp.tpl' => 'd3/totp/Application/views/admin/tpl/d3user_totp.tpl', - 'd3totplogin.tpl' => 'd3/totp/Application/views/tpl/d3totplogin.tpl', + 'templates' => [ + 'd3user_totp.tpl' => 'd3/totp/Application/views/admin/tpl/d3user_totp.tpl', + 'd3totplogin.tpl' => 'd3/totp/Application/views/tpl/d3totplogin.tpl', + 'd3_account_totp.tpl' => 'd3/totp/Application/views/tpl/d3_account_totp.tpl', ], 'events' => [ 'onActivate' => '\D3\Totp\Setup\Events::onActivate',