From 1d6d009faa19aaca9a3f38eeedc33fa9c6639029 Mon Sep 17 00:00:00 2001 From: thucke Date: Fri, 19 Feb 2021 17:23:41 +0100 Subject: [PATCH] AccessControlService can not detect logged in frontend user #93 --- Classes/Service/AccessControlService.php | 27 +++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Classes/Service/AccessControlService.php b/Classes/Service/AccessControlService.php index 0ad4cdfd..07b1354d 100644 --- a/Classes/Service/AccessControlService.php +++ b/Classes/Service/AccessControlService.php @@ -68,6 +68,18 @@ public function injectVoterRepository(\Thucke\ThRating\Domain\Repository\VoterRe $this->voterRepository = $voterRepository; } + /** + * @var \TYPO3\CMS\Core\Context\Context $context + */ + protected $context; + /** + * @param \TYPO3\CMS\Core\Context\Context $context + */ + public function injectContext(\TYPO3\CMS\Core\Context\Context $context): void + { + $this->context = $context; + } + /** * Tests, if the given person is logged into the frontend * @@ -86,7 +98,6 @@ public function isLoggedIn(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser $person return true; //treat anonymous user also as logged in } } - return false; } @@ -96,9 +107,7 @@ public function isLoggedIn(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser $person */ public function backendAdminIsLoggedIn(): bool { - /** @var Context $context */ - $context = GeneralUtility::makeInstance(Context::class, null); - return $context->getPropertyFromAspect('backend.user', 'isLoggedIn'); + return $this->context->getPropertyFromAspect('backend.user', 'isLoggedIn'); } /** @@ -108,8 +117,7 @@ public function backendAdminIsLoggedIn(): bool public function hasLoggedInFrontendUser(): bool { /** @var Context $context */ - $context = GeneralUtility::makeInstance(Context::class, array()); - return $context->getPropertyFromAspect('frontend.user', 'isLoggedIn'); + return $this->context->getPropertyFromAspect('frontend.user', 'isLoggedIn'); } /** @@ -119,9 +127,8 @@ public function hasLoggedInFrontendUser(): bool public function getFrontendUserGroups(): array { if ($this->hasLoggedInFrontendUser()) { - return $GLOBALS['TSFE']->fe_user->groupData['uid']; + return $this->context->getPropertyFromAspect('frontend.user', 'groupIds'); } - return []; } @@ -131,8 +138,8 @@ public function getFrontendUserGroups(): array */ public function getFrontendUserUid(): ?int { - if ($this->hasLoggedInFrontendUser() && !empty($GLOBALS['TSFE']->fe_user->user['uid'])) { - return (int)$GLOBALS['TSFE']->fe_user->user['uid']; + if ($this->hasLoggedInFrontendUser()) { + return $this->context->getPropertyFromAspect('frontend.user', 'id'); } return null; }