|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the TYPO3 CMS project. |
|
7
|
|
|
* |
|
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
10
|
|
|
* of the License, or any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please read the |
|
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
14
|
|
|
* |
|
15
|
|
|
* The TYPO3 project - inspiring people to share! |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Backend\ViewHelpers\Mfa; |
|
19
|
|
|
|
|
20
|
|
|
use TYPO3\CMS\Core\Authentication\Mfa\MfaProviderManifestInterface; |
|
21
|
|
|
use TYPO3\CMS\Core\Authentication\Mfa\MfaProviderPropertyManager; |
|
22
|
|
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
|
23
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Check if the given provider for the current user has the requested state set |
|
27
|
|
|
* |
|
28
|
|
|
* @internal |
|
29
|
|
|
*/ |
|
30
|
|
|
class IfHasStateViewHelper extends AbstractConditionViewHelper |
|
31
|
|
|
{ |
|
32
|
|
|
public function initializeArguments(): void |
|
33
|
|
|
{ |
|
34
|
|
|
parent::initializeArguments(); |
|
35
|
|
|
$this->registerArgument('state', 'string', 'The state to check for (e.g. active or locked)', true); |
|
36
|
|
|
$this->registerArgument('provider', MfaProviderManifestInterface::class, 'The provider in question', true); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public static function verdict(array $arguments, RenderingContextInterface $renderingContext): bool |
|
40
|
|
|
{ |
|
41
|
|
|
$stateMethod = 'is' . ucfirst($arguments['state']); |
|
42
|
|
|
$provider = $arguments['provider']; |
|
43
|
|
|
|
|
44
|
|
|
$propertyManager = MfaProviderPropertyManager::create($provider, $GLOBALS['BE_USER']); |
|
45
|
|
|
return is_callable([$provider, $stateMethod]) && $provider->{$stateMethod}($propertyManager); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|