diff --git a/Classes/Backend/Form/Element/TwoFactorAuth.php b/Classes/Backend/Form/Element/TwoFactorAuth.php new file mode 100644 index 0000000..27c7e78 --- /dev/null +++ b/Classes/Backend/Form/Element/TwoFactorAuth.php @@ -0,0 +1,225 @@ + + * @copyright (c) 2018-2022 by Robin von den Bergen + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + * @version 1.0.0 + * + * @link https://github.com/codeFareith/cf_google_authenticator + * @see https://www.fareith.de + * @see https://typo3.org + */ + +namespace CodeFareith\CfGoogleAuthenticator\Backend\Form\Element; + +use CodeFareith\CfGoogleAuthenticator\Domain\Immutable\AuthenticationSecret; +use CodeFareith\CfGoogleAuthenticator\Service\GoogleQrCodeGenerator; +use CodeFareith\CfGoogleAuthenticator\Service\QrCodeGeneratorInterface; +use CodeFareith\CfGoogleAuthenticator\Traits\GeneralUtilityObjectManager; +use CodeFareith\CfGoogleAuthenticator\Utility\Base32Utility; +use CodeFareith\CfGoogleAuthenticator\Utility\PathUtility; +use Exception; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\SignalSlot\Dispatcher; +use TYPO3\CMS\Fluid\View\StandaloneView; +use function sprintf; +use function vsprintf; +use TYPO3\CMS\Backend\Form\Element\AbstractFormElement; + +/** + * Custom field for the OTP setup in TCA + * + * This class hooks into the backend user settings, + * to extend the view by creating a secret key and an image of + * the QR code for the Google Authenticator. + * + * @package CodeFareith\CfGoogleAuthenticator\Hook + * @since 1.0.0 + */ +class TwoFactorAuth extends AbstractFormElement +{ + /*─────────────────────────────────────────────────────────────────────────────*\ + Traits + \*─────────────────────────────────────────────────────────────────────────────*/ + use GeneralUtilityObjectManager; + + /*─────────────────────────────────────────────────────────────────────────────*\ + Properties + \*─────────────────────────────────────────────────────────────────────────────*/ + /** + * @var mixed[] + */ + protected $data; + + /** + * @var AuthenticationSecret + */ + private $authenticationSecret; + + /** + * @var QrCodeGeneratorInterface + */ + private $qrCodeGenerator; + + /*─────────────────────────────────────────────────────────────────────────────*\ + Methods + \*─────────────────────────────────────────────────────────────────────────────*/ + /** + * @return array + * @throws Exception + */ + public function render(): array + { + $result = $this->initializeResultArray(); + $authenticationSecret = $this->getAuthenticationSecret(); + $templateView = $this->initializeTemplateView(); + $isEnabled = $this->isGoogleAuthenticatorEnabled(); + $qrCodeUri = $this->getQrCodeGenerator()->generateUri($authenticationSecret); + + $prefix = ''; + if ($this->data['tableName'] !== null) { + $prefix .= sprintf('[%s]', $this->data['tableName']); + } + if ($data['databaseRow']['uid'] !== null) { + $prefix .= sprintf('[%s]', (string)$this->data['databaseRow']['uid']); + } + + $templateView->assignMultiple( + [ + 'prefix' => $prefix, + 'isEnabled' => $isEnabled, + 'qrCodeUri' => $qrCodeUri, + 'authenticatorSecret' => $this->getAuthenticationSecret()->getSecretKey(), + ] + ); + + $result['html'] = $templateView->render(); + + return $result; + } + + private function initializeTemplateView(): StandaloneView + { + $templatePath = $this->getTemplatePath(); + + /** @var StandaloneView $templateView */ + $templateView = $this->objectManager()->get(StandaloneView::class); + $templateView->setLayoutRootPaths([$templatePath . 'Layouts/']); + $templateView->setPartialRootPaths([$templatePath . 'Partials/']); + $templateView->setTemplateRootPaths([$templatePath . 'Templates/']); + + $templateView->setTemplatePathAndFilename( + GeneralUtility::getFileAbsFileName( + PathUtility::makeExtensionPath('Resources/Private/Templates/Backend/UserSettings.html') + ) + ); + + return $templateView; + } + + private function getTemplatePath(): string + { + return GeneralUtility::getFileAbsFileName( + PathUtility::makeExtensionPath('Resources/Private/') + ); + } + + private function getIssuer(): string + { + return vsprintf( + '%s - %s', + [ + $this->getSiteName(), + $this->getLayer(), + ] + ); + } + + private function getSiteName(): string + { + return $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']; + } + + private function getLayer(): string + { + $layer = ''; + + if ($this->data['tableName'] === 'fe_users') { + $layer = 'Frontend'; + } elseif ($this->data['tableName'] === 'be_users') { + $layer = 'Backend'; + } + + $dispatcher = GeneralUtility::makeInstance(Dispatcher::class); + $signalArguments = [ + 'table' => $this->data['tableName'], + 'layer' => $layer, + 'caller' => $this, + ]; + $signalArguments = $dispatcher->dispatch( + __CLASS__, + 'defineIssuerLayer', + $signalArguments + ); + + return $signalArguments['layer']; + } + + private function getUsername(): string + { + return $this->data['databaseRow']['username'] ?? ''; + } + + /** + * @throws Exception + */ + private function getAuthenticationSecret(): AuthenticationSecret + { + if ($this->authenticationSecret === null) { + $this->authenticationSecret = $this->objectManager()->get( + AuthenticationSecret::class, + $this->getIssuer(), + $this->getUsername(), + $this->getSecretKey() + ); + } + + return $this->authenticationSecret; + } + + /** + * @throws Exception + */ + private function getSecretKey(): string + { + if ($this->isGoogleAuthenticatorEnabled()) { + $secretKey = (string) $this->data['databaseRow']['tx_cfgoogleauthenticator_secret']; + } else { + $secretKey = Base32Utility::generateRandomString(16); + } + + return $secretKey; + } + + private function isGoogleAuthenticatorEnabled(): bool + { + if ($this->data['parameterArray']['fieldConf']['config']['type'] === 'user' && !is_array($this->data['databaseRow'])) { + $this->data['databaseRow'] = $GLOBALS['BE_USER']->user; + } + return (bool) $this->data['databaseRow']['tx_cfgoogleauthenticator_enabled']; + } + + private function getQrCodeGenerator(): QrCodeGeneratorInterface + { + if ($this->qrCodeGenerator === null) { + $this->qrCodeGenerator = $this->objectManager()->get(GoogleQrCodeGenerator::class); + } + + return $this->qrCodeGenerator; + } +} diff --git a/Classes/Controller/Frontend/SetupController.php b/Classes/Controller/Frontend/SetupController.php index 7cbc2a4..9393fec 100644 --- a/Classes/Controller/Frontend/SetupController.php +++ b/Classes/Controller/Frontend/SetupController.php @@ -3,7 +3,7 @@ * Class SetupController * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * @@ -33,7 +33,8 @@ use TYPO3\CMS\Extbase\Object\Exception as ObjectException; use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException; use TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException; -use TYPO3\CMS\Lang\LanguageService; +use TYPO3\CMS\Core\Localization\LanguageService; +use TYPO3\CMS\Extbase\SignalSlot\Dispatcher; use function get_class; use function vsprintf; @@ -82,6 +83,11 @@ class SetupController */ private $authenticationSecret; + /** + * @var Dispatcher + */ + protected $dispatcher; + /*─────────────────────────────────────────────────────────────────────────────*\ Methods \*─────────────────────────────────────────────────────────────────────────────*/ @@ -90,16 +96,16 @@ public function __construct( GoogleQrCodeGenerator $qrCodeGenerator, SetupFormValidator $setupFormValidator, LanguageService $languageService, - Context $context + Context $context, + Dispatcher $dispatcher ) { - parent::__construct(); - $this->frontendUserRepository = $frontendUserRepository; $this->qrCodeGenerator = $qrCodeGenerator; $this->setupFormValidator = $setupFormValidator; $this->languageService = $languageService; $this->context = $context; + $this->dispatcher = $dispatcher; } /** @@ -153,16 +159,31 @@ public function updateAction(): void if ($user !== null) { $formData = (array)$this->request->getArgument(SetupForm::FORM_NAME); + $action = null; if ($this->request->hasArgument('enable')) { $user->enableGoogleAuthenticator($formData['secret']); + $action = 'enable'; } elseif ($this->request->hasArgument('disable')) { $user->disableGoogleAuthenticator(); + $action = 'disable'; } $this->frontendUserRepository->update($user); $this->addSuccessMessage(); + if ($action !== null) { + $this->dispatcher->dispatch( + __CLASS__, + 'toggleGoogleAuthenticator', + [ + 'action' => $action, + 'user' => $user, + 'caller' => $this, + ] + ); + } + $this->redirect('index'); } } diff --git a/Classes/Domain/DataTransferObject/GoogleAuthenticatorSettingsDTO.php b/Classes/Domain/DataTransferObject/GoogleAuthenticatorSettingsDTO.php index 8994bc3..45166fa 100644 --- a/Classes/Domain/DataTransferObject/GoogleAuthenticatorSettingsDTO.php +++ b/Classes/Domain/DataTransferObject/GoogleAuthenticatorSettingsDTO.php @@ -3,7 +3,7 @@ * Class GoogleAuthenticatorSettingsDTO * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/DataTransferObject/PreProcessFieldArrayDTO.php b/Classes/Domain/DataTransferObject/PreProcessFieldArrayDTO.php index d10a86b..caa2479 100644 --- a/Classes/Domain/DataTransferObject/PreProcessFieldArrayDTO.php +++ b/Classes/Domain/DataTransferObject/PreProcessFieldArrayDTO.php @@ -3,7 +3,7 @@ * Class PreProcessFieldArrayDTO * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Form/FormInterface.php b/Classes/Domain/Form/FormInterface.php index 1d5f2c1..3e628f5 100644 --- a/Classes/Domain/Form/FormInterface.php +++ b/Classes/Domain/Form/FormInterface.php @@ -3,7 +3,7 @@ * Interface FormInterface * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Form/SetupForm.php b/Classes/Domain/Form/SetupForm.php index 24c66e0..c01aed7 100644 --- a/Classes/Domain/Form/SetupForm.php +++ b/Classes/Domain/Form/SetupForm.php @@ -3,7 +3,7 @@ * Class SetupForm * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Immutable/AuthenticationSecret.php b/Classes/Domain/Immutable/AuthenticationSecret.php index 43829a5..6d9bebf 100644 --- a/Classes/Domain/Immutable/AuthenticationSecret.php +++ b/Classes/Domain/Immutable/AuthenticationSecret.php @@ -3,7 +3,7 @@ * Class AuthenticationSecret * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Immutable/ImmutableInterface.php b/Classes/Domain/Immutable/ImmutableInterface.php index 141f7de..68dd745 100644 --- a/Classes/Domain/Immutable/ImmutableInterface.php +++ b/Classes/Domain/Immutable/ImmutableInterface.php @@ -3,7 +3,7 @@ * Interface ImmutableInterface * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Mapper/AbstractMapper.php b/Classes/Domain/Mapper/AbstractMapper.php index 1f4d27c..c8964e9 100644 --- a/Classes/Domain/Mapper/AbstractMapper.php +++ b/Classes/Domain/Mapper/AbstractMapper.php @@ -3,7 +3,7 @@ * Class AbstractMapper * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Mapper/GoogleAuthenticatorSettingsMapper.php b/Classes/Domain/Mapper/GoogleAuthenticatorSettingsMapper.php index 90514f8..8ba4ac7 100644 --- a/Classes/Domain/Mapper/GoogleAuthenticatorSettingsMapper.php +++ b/Classes/Domain/Mapper/GoogleAuthenticatorSettingsMapper.php @@ -3,7 +3,7 @@ * Class GoogleAuthenticatorSettingsMapper * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Mapper/MapperInterface.php b/Classes/Domain/Mapper/MapperInterface.php index fc74c36..f298404 100644 --- a/Classes/Domain/Mapper/MapperInterface.php +++ b/Classes/Domain/Mapper/MapperInterface.php @@ -3,7 +3,7 @@ * Interface MapperInterface * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Model/BackendUser.php b/Classes/Domain/Model/BackendUser.php index 4825bb3..b18d992 100644 --- a/Classes/Domain/Model/BackendUser.php +++ b/Classes/Domain/Model/BackendUser.php @@ -3,7 +3,7 @@ * Class BackendUser * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Model/FrontendUser.php b/Classes/Domain/Model/FrontendUser.php index 551f63f..8182975 100644 --- a/Classes/Domain/Model/FrontendUser.php +++ b/Classes/Domain/Model/FrontendUser.php @@ -3,7 +3,7 @@ * Class FrontendUser * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Repository/BackendUserRepository.php b/Classes/Domain/Repository/BackendUserRepository.php index 6e73ea2..bfb9ae8 100644 --- a/Classes/Domain/Repository/BackendUserRepository.php +++ b/Classes/Domain/Repository/BackendUserRepository.php @@ -3,7 +3,7 @@ * Class BackendUserRepository * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Repository/FrontendUserRepository.php b/Classes/Domain/Repository/FrontendUserRepository.php index 5b702c5..567eb42 100644 --- a/Classes/Domain/Repository/FrontendUserRepository.php +++ b/Classes/Domain/Repository/FrontendUserRepository.php @@ -3,7 +3,7 @@ * Class FrontendUserRepository * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Struct/AbstractStruct.php b/Classes/Domain/Struct/AbstractStruct.php index 039c63e..6816dc7 100644 --- a/Classes/Domain/Struct/AbstractStruct.php +++ b/Classes/Domain/Struct/AbstractStruct.php @@ -3,7 +3,7 @@ * Class AbstractStruct * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Struct/GoogleAuthenticatorSettings.php b/Classes/Domain/Struct/GoogleAuthenticatorSettings.php index 55ad621..6cdf528 100644 --- a/Classes/Domain/Struct/GoogleAuthenticatorSettings.php +++ b/Classes/Domain/Struct/GoogleAuthenticatorSettings.php @@ -3,7 +3,7 @@ * Class GoogleAuthenticatorSettings * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Domain/Struct/StructInterface.php b/Classes/Domain/Struct/StructInterface.php index c58d9ab..9455cdd 100644 --- a/Classes/Domain/Struct/StructInterface.php +++ b/Classes/Domain/Struct/StructInterface.php @@ -3,7 +3,7 @@ * Interface StructInterface * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Exception/MissingRequiredField.php b/Classes/Exception/MissingRequiredField.php index 8f34588..3dfe9f1 100644 --- a/Classes/Exception/MissingRequiredField.php +++ b/Classes/Exception/MissingRequiredField.php @@ -3,7 +3,7 @@ * Class MissingRequiredField * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Exception/PropertyNotFound.php b/Classes/Exception/PropertyNotFound.php index 7cc81ad..542cbd3 100644 --- a/Classes/Exception/PropertyNotFound.php +++ b/Classes/Exception/PropertyNotFound.php @@ -3,7 +3,7 @@ * Class PropertyNotFound * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Exception/PropertyNotInitialized.php b/Classes/Exception/PropertyNotInitialized.php index 1b310cc..a564afe 100644 --- a/Classes/Exception/PropertyNotInitialized.php +++ b/Classes/Exception/PropertyNotInitialized.php @@ -3,7 +3,7 @@ * Class PropertyNotInitialized * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Handler/GoogleAuthenticatorSetupHandler.php b/Classes/Handler/GoogleAuthenticatorSetupHandler.php index f792d61..620700c 100644 --- a/Classes/Handler/GoogleAuthenticatorSetupHandler.php +++ b/Classes/Handler/GoogleAuthenticatorSetupHandler.php @@ -3,7 +3,7 @@ * Class GoogleAuthenticatorSetupHandler * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Hook/FeLogin.php b/Classes/Hook/FeLogin.php index 85c6b6d..c94425c 100644 --- a/Classes/Hook/FeLogin.php +++ b/Classes/Hook/FeLogin.php @@ -3,7 +3,7 @@ * Class FeLogin * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * @@ -18,7 +18,7 @@ use CodeFareith\CfGoogleAuthenticator\Utility\ExtensionBasicDataUtility; use CodeFareith\CfGoogleAuthenticator\Utility\PathUtility; use TYPO3\CMS\Core\Service\MarkerBasedTemplateService; -use TYPO3\CMS\Lang\LanguageService; +use TYPO3\CMS\Core\Localization\LanguageService; /** * Hook for the TYPO3 CMS extension 'felogin' diff --git a/Classes/Hook/TCEMain.php b/Classes/Hook/TCEMain.php index 455c89e..60cd243 100644 --- a/Classes/Hook/TCEMain.php +++ b/Classes/Hook/TCEMain.php @@ -3,7 +3,7 @@ * Class TCEMain * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * @@ -54,7 +54,7 @@ class TCEMain /** * @noinspection MoreThanThreeArgumentsInspection * - * @param mixed $fieldArray + * @param mixed $fieldArray * @param string|int $id * * @throws MissingRequiredField @@ -69,13 +69,20 @@ public function processDatamap_preProcessFieldArray( ): void { $otpInFieldArray = &$fieldArray['tx_cfgoogleauthenticator_otp']; - $otpInPostData = $_POST['data']['be_users']['tx_cfgoogleauthenticator_otp']; + $otpInPostData = $_POST['data'][$table]['tx_cfgoogleauthenticator_otp']; if ($otpInFieldArray === null && $otpInPostData !== null) { $otpInFieldArray = $otpInPostData; } - $preProcessFieldArrayDTO = $this->getPreProcessFieldArrayDTO($fieldArray, $table, (int) $id, $dataHandler); + $secretInFieldArray = &$fieldArray['tx_cfgoogleauthenticator_secret']; + $secretInPostData = $_POST['data'][$table]['tx_cfgoogleauthenticator_secret']; + + if ($secretInFieldArray === null && $secretInPostData !== null) { + $secretInFieldArray = $secretInPostData; + } + + $preProcessFieldArrayDTO = $this->getPreProcessFieldArrayDTO($fieldArray, $table, (int)$id, $dataHandler); $result = $this->getGoogleAuthenticatorSetupHandler()->process($preProcessFieldArrayDTO); $fieldArray = array_merge($fieldArray, $result); diff --git a/Classes/Hook/UserSettings.php b/Classes/Hook/UserSettings.php index 7729060..217f479 100644 --- a/Classes/Hook/UserSettings.php +++ b/Classes/Hook/UserSettings.php @@ -1,222 +1,27 @@ - - * @copyright (c) 2018-2019 by Robin von den Bergen - * @license http://opensource.org/licenses/gpl-license.php GNU Public License - * @version 1.0.0 - * - * @link https://github.com/codeFareith/cf_google_authenticator - * @see https://www.fareith.de - * @see https://typo3.org - */ +data = $data; - - $authenticationSecret = $this->getAuthenticationSecret(); - $templateView = $this->initializeTemplateView(); - $isEnabled = $this->isGoogleAuthenticatorEnabled(); - $qrCodeUri = $this->getQrCodeGenerator()->generateUri($authenticationSecret); - - $prefix = ''; - if ($data['table'] !== null) { - $prefix .= sprintf('[%s]', $data['table']); - } - if ($data['row']['uid'] !== null) { - $prefix .= sprintf('[%s]', (string)$data['row']['uid']); - } - - $templateView->assignMultiple( - [ - 'prefix' => $prefix, - 'isEnabled' => $isEnabled, - 'qrCodeUri' => $qrCodeUri, - 'authenticatorSecret' => $this->getAuthenticationSecret()->getSecretKey(), - ] - ); - - return $templateView->render(); - } - - private function initializeTemplateView(): StandaloneView - { - $templatePath = $this->getTemplatePath(); - - /** @var StandaloneView $templateView */ - $templateView = $this->objectManager()->get(StandaloneView::class); - $templateView->setLayoutRootPaths([$templatePath . 'Layouts/']); - $templateView->setPartialRootPaths([$templatePath . 'Partials/']); - $templateView->setTemplateRootPaths([$templatePath . 'Templates/']); - - $templateView->setTemplatePathAndFilename( - GeneralUtility::getFileAbsFileName( - PathUtility::makeExtensionPath('Resources/Private/Templates/Backend/UserSettings.html') - ) - ); - - return $templateView; - } - - private function getTemplatePath(): string - { - return GeneralUtility::getFileAbsFileName( - PathUtility::makeExtensionPath('Resources/Private/') - ); - } - - private function getIssuer(): string - { - return vsprintf( - '%s - %s', - [ - $this->getSiteName(), - $this->getLayer(), - ] - ); - } - - private function getSiteName(): string - { - return $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']; - } - - private function getLayer(): string + public function createSecretField(array $config, SetupModuleController $pObj) { - $layer = ''; - - if ($this->data['table'] === 'fe_users') { - $layer = 'Frontend'; - } elseif ($this->data['table'] === 'be_users') { - $layer = 'Backend'; - } - - $dispatcher = GeneralUtility::makeInstance(Dispatcher::class); - $signalArguments = [ - 'table' => $this->data['table'], - 'layer' => $layer, - 'caller' => $this, + /** @var \TYPO3\CMS\Backend\Form\NodeFactory $nodeFactory */ + $nodeFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\NodeFactory::class); + $data = [ + 'tableName' => 'be_users', + 'databaseRow' => $GLOBALS['BE_USER']->user, ]; - $signalArguments = $dispatcher->dispatch( - __CLASS__, - 'defineIssuerLayer', - $signalArguments - ); - return $signalArguments['layer']; - } - - private function getUsername(): string - { - return $this->data['row']['username'] ?? ''; - } - - /** - * @throws Exception - */ - private function getAuthenticationSecret(): AuthenticationSecret - { - if ($this->authenticationSecret === null) { - $this->authenticationSecret = $this->objectManager()->get( - AuthenticationSecret::class, - $this->getIssuer(), - $this->getUsername(), - $this->getSecretKey() - ); - } - - return $this->authenticationSecret; - } - - /** - * @throws Exception - */ - private function getSecretKey(): string - { - if ($this->isGoogleAuthenticatorEnabled()) { - $secretKey = (string) $this->data['row']['tx_cfgoogleauthenticator_secret']; - } else { - $secretKey = Base32Utility::generateRandomString(16); - } - - return $secretKey; - } - - private function isGoogleAuthenticatorEnabled(): bool - { - if ($this->data['type'] === 'user' && !is_array($this->data['row'])) { - $this->data['row'] = $GLOBALS['BE_USER']->user; - } - return (bool) $this->data['row']['tx_cfgoogleauthenticator_enabled']; - } - - private function getQrCodeGenerator(): QrCodeGeneratorInterface - { - if ($this->qrCodeGenerator === null) { - $this->qrCodeGenerator = $this->objectManager()->get(GoogleQrCodeGenerator::class); - } + $twoFactorAuthElement = GeneralUtility::makeInstance(TwoFactorAuth::class, $nodeFactory, $data); - return $this->qrCodeGenerator; + $result = $twoFactorAuthElement->render(); + return $result['html']; } } diff --git a/Classes/Provider/Login/GoogleAuthenticatorLoginProvider.php b/Classes/Provider/Login/GoogleAuthenticatorLoginProvider.php index 5a1e0bb..e647c5a 100644 --- a/Classes/Provider/Login/GoogleAuthenticatorLoginProvider.php +++ b/Classes/Provider/Login/GoogleAuthenticatorLoginProvider.php @@ -3,7 +3,7 @@ * Class GoogleAuthenticatorLoginProvider * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Service/AuthenticationService.php b/Classes/Service/AuthenticationService.php index ca01aeb..831edb2 100644 --- a/Classes/Service/AuthenticationService.php +++ b/Classes/Service/AuthenticationService.php @@ -3,7 +3,7 @@ * Interface AuthenticationService * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Service/AuthenticationServiceAdapterFactory.php b/Classes/Service/AuthenticationServiceAdapterFactory.php index 665613a..7212e9f 100644 --- a/Classes/Service/AuthenticationServiceAdapterFactory.php +++ b/Classes/Service/AuthenticationServiceAdapterFactory.php @@ -3,7 +3,7 @@ * Interface AuthenticationServiceAdapterFactory * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Service/CoreAuthenticationServiceAdapter.php b/Classes/Service/CoreAuthenticationServiceAdapter.php index 005972e..47211d9 100644 --- a/Classes/Service/CoreAuthenticationServiceAdapter.php +++ b/Classes/Service/CoreAuthenticationServiceAdapter.php @@ -3,7 +3,7 @@ * Class CoreAuthenticationServiceAdapter * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Service/GoogleAuthenticationServiceAdapterFactory.php b/Classes/Service/GoogleAuthenticationServiceAdapterFactory.php deleted file mode 100644 index 8fc9df2..0000000 --- a/Classes/Service/GoogleAuthenticationServiceAdapterFactory.php +++ /dev/null @@ -1,65 +0,0 @@ - - * @copyright (c) 2018-2019 by Robin von den Bergen - * @license http://opensource.org/licenses/gpl-license.php GNU Public License - * @version 1.0.0 - * - * @link https://github.com/codeFareith/cf_google_authenticator - * @see https://www.fareith.de - * @see https://typo3.org - */ - -namespace CodeFareith\CfGoogleAuthenticator\Service; - -use TYPO3\CMS\Core\Utility\VersionNumberUtility; -use TYPO3\CMS\Extbase\Object\ObjectManager; -use function version_compare; - -/** - * @package CodeFareith\CfGoogleAuthenticator\Service - * @since 1.1.5 - */ -class GoogleAuthenticationServiceAdapterFactory - implements AuthenticationServiceAdapterFactory -{ - protected $objectManager; - - public function __construct(ObjectManager $objectManager) - { - $this->objectManager = $objectManager; - } - - public function create(): AuthenticationService - { - return $this->objectManager->get( - $this->suggestServiceAdapter(), - $this->suggestAuthenticatorService() - ); - } - - private function suggestServiceAdapter(): string - { - if ($this->isLegacyInstallation()) { - $serviceAdapter = LegacyAuthenticationServiceAdapter::class; - } else { - $serviceAdapter = CoreAuthenticationServiceAdapter::class; - } - - return $serviceAdapter; - } - - private function isLegacyInstallation(): bool - { - $version = VersionNumberUtility::getNumericTypo3Version(); - - return version_compare($version, '9.0.0', '<'); - } - - private function suggestAuthenticatorService(): AuthenticationService - { - return $this->objectManager->get(GoogleAuthenticatorService::class); - } -} diff --git a/Classes/Service/GoogleAuthenticatorService.php b/Classes/Service/GoogleAuthenticatorService.php index 53848c8..da7cdf2 100644 --- a/Classes/Service/GoogleAuthenticatorService.php +++ b/Classes/Service/GoogleAuthenticatorService.php @@ -3,7 +3,7 @@ * Class GoogleAuthenticatorService * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * @@ -73,7 +73,8 @@ public function authUser(array $user): int $logArgs ); - $otp = GeneralUtility::_GP('google-authenticator-otp'); + // TODO: Bypass OTP check in case we try to access the Install Tool? Or add support for OTP in prompt? + $otp = GeneralUtility::_GP('google-authenticator-otp') ?? ''; $secret = $user['tx_cfgoogleauthenticator_secret']; if (GoogleAuthenticatorUtility::verifyOneTimePassword($secret, $otp) === true) { diff --git a/Classes/Service/GoogleQrCodeGenerator.php b/Classes/Service/GoogleQrCodeGenerator.php index 5983ca1..79cac0b 100644 --- a/Classes/Service/GoogleQrCodeGenerator.php +++ b/Classes/Service/GoogleQrCodeGenerator.php @@ -3,7 +3,7 @@ * Class GoogleQrImageGenerator * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Service/LegacyAuthenticationServiceAdapter.php b/Classes/Service/LegacyAuthenticationServiceAdapter.php deleted file mode 100644 index db0ec03..0000000 --- a/Classes/Service/LegacyAuthenticationServiceAdapter.php +++ /dev/null @@ -1,54 +0,0 @@ - - * @copyright (c) 2018-2019 by Robin von den Bergen - * @license http://opensource.org/licenses/gpl-license.php GNU Public License - * @version 1.0.0 - * - * @link https://github.com/codeFareith/cf_google_authenticator - * @see https://www.fareith.de - * @see https://typo3.org - */ - -namespace CodeFareith\CfGoogleAuthenticator\Service; - -use TYPO3\CMS\Sv\AuthenticationService as SvAuthenticationService; - -/** @noinspection LongInheritanceChainInspection */ - -/** - * @package CodeFareith\CfGoogleAuthenticator\Service - * @since 1.1.5 - */ -class LegacyAuthenticationServiceAdapter - extends SvAuthenticationService - implements AuthenticationService -{ - /** - * @var AuthenticationService - */ - protected $service; - - public function __construct(AuthenticationService $authenticationService = null) - { - $authenticationService = $authenticationService ?? new GoogleAuthenticatorService(); - - $this->service = $authenticationService; - } - - public function init(): bool - { - return ( - parent::init() - && $this->service->init() - ); - } - - public function authUser(array $user): int - { - parent::authUser($user); - return $this->service->authUser($user); - } -} diff --git a/Classes/Service/QrCodeGeneratorInterface.php b/Classes/Service/QrCodeGeneratorInterface.php index 298d5c3..1759b45 100644 --- a/Classes/Service/QrCodeGeneratorInterface.php +++ b/Classes/Service/QrCodeGeneratorInterface.php @@ -3,7 +3,7 @@ * Interface QrImageGeneratorInterface * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Traits/GeneralUtilityObjectManager.php b/Classes/Traits/GeneralUtilityObjectManager.php index 976d172..acf32c5 100644 --- a/Classes/Traits/GeneralUtilityObjectManager.php +++ b/Classes/Traits/GeneralUtilityObjectManager.php @@ -3,7 +3,7 @@ * Trait GeneralUtilityObjectManager * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Utility/Base32Utility.php b/Classes/Utility/Base32Utility.php index 6a6c0c7..dd761e2 100644 --- a/Classes/Utility/Base32Utility.php +++ b/Classes/Utility/Base32Utility.php @@ -3,7 +3,7 @@ * Class Base32Utility * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Utility/ExtensionBasicDataUtility.php b/Classes/Utility/ExtensionBasicDataUtility.php index 110c852..2a8e305 100644 --- a/Classes/Utility/ExtensionBasicDataUtility.php +++ b/Classes/Utility/ExtensionBasicDataUtility.php @@ -3,7 +3,7 @@ * Class ExtensionBasicDataUtility * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Utility/GoogleAuthenticatorUtility.php b/Classes/Utility/GoogleAuthenticatorUtility.php index e5135f6..0931c6b 100644 --- a/Classes/Utility/GoogleAuthenticatorUtility.php +++ b/Classes/Utility/GoogleAuthenticatorUtility.php @@ -3,7 +3,7 @@ * Class GoogleAuthenticatorUtility * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Utility/PathUtility.php b/Classes/Utility/PathUtility.php index 517f249..aa631b1 100644 --- a/Classes/Utility/PathUtility.php +++ b/Classes/Utility/PathUtility.php @@ -3,7 +3,7 @@ * Class PathUtility * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Utility/TypoScriptUtility.php b/Classes/Utility/TypoScriptUtility.php index 8a2e8a0..98f6881 100644 --- a/Classes/Utility/TypoScriptUtility.php +++ b/Classes/Utility/TypoScriptUtility.php @@ -3,7 +3,7 @@ * Class TypoScriptUtility * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Classes/Validation/Validator/SetupFormValidator.php b/Classes/Validation/Validator/SetupFormValidator.php index 5b8fd6f..59e0d4a 100644 --- a/Classes/Validation/Validator/SetupFormValidator.php +++ b/Classes/Validation/Validator/SetupFormValidator.php @@ -3,7 +3,7 @@ * Class SetupFormValidator * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Configuration/Extbase/Persistence/Classes.php b/Configuration/Extbase/Persistence/Classes.php new file mode 100644 index 0000000..8adc467 --- /dev/null +++ b/Configuration/Extbase/Persistence/Classes.php @@ -0,0 +1,10 @@ + [ + 'tableName' => 'fe_users', + ], + \CodeFareith\CfGoogleAuthenticator\Domain\Model\BackendUser::class => [ + 'tableName' => 'be_users', + ], +]; diff --git a/Configuration/TCA/Overrides/be_users.php b/Configuration/TCA/Overrides/be_users.php index faeb79e..27b129b 100644 --- a/Configuration/TCA/Overrides/be_users.php +++ b/Configuration/TCA/Overrides/be_users.php @@ -6,7 +6,7 @@ * are represented and handled in the TYPO3 backend. * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * @@ -31,6 +31,13 @@ static function () { ), 'config' => [ 'type' => 'check', + 'renderType' => 'checkboxToggle', + 'items' => [ + [ + 0 => '', + 1 => '', + ] + ], ], ], 'tx_cfgoogleauthenticator_secret' => [ @@ -41,7 +48,7 @@ static function () { ), 'config' => [ 'type' => 'user', - 'userFunc' => \CodeFareith\CfGoogleAuthenticator\Hook\UserSettings::class . '->createSecretField', + 'renderType' => 'TwoFactorAuth', ], ], ] diff --git a/Configuration/TCA/Overrides/fe_users.php b/Configuration/TCA/Overrides/fe_users.php index 4e203c2..5f57a7c 100644 --- a/Configuration/TCA/Overrides/fe_users.php +++ b/Configuration/TCA/Overrides/fe_users.php @@ -6,7 +6,7 @@ * are represented and handled in the TYPO3 backend. * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * @@ -31,6 +31,13 @@ static function () { ), 'config' => [ 'type' => 'check', + 'renderType' => 'checkboxToggle', + 'items' => [ + [ + 0 => '', + 1 => '', + ] + ], ], ], 'tx_cfgoogleauthenticator_secret' => [ @@ -41,7 +48,7 @@ static function () { ), 'config' => [ 'type' => 'user', - 'userFunc' => \CodeFareith\CfGoogleAuthenticator\Hook\UserSettings::class . '->createSecretField', + 'renderType' => 'TwoFactorAuth', ], ], ] diff --git a/Configuration/TCA/Overrides/sys_template.php b/Configuration/TCA/Overrides/sys_template.php index 07a6035..fa4901c 100644 --- a/Configuration/TCA/Overrides/sys_template.php +++ b/Configuration/TCA/Overrides/sys_template.php @@ -6,7 +6,7 @@ * are represented and handled in the TYPO3 backend. * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Configuration/TCA/Overrides/tt_content.php b/Configuration/TCA/Overrides/tt_content.php index af48d7b..310b17d 100644 --- a/Configuration/TCA/Overrides/tt_content.php +++ b/Configuration/TCA/Overrides/tt_content.php @@ -5,7 +5,7 @@ * This script extends the tt_content * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index 907281d..f5a0f8a 100644 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -14,5 +14,17 @@ plugin { 1 = {$plugin.tx_cfgoogleauthenticator_setup.view.templateRootPath} } } + + # Persistence mapping is required for TYPO3 v9 + # (in TYPO3 v10, this has moved to EXT:cf_google_authenticator/Configuration/Extbase/Persistence/Classes.php) + persistence { + classes { + CodeFareith\CfGoogleAuthenticator\Domain\Model\FrontendUser { + mapping { + tableName = fe_users + } + } + } + } } } diff --git a/Documentation/API/files/Classes/Domain/Form/SetupForm.php.txt b/Documentation/API/files/Classes/Domain/Form/SetupForm.php.txt index ba22f08..541f983 100644 --- a/Documentation/API/files/Classes/Domain/Form/SetupForm.php.txt +++ b/Documentation/API/files/Classes/Domain/Form/SetupForm.php.txt @@ -3,7 +3,7 @@ * Class SetupForm * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Exception/MissingRequiredField.php.txt b/Documentation/API/files/Classes/Exception/MissingRequiredField.php.txt index ba89837..b91f011 100644 --- a/Documentation/API/files/Classes/Exception/MissingRequiredField.php.txt +++ b/Documentation/API/files/Classes/Exception/MissingRequiredField.php.txt @@ -3,7 +3,7 @@ * Class MissingRequiredField * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Exception/PropertyNotFound.php.txt b/Documentation/API/files/Classes/Exception/PropertyNotFound.php.txt index 396fd09..4bca28f 100644 --- a/Documentation/API/files/Classes/Exception/PropertyNotFound.php.txt +++ b/Documentation/API/files/Classes/Exception/PropertyNotFound.php.txt @@ -3,7 +3,7 @@ * Class PropertyNotFound * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Exception/PropertyNotInitialized.php.txt b/Documentation/API/files/Classes/Exception/PropertyNotInitialized.php.txt index 71fb045..67b1fc6 100644 --- a/Documentation/API/files/Classes/Exception/PropertyNotInitialized.php.txt +++ b/Documentation/API/files/Classes/Exception/PropertyNotInitialized.php.txt @@ -3,7 +3,7 @@ * Class PropertyNotInitialized * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Handler/GoogleAuthenticatorSetupHandler.php.txt b/Documentation/API/files/Classes/Handler/GoogleAuthenticatorSetupHandler.php.txt index 6feaca5..4688288 100644 --- a/Documentation/API/files/Classes/Handler/GoogleAuthenticatorSetupHandler.php.txt +++ b/Documentation/API/files/Classes/Handler/GoogleAuthenticatorSetupHandler.php.txt @@ -3,7 +3,7 @@ * Class GoogleAuthenticatorSetupHandler * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Hook/FeLogin.php.txt b/Documentation/API/files/Classes/Hook/FeLogin.php.txt index da0ab31..3abc6da 100644 --- a/Documentation/API/files/Classes/Hook/FeLogin.php.txt +++ b/Documentation/API/files/Classes/Hook/FeLogin.php.txt @@ -3,7 +3,7 @@ * Class FeLogin * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Hook/TCEMain.php.txt b/Documentation/API/files/Classes/Hook/TCEMain.php.txt index a21ebd5..2bdc0f8 100644 --- a/Documentation/API/files/Classes/Hook/TCEMain.php.txt +++ b/Documentation/API/files/Classes/Hook/TCEMain.php.txt @@ -3,7 +3,7 @@ * Class TCEMain * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Hook/UserSettings.php.txt b/Documentation/API/files/Classes/Hook/UserSettings.php.txt index 4207eb3..9715c13 100644 --- a/Documentation/API/files/Classes/Hook/UserSettings.php.txt +++ b/Documentation/API/files/Classes/Hook/UserSettings.php.txt @@ -3,7 +3,7 @@ * Class UserSettings * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Service/GoogleQrCodeGenerator.php.txt b/Documentation/API/files/Classes/Service/GoogleQrCodeGenerator.php.txt index 09eceef..b6912a2 100644 --- a/Documentation/API/files/Classes/Service/GoogleQrCodeGenerator.php.txt +++ b/Documentation/API/files/Classes/Service/GoogleQrCodeGenerator.php.txt @@ -3,7 +3,7 @@ * Class GoogleQrImageGenerator * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Service/QrCodeGeneratorInterface.php.txt b/Documentation/API/files/Classes/Service/QrCodeGeneratorInterface.php.txt index 859e423..155140d 100644 --- a/Documentation/API/files/Classes/Service/QrCodeGeneratorInterface.php.txt +++ b/Documentation/API/files/Classes/Service/QrCodeGeneratorInterface.php.txt @@ -3,7 +3,7 @@ * Interface QrImageGeneratorInterface * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Traits/GeneralUtilityObjectManager.php.txt b/Documentation/API/files/Classes/Traits/GeneralUtilityObjectManager.php.txt index 033183c..562366e 100644 --- a/Documentation/API/files/Classes/Traits/GeneralUtilityObjectManager.php.txt +++ b/Documentation/API/files/Classes/Traits/GeneralUtilityObjectManager.php.txt @@ -3,7 +3,7 @@ * Trait GeneralUtilityObjectManager * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Utility/Base32Utility.php.txt b/Documentation/API/files/Classes/Utility/Base32Utility.php.txt index d90dfcb..c4f67db 100644 --- a/Documentation/API/files/Classes/Utility/Base32Utility.php.txt +++ b/Documentation/API/files/Classes/Utility/Base32Utility.php.txt @@ -3,7 +3,7 @@ * Class Base32Utility * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Utility/ExtensionBasicDataUtility.php.txt b/Documentation/API/files/Classes/Utility/ExtensionBasicDataUtility.php.txt index 31f5747..ff7e634 100644 --- a/Documentation/API/files/Classes/Utility/ExtensionBasicDataUtility.php.txt +++ b/Documentation/API/files/Classes/Utility/ExtensionBasicDataUtility.php.txt @@ -3,7 +3,7 @@ * Class ExtensionBasicDataUtility * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Utility/GoogleAuthenticatorUtility.php.txt b/Documentation/API/files/Classes/Utility/GoogleAuthenticatorUtility.php.txt index e97b7e5..9e744dc 100644 --- a/Documentation/API/files/Classes/Utility/GoogleAuthenticatorUtility.php.txt +++ b/Documentation/API/files/Classes/Utility/GoogleAuthenticatorUtility.php.txt @@ -3,7 +3,7 @@ * Class GoogleAuthenticatorUtility * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Utility/PathUtility.php.txt b/Documentation/API/files/Classes/Utility/PathUtility.php.txt index 0b4efef..54cbf24 100644 --- a/Documentation/API/files/Classes/Utility/PathUtility.php.txt +++ b/Documentation/API/files/Classes/Utility/PathUtility.php.txt @@ -3,7 +3,7 @@ * Class PathUtility * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Documentation/API/files/Classes/Utility/TypoScriptUtility.php.txt b/Documentation/API/files/Classes/Utility/TypoScriptUtility.php.txt index efc0e5a..f867cde 100644 --- a/Documentation/API/files/Classes/Utility/TypoScriptUtility.php.txt +++ b/Documentation/API/files/Classes/Utility/TypoScriptUtility.php.txt @@ -3,7 +3,7 @@ * Class TypoScriptUtility * * @author Robin 'codeFareith' von den Bergen - * @copyright (c) 2018-2019 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/Resources/Private/Language/fr.locallang.xlf b/Resources/Private/Language/fr.locallang.xlf new file mode 100644 index 0000000..e719563 --- /dev/null +++ b/Resources/Private/Language/fr.locallang.xlf @@ -0,0 +1,54 @@ + + + +
+ + + Google Authenticator Code + + + + Configurer l'authentification à deux facteurs de Google + + + + Mot de passe unique + + + Pour désactiver Google Authenticator, saisissez le mot de passe à usage unique valide et cliquez sur le bouton DÉSACTIVER. + + + + Scannez le code QR + + + Scannez le code QR ci-dessous avec votre application Authenticator. + + + Conservez le code secret dans un endroit sûr + + + Vous avez besoin de ce code secret pour restaurer votre authentificateur. + + + Saisissez le code de vérification + + + Après avoir scanné le code QR, saisissez le code de vérification à 6 chiffres que votre application Authenticator a généré. + + + + Succès! + + + Vos modifications ont été enregistrées avec succès. + + + + diff --git a/Resources/Private/Language/fr.locallang_be.xlf b/Resources/Private/Language/fr.locallang_be.xlf new file mode 100644 index 0000000..e32f8ce --- /dev/null +++ b/Resources/Private/Language/fr.locallang_be.xlf @@ -0,0 +1,60 @@ + + + +
+ + + Google Authenticator QR-Code + + + + Clé + + + + Mot de passe unique + + + + Rangez cette clé dans un endroit sûr. + + + Vous aurez besoin de la clé si vous devez un jour restaurer l'Authenticator. + + + Pour désactiver Google Authenticator, décochez la case ci-dessus et saisissez un mot de passe à usage unique valide. + + + + Succès! + + + Votre compte est désormais également protégé par une authentification à deux facteurs. + + + Succès! + + + Vous avez désactivé l'authentification à deux facteurs. + + + Oops! + + + Le mot de passe à usage unique indiqué était incorrect ou a expiré. + + + Oops! + + + Le mot de passe à usage unique indiqué était incorrect ou a expiré. + + + + diff --git a/Resources/Private/Language/fr.locallang_db.xlf b/Resources/Private/Language/fr.locallang_db.xlf new file mode 100644 index 0000000..7ac6fcf --- /dev/null +++ b/Resources/Private/Language/fr.locallang_db.xlf @@ -0,0 +1,31 @@ + + + +
+ + + Google Authenticator + + + + Activer Google Authenticator + + + Clé de Google Authenticator + + + + Activer Google Authenticator + + + Clé de Google Authenticator + + + + diff --git a/Resources/Private/Language/fr.locallang_ect.xlf b/Resources/Private/Language/fr.locallang_ect.xlf new file mode 100644 index 0000000..59480f6 --- /dev/null +++ b/Resources/Private/Language/fr.locallang_ect.xlf @@ -0,0 +1,26 @@ + + + +
+ + + BE activé : Google Authenticator pour la connexion au backend est activé. + + + FE activé : Google Authenticator pour la connexion frontend est activé. + + + FE-Login Template File : si googleAuthenticatorEnableFE est défini et que vous utilisez EXT:felogin pour la connexion frontend de votre site, le modèle original "FrontendLogin.html" doit être remplacé par un modèle qui fournit le champ de mot de passe à usage unique. + + + Devlog : Écrire des informations de débog dans Devlog. + + + + diff --git a/ext_icon.png b/Resources/Public/Icons/Extension.png similarity index 100% rename from ext_icon.png rename to Resources/Public/Icons/Extension.png diff --git a/Tests/Build/UnitTests.xml b/Tests/Build/UnitTests.xml index e63d396..02a8f4e 100644 --- a/Tests/Build/UnitTests.xml +++ b/Tests/Build/UnitTests.xml @@ -17,7 +17,6 @@ ../../Classes ../../Classes/Service/CoreAuthenticationServiceAdapter.php - ../../Classes/Service/LegacyAuthenticationServiceAdapter.php diff --git a/Tests/Unit/BaseTestCase.php b/Tests/Unit/BaseTestCase.php index 1d62655..a73d37f 100644 --- a/Tests/Unit/BaseTestCase.php +++ b/Tests/Unit/BaseTestCase.php @@ -1,7 +1,7 @@ - * @copyright (c) 2018 by Robin von den Bergen + * @copyright (c) 2018-2022 by Robin von den Bergen * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.0.0 * diff --git a/composer.json b/composer.json index 58f81af..3268d2d 100644 --- a/composer.json +++ b/composer.json @@ -46,9 +46,9 @@ "rss": "https://github.com/codeFareith/cf_google_authenticator/commits/master.atom" }, "require": { - "typo3/cms-core": "^8.7 || ^9.5", - "typo3/cms-reports": "^8.7 || ^9.5", - "typo3/cms-setup": "^8.7 || ^9.5", + "typo3/cms-core": "^9.5 || ^10.4", + "typo3/cms-reports": "^9.5 || ^10.4", + "typo3/cms-setup": "^9.5 || ^10.4", "ext-json": "*" }, "require-dev": { diff --git a/ext_emconf.php b/ext_emconf.php index 95da051..15a33eb 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -1,47 +1,36 @@ - * @copyright (c) 2018-2019 by Robin von den Bergen - * @license http://opensource.org/licenses/gpl-license.php GNU Public License - * @version 1.0.0 + * Auto generated 23-11-2020 17:42 * - * @link https://github.com/codeFareith/cf_google_authenticator - * @see https://www.fareith.de - * @see https://typo3.org - */ - -/** @var string $_EXTKEY */ + * Manual updates: + * Only the data in the array - everything else is removed by next + * writing. "version" and "dependencies" must not be touched! + ***************************************************************/ $EM_CONF[$_EXTKEY] = [ 'title' => '[codeFareith] Google Authenticator', 'description' => 'Enable Google 2FA (two factor authentication) for both, frontend- and backend accounts.', 'category' => 'misc', - 'author' => 'Robin "codeFareith" von den Bergen', 'author_email' => 'robin@vondenbergen.de', 'author_company' => '', - 'state' => 'stable', 'version' => '1.2.4', - 'uploadFolders' => false, 'createDirs' => '', 'clearCacheOnLoad' => true, - 'constraints' => [ 'depends' => [ - 'php' => '7.1-', - 'typo3' => '8.7.0-9.5.99', + 'php' => '7.2-', + 'typo3' => '9.5.0-10.4.99', ], 'conflicts' => [ ], 'suggests' => [ - 'felogin' => '8.7.0-9.5.99', + 'felogin' => '9.5.0-10.4.99', ], ], @@ -56,3 +45,4 @@ ], ], ]; + diff --git a/ext_localconf.php b/ext_localconf.php index 91a0b32..4c1db5f 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -26,12 +26,6 @@ static function ($_EXTKEY) { $extConf = \CodeFareith\CfGoogleAuthenticator\Utility\ExtensionBasicDataUtility::getExtensionConfiguration(); - $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( - \TYPO3\CMS\Extbase\Object\ObjectManager::class - ); - $adapterFactory = $objectManager->get(\CodeFareith\CfGoogleAuthenticator\Service\GoogleAuthenticationServiceAdapterFactory::class); - $adapter = $adapterFactory->create(); - \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addService( $_EXTKEY, 'auth', @@ -45,7 +39,7 @@ static function ($_EXTKEY) { 'quality' => 80, 'os' => '', 'exec' => '', - 'className' => get_class($adapter), + 'className' => \CodeFareith\CfGoogleAuthenticator\Service\CoreAuthenticationServiceAdapter::class, ] ); @@ -95,7 +89,13 @@ static function ($_EXTKEY) { ['felogin'] ['postProcContent'] [$_EXTKEY] = \CodeFareith\CfGoogleAuthenticator\Hook\FeLogin::class . '->createOneTimePasswordField'; + + // Register a node in ext_localconf.php + $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1606376982] = [ + 'nodeName' => 'TwoFactorAuth', + 'priority' => 40, + 'class' => \CodeFareith\CfGoogleAuthenticator\Backend\Form\Element\TwoFactorAuth::class, + ]; }, - /** @var string $_EXTKEY */ - $_EXTKEY + 'cf_google_authenticator' ); diff --git a/ext_tables.php b/ext_tables.php index 984f214..da8daae 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -24,37 +24,34 @@ or die('Access denied.'); call_user_func( - static function (/*$_EXTKEY*/) { + static function ($_EXTKEY) { $globalsReference = &$GLOBALS; $globalsReference['TBE_STYLES'] ['stylesheet2'] = \CodeFareith\CfGoogleAuthenticator\Utility\PathUtility::makeExtensionPath('Resources/Public/Css/cf_google_authenticator.css'); - if (TYPO3_version >= '9.0.0') { - $globalsReference['TYPO3_USER_SETTINGS']['columns'] = array_merge( - $globalsReference['TYPO3_USER_SETTINGS']['columns'], - [ - 'tx_cfgoogleauthenticator_enabled' => [ - 'label' => \CodeFareith\CfGoogleAuthenticator\Utility\PathUtility::makeLocalLangLinkPath( - 'be_users.tx_cfgoogleauthenticator_enabled', - 'locallang_db.xlf' - ), - 'type' => 'check', - 'table' => 'be_users', - ], + $globalsReference['TYPO3_USER_SETTINGS']['columns'] = array_merge( + $globalsReference['TYPO3_USER_SETTINGS']['columns'], + [ + 'tx_cfgoogleauthenticator_enabled' => [ + 'label' => \CodeFareith\CfGoogleAuthenticator\Utility\PathUtility::makeLocalLangLinkPath( + 'be_users.tx_cfgoogleauthenticator_enabled', + 'locallang_db.xlf' + ), + 'type' => 'check', + 'table' => 'be_users', + ], - 'tx_cfgoogleauthenticator_secret' => [ - 'label' => \CodeFareith\CfGoogleAuthenticator\Utility\PathUtility::makeLocalLangLinkPath( - 'be_users.tx_cfgoogleauthenticator_secret', - 'locallang_db.xlf' - ), - 'type' => 'user', - 'userFunc' => \CodeFareith\CfGoogleAuthenticator\Hook\UserSettings::class . '->createSecretField', - 'table' => 'be_users', - ], - ] - ); - } + 'tx_cfgoogleauthenticator_secret' => [ + 'label' => \CodeFareith\CfGoogleAuthenticator\Utility\PathUtility::makeLocalLangLinkPath( + 'be_users.tx_cfgoogleauthenticator_secret', + 'locallang_db.xlf' + ), + 'type' => 'user', + 'userFunc' => \CodeFareith\CfGoogleAuthenticator\Hook\UserSettings::class . '->createSecretField', + ], + ] + ); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToUserSettings( '--div--;' . \CodeFareith\CfGoogleAuthenticator\Utility\PathUtility::makeLocalLangLinkPath( @@ -65,6 +62,5 @@ static function (/*$_EXTKEY*/) { tx_cfgoogleauthenticator_secret' ); }, - /** @var string $_EXTKEY */ - $_EXTKEY + 'cf_google_authenticator' ); diff --git a/ext_typoscript_setup.typoscript b/ext_typoscript_setup.typoscript deleted file mode 100644 index cec0503..0000000 --- a/ext_typoscript_setup.typoscript +++ /dev/null @@ -1,18 +0,0 @@ -config { - tx_extbase { - persistence { - classes { - CodeFareith\CfGoogleAuthenticator\Domain\Model\FrontendUser { - mapping { - tableName = fe_users - } - } - CodeFareith\CfGoogleAuthenticator\Domain\Model\BackendUser { - mapping { - tableName = be_users - } - } - } - } - } -}