diff --git a/Classes/Controller/Frontend/SetupController.php b/Classes/Controller/Frontend/SetupController.php index 7cbc2a4..d96d2dc 100644 --- a/Classes/Controller/Frontend/SetupController.php +++ b/Classes/Controller/Frontend/SetupController.php @@ -33,7 +33,7 @@ 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 function get_class; use function vsprintf; @@ -93,8 +93,6 @@ public function __construct( Context $context ) { - parent::__construct(); - $this->frontendUserRepository = $frontendUserRepository; $this->qrCodeGenerator = $qrCodeGenerator; $this->setupFormValidator = $setupFormValidator; diff --git a/Classes/Hook/FeLogin.php b/Classes/Hook/FeLogin.php index 85c6b6d..404df00 100644 --- a/Classes/Hook/FeLogin.php +++ b/Classes/Hook/FeLogin.php @@ -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..87888ce 100644 --- a/Classes/Hook/TCEMain.php +++ b/Classes/Hook/TCEMain.php @@ -54,7 +54,7 @@ class TCEMain /** * @noinspection MoreThanThreeArgumentsInspection * - * @param mixed $fieldArray + * @param mixed $fieldArray * @param string|int $id * * @throws MissingRequiredField @@ -75,7 +75,14 @@ public function processDatamap_preProcessFieldArray( $otpInFieldArray = $otpInPostData; } - $preProcessFieldArrayDTO = $this->getPreProcessFieldArrayDTO($fieldArray, $table, (int) $id, $dataHandler); + $otpInFieldArray2 = &$fieldArray['tx_cfgoogleauthenticator_secret']; + $otpInPostData2 = $_POST['data']['be_users']['tx_cfgoogleauthenticator_secret']; + + if ($otpInFieldArray2 === null && $otpInPostData2 !== null) { + $otpInFieldArray2 = $otpInPostData2; + } + + $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..96bd5e7 100644 --- a/Classes/Hook/UserSettings.php +++ b/Classes/Hook/UserSettings.php @@ -26,6 +26,7 @@ use TYPO3\CMS\Fluid\View\StandaloneView; use function sprintf; use function vsprintf; +use TYPO3\CMS\Backend\Form\Element\AbstractFormElement; /** * Hook for the user settings @@ -37,7 +38,7 @@ * @package CodeFareith\CfGoogleAuthenticator\Hook * @since 1.0.0 */ -class UserSettings +class UserSettings extends AbstractFormElement { /*─────────────────────────────────────────────────────────────────────────────*\ Traits @@ -71,21 +72,20 @@ class UserSettings * @return string * @throws Exception */ - public function createSecretField(array $data): string + public function render(): array { - $this->data = $data; - + $result = $this->initializeResultArray(); $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 ($this->data['tableName'] !== null) { + $prefix .= sprintf('[%s]', $this->data['tableName']); } - if ($data['row']['uid'] !== null) { - $prefix .= sprintf('[%s]', (string)$data['row']['uid']); + if ($data['databaseRow']['uid'] !== null) { + $prefix .= sprintf('[%s]', (string)$this->data['databaseRow']['uid']); } $templateView->assignMultiple( @@ -97,7 +97,9 @@ public function createSecretField(array $data): string ] ); - return $templateView->render(); + $result['html'] = $templateView->render(); + + return $result; } private function initializeTemplateView(): StandaloneView @@ -146,15 +148,15 @@ private function getLayer(): string { $layer = ''; - if ($this->data['table'] === 'fe_users') { + if ($this->data['tableName'] === 'fe_users') { $layer = 'Frontend'; - } elseif ($this->data['table'] === 'be_users') { + } elseif ($this->data['tableName'] === 'be_users') { $layer = 'Backend'; } $dispatcher = GeneralUtility::makeInstance(Dispatcher::class); $signalArguments = [ - 'table' => $this->data['table'], + 'table' => $this->data['tableName'], 'layer' => $layer, 'caller' => $this, ]; @@ -169,7 +171,7 @@ private function getLayer(): string private function getUsername(): string { - return $this->data['row']['username'] ?? ''; + return $this->data['databaseRow']['username'] ?? ''; } /** @@ -195,7 +197,7 @@ private function getAuthenticationSecret(): AuthenticationSecret private function getSecretKey(): string { if ($this->isGoogleAuthenticatorEnabled()) { - $secretKey = (string) $this->data['row']['tx_cfgoogleauthenticator_secret']; + $secretKey = (string) $this->data['databaseRow']['tx_cfgoogleauthenticator_secret']; } else { $secretKey = Base32Utility::generateRandomString(16); } @@ -205,10 +207,10 @@ private function getSecretKey(): string private function isGoogleAuthenticatorEnabled(): bool { - if ($this->data['type'] === 'user' && !is_array($this->data['row'])) { - $this->data['row'] = $GLOBALS['BE_USER']->user; + if ($this->data['parameterArray']['fieldConf']['config']['type'] === 'user' && !is_array($this->data['databaseRow'])) { + $this->data['databaseRow'] = $GLOBALS['BE_USER']->user; } - return (bool) $this->data['row']['tx_cfgoogleauthenticator_enabled']; + return (bool) $this->data['databaseRow']['tx_cfgoogleauthenticator_enabled']; } private function getQrCodeGenerator(): QrCodeGeneratorInterface 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..c1705ed 100644 --- a/Configuration/TCA/Overrides/be_users.php +++ b/Configuration/TCA/Overrides/be_users.php @@ -41,7 +41,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..478bc7e 100644 --- a/Configuration/TCA/Overrides/fe_users.php +++ b/Configuration/TCA/Overrides/fe_users.php @@ -41,7 +41,7 @@ static function () { ), 'config' => [ 'type' => 'user', - 'userFunc' => \CodeFareith\CfGoogleAuthenticator\Hook\UserSettings::class . '->createSecretField', + 'renderType' => 'TwoFactorAuth', ], ], ] 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..f1e2986 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', + '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..021d36f 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,14 @@ 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\Hook\UserSettings::class, + ]; }, /** @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 - } - } - } - } - } -}