5
5
use Neos \Flow \Security \Authentication \TokenInterface ;
6
6
use Neos \Flow \Security \Context ;
7
7
use Neos \FluidAdaptor \Core \ViewHelper \AbstractConditionViewHelper ;
8
+ use TYPO3Fluid \Fluid \Core \Rendering \RenderingContextInterface ;
8
9
9
10
class IfAuthenticatedViewHelper extends AbstractConditionViewHelper
10
11
{
11
- /**
12
- * @Flow\Inject
13
- * @var Context
14
- */
15
- protected $ securityContext ;
16
-
17
12
18
13
/**
19
14
* Renders <f:then> child if any account is currently authenticated, otherwise renders <f:else> child.
@@ -24,14 +19,32 @@ class IfAuthenticatedViewHelper extends AbstractConditionViewHelper
24
19
*/
25
20
public function render ($ authenticationProviderName = 'Sandstorm.UserManagement:Login ' )
26
21
{
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
+
28
42
/** @var $token TokenInterface */
29
43
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 ;
32
46
}
33
47
}
34
-
35
- return $ this ->renderElseChild ();
48
+ return false ;
36
49
}
37
50
}
0 commit comments