Skip to content

Commit

Permalink
Merge pull request #11 from b13/pr/v12-update
Browse files Browse the repository at this point in the history
[FEATURE] Add TYPO3 v12 support and drop v10 support
  • Loading branch information
bmack authored May 2, 2024
2 parents 7b3ecb9 + c13e0b8 commit f60ae4b
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 219 deletions.
19 changes: 11 additions & 8 deletions Classes/Controller/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

use B13\Sessionpassword\Helper\PasswordHasher;
use B13\Sessionpassword\Helper\SessionHelper;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;

/**
* The application logic for the Password Form
Expand All @@ -32,10 +34,10 @@ class PasswordController extends ActionController
* case 3: wrong entered password => show the form plus a message
* case 4: valid entered password => store in session and check for a redirect
*
* @param string $password the entered password
* @param string|null $password the entered password
* @param string $referer URL to redirect to. Takes pre
*/
public function unlockAction($password = null, $referer = '')
public function unlockAction(?string $password = null, string $referer = ''): ResponseInterface
{
$sessionHelper = GeneralUtility::makeInstance(SessionHelper::class);
$passwordHelper = GeneralUtility::makeInstance(PasswordHasher::class);
Expand All @@ -49,7 +51,7 @@ public function unlockAction($password = null, $referer = '')
if ($enteredPassword === null) {
// case 1: needed password is in session => don't show anything as everything is done already
if ($sessionHelper->isInSession($neededPassword)) {
return '';
return new HtmlResponse('');
}
// case 2: needed password is not in session
// => show the form without any message
Expand All @@ -68,9 +70,9 @@ public function unlockAction($password = null, $referer = '')
// make sure the groups get initialized again, (done via the FrontendUsergroupService)
// so if the redirect page is a protected page, you can
// @todo: maybe we need to do the storeInSession in an earlier phase.
/** @var TypoScriptFrontendController $tsfe */
$tsfe = $GLOBALS['TSFE'];
$tsfe->initUserGroups();
/** @var FrontendUserAuthentication $frontendUser */
$frontendUser = $this->request->getAttribute('frontend.user');
$frontendUser->fetchGroupData($this->request);
if (!empty($referer)) {
$this->redirectToUri($referer);
}
Expand All @@ -80,8 +82,9 @@ public function unlockAction($password = null, $referer = '')
'parameter' => $this->settings['redirectPage'],
'linkAccessRestrictedPages' => 1
]);
$this->redirectToUri($url);
return $this->redirectToUri($url);
}
}
return new HtmlResponse($this->view->render());
}
}
24 changes: 11 additions & 13 deletions Classes/EventListener/ModifyResolvedFrontendGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
class ModifyResolvedFrontendGroups
{
protected string $usergroupTable;
protected array $authInfo;
protected LoggerInterface $logger;

public function __invoke(ModifyResolvedFrontendGroupsEvent $event): void
{

$allGroups = $event->getGroups();
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$this->usergroupTable = $event->getUser()->usergroup_table;

$groups = [];
if (GeneralUtility::_GP('logintype') === 'logout') {
$this->authInfo = $event->getUser()->getAuthInfoArray($event->getRequest());
$loginType = (string)($event->getRequest()->getQueryParams()['logintype'] ?? $event->getRequest()->getParsedBody()['logintype'] ?? '');
if ($loginType === 'logout') {
GeneralUtility::makeInstance(SessionHelper::class, $event->getUser())->clearSessionData();
} else {
$groups = $this->findValidSessionUsergroups($event->getUser());
Expand All @@ -55,18 +55,16 @@ public function __invoke(ModifyResolvedFrontendGroupsEvent $event): void
$queryBuilder->createNamedParameter($groups, Connection::PARAM_INT_ARRAY)
)
)
->execute();
while ($row = $res->fetch()) {
$allGroups[$row['uid']] = $row;
->executeQuery();
while ($row = $res->fetchAssociative()) {
$allGroups[] = $row;
}
}
}


$event->setGroups($allGroups);
}

protected function findValidSessionUsergroups(FrontendUserAuthentication $frontendUserAuthentication)
protected function findValidSessionUsergroups(FrontendUserAuthentication $frontendUserAuthentication): array
{
$groups = [];
$sessionHelper = GeneralUtility::makeInstance(SessionHelper::class, $frontendUserAuthentication);
Expand All @@ -90,7 +88,7 @@ protected function findValidSessionUsergroups(FrontendUserAuthentication $fronte
* @param array $groups
* @return array
*/
public function getSubGroups($grList, $idList, &$groups)
protected function getSubGroups(string $grList, string $idList, array &$groups): void
{
// Fetching records of the groups in $grList (which are not blocked by lockedToDomain either):
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('fe_groups');
Expand All @@ -110,12 +108,12 @@ public function getSubGroups($grList, $idList, &$groups)
)
)
)
->execute();
->executeQuery();

// Internal group record storage
$groupRows = [];
// The groups array is filled
while ($row = $res->fetch()) {
while ($row = $res->fetchAssociative()) {
if (!in_array($row['uid'], $groups)) {
$groups[] = $row['uid'];
}
Expand Down
10 changes: 9 additions & 1 deletion Classes/Helper/SessionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* of the License, or any later version.
*/

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;

Expand Down Expand Up @@ -87,6 +88,13 @@ public function clearSessionData(): void
*/
protected function getUserObject(): FrontendUserAuthentication
{
return $GLOBALS['TSFE']->fe_user;
$user = null;
if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface) {
$user = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user');
}
if ($user === null) {
return $GLOBALS['TSFE']->fe_user;
}
return $user;
}
}
2 changes: 1 addition & 1 deletion Classes/Service/ContentObjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ContentObjectService implements ContentObjectPostInitHookInterface
* called at the end of cObj->start().
* @param ContentObjectRenderer $parentObject
*/
public function postProcessContentObjectInitialization(ContentObjectRenderer &$parentObject)
public function postProcessContentObjectInitialization(ContentObjectRenderer &$parentObject): void
{
// check if the DB record has a tx_sessionpassword
if ($parentObject->getCurrentTable() === 'tt_content' && !empty($parentObject->data['tx_sessionpassword'])) {
Expand Down
169 changes: 0 additions & 169 deletions Classes/Service/FrontendUsergroupService.php

This file was deleted.

7 changes: 5 additions & 2 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
services:
_defaults:
autowire: false
autoconfigure: false
autowire: true
autoconfigure: true
public: false

B13\Sessionpassword\:
resource: '../Classes/*'

B13\Sessionpassword\Controller\PasswordController:
public: true

B13\Sessionpassword\EventListener\ModifyResolvedFrontendGroups:
tags:
- name: event.listener
Expand Down
6 changes: 2 additions & 4 deletions Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$useHashedPasswords = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)->get('sessionpassword', 'useHashedPasswords');

// add the additional field to tt_content
$tempColumns = [
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', [
'tx_sessionpassword' => [
'label' => 'LLL:EXT:sessionpassword/Resources/Private/Language/db.xlf:tt_content.tx_sessionpassword',
'exclude' => true,
Expand All @@ -16,9 +16,7 @@
'eval' => 'trim' . ($useHashedPasswords ? ',password,saltedPassword' : ''),
],
],
];

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $tempColumns);
]);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin('sessionpassword', 'Password', 'Session Password Form');

$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['sessionpassword_password'] = 'layout,select_key,pages,recursive';
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"role": "Maintainer"
}],
"require": {
"php": "^7.4 || ^8",
"typo3/cms-core": "^10 || ^11"
"php": "^7.4 || ^8",
"typo3/cms-core": "^11.5 || ^12.4"
},
"extra": {
"typo3/cms": {
Expand Down
4 changes: 2 additions & 2 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
'author' => 'b13 GmbH',
'author_email' => '[email protected]',
'state' => 'stable',
'version' => '2.1.0',
'version' => '2.2.0',
'constraints' => [
'depends' => [
'core' => '10.0.0-11.5.99',
'core' => '11.5.0-12.9.99',
],
'conflicts' => [
],
Expand Down
Loading

0 comments on commit f60ae4b

Please sign in to comment.