Skip to content

Commit 3dc8f79

Browse files
authored
Merge pull request #17 from sandstorm/authentificationFix
BUGFIX: fixed IfAuthenticatedViewHelper to work with Flow 4.0
2 parents 9f62ffb + f98f404 commit 3dc8f79

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

Classes/ViewHelpers/IfAuthenticatedViewHelper.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@
55
use Neos\Flow\Security\Authentication\TokenInterface;
66
use Neos\Flow\Security\Context;
77
use Neos\FluidAdaptor\Core\ViewHelper\AbstractConditionViewHelper;
8+
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
89

910
class IfAuthenticatedViewHelper extends AbstractConditionViewHelper
1011
{
11-
/**
12-
* @Flow\Inject
13-
* @var Context
14-
*/
15-
protected $securityContext;
16-
1712

1813
/**
1914
* Renders <f:then> child if any account is currently authenticated, otherwise renders <f:else> child.
@@ -24,14 +19,32 @@ class IfAuthenticatedViewHelper extends AbstractConditionViewHelper
2419
*/
2520
public function render($authenticationProviderName = 'Sandstorm.UserManagement:Login')
2621
{
27-
$activeTokens = $this->securityContext->getAuthenticationTokens();
22+
if (static::evaluateCondition($this->arguments, $this->renderingContext)) {
23+
return $this->renderThenChild();
24+
}
25+
26+
return $this->renderElseChild();
27+
}
28+
29+
/**
30+
* @param null $arguments
31+
* @param RenderingContextInterface $renderingContext
32+
* @return bool
33+
*/
34+
protected static function evaluateCondition($arguments = null, RenderingContextInterface $renderingContext)
35+
{
36+
$objectManager = $renderingContext->getObjectManager();
37+
/** @var Context $securityContext */
38+
$securityContext = $objectManager->get(Context::class);
39+
$activeTokens = $securityContext->getAuthenticationTokens();
40+
41+
2842
/** @var $token TokenInterface */
2943
foreach ($activeTokens as $token) {
30-
if ($token->getAuthenticationProviderName() === $authenticationProviderName && $token->isAuthenticated()) {
31-
return $this->renderThenChild();
44+
if ($token->getAuthenticationProviderName() === $arguments['authenticationProviderName'] && $token->isAuthenticated()) {
45+
return true;
3246
}
3347
}
34-
35-
return $this->renderElseChild();
48+
return false;
3649
}
3750
}

0 commit comments

Comments
 (0)