Skip to content

Commit

Permalink
Merge pull request #17 from sandstorm/authentificationFix
Browse files Browse the repository at this point in the history
BUGFIX: fixed IfAuthenticatedViewHelper to work with Flow 4.0
  • Loading branch information
Pingu501 authored Apr 12, 2017
2 parents 9f62ffb + f98f404 commit 3dc8f79
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions Classes/ViewHelpers/IfAuthenticatedViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
use Neos\Flow\Security\Authentication\TokenInterface;
use Neos\Flow\Security\Context;
use Neos\FluidAdaptor\Core\ViewHelper\AbstractConditionViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;

class IfAuthenticatedViewHelper extends AbstractConditionViewHelper
{
/**
* @Flow\Inject
* @var Context
*/
protected $securityContext;


/**
* Renders <f:then> child if any account is currently authenticated, otherwise renders <f:else> child.
Expand All @@ -24,14 +19,32 @@ class IfAuthenticatedViewHelper extends AbstractConditionViewHelper
*/
public function render($authenticationProviderName = 'Sandstorm.UserManagement:Login')
{
$activeTokens = $this->securityContext->getAuthenticationTokens();
if (static::evaluateCondition($this->arguments, $this->renderingContext)) {
return $this->renderThenChild();
}

return $this->renderElseChild();
}

/**
* @param null $arguments
* @param RenderingContextInterface $renderingContext
* @return bool
*/
protected static function evaluateCondition($arguments = null, RenderingContextInterface $renderingContext)
{
$objectManager = $renderingContext->getObjectManager();
/** @var Context $securityContext */
$securityContext = $objectManager->get(Context::class);
$activeTokens = $securityContext->getAuthenticationTokens();


/** @var $token TokenInterface */
foreach ($activeTokens as $token) {
if ($token->getAuthenticationProviderName() === $authenticationProviderName && $token->isAuthenticated()) {
return $this->renderThenChild();
if ($token->getAuthenticationProviderName() === $arguments['authenticationProviderName'] && $token->isAuthenticated()) {
return true;
}
}

return $this->renderElseChild();
return false;
}
}

0 comments on commit 3dc8f79

Please sign in to comment.