Skip to content

Commit

Permalink
AccessControlService can not detect logged in frontend user #93
Browse files Browse the repository at this point in the history
  • Loading branch information
thucke authored and thucke committed Feb 19, 2021
1 parent 2d93763 commit 1d6d009
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions Classes/Service/AccessControlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
}

Expand All @@ -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');
}

/**
Expand All @@ -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');
}

/**
Expand All @@ -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 [];
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 1d6d009

Please sign in to comment.