Passed
Push — master ( 25a926...39145a )
by
unknown
20:30
created

MfaStatusViewHelper::getLanguageService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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\Beuser\ViewHelpers;
19
20
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
21
use TYPO3\CMS\Core\Authentication\Mfa\MfaProviderRegistry;
22
use TYPO3\CMS\Core\Localization\LanguageService;
23
use TYPO3\CMS\Core\Utility\GeneralUtility;
24
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
25
26
/**
27
 * Render MFA status information
28
 *
29
 * @internal
30
 */
31
class MfaStatusViewHelper extends AbstractTagBasedViewHelper
32
{
33
    protected $tagName = 'span';
34
35
    public function initializeArguments(): void
36
    {
37
        parent::initializeArguments();
38
        $this->registerUniversalTagAttributes();
39
        $this->registerArgument('userUid', 'int', 'The uid of the user to check', true);
40
    }
41
42
    public function render(): string
43
    {
44
        $userUid = (int)($this->arguments['userUid'] ?? 0);
45
        if (!$userUid) {
46
            return '';
47
        }
48
49
        $backendUser = GeneralUtility::makeInstance(BackendUserAuthentication::class);
50
        $backendUser->enablecolumns = ['deleted' => true];
51
        $backendUser->setBeUserByUid($userUid);
52
53
        $mfaProviderRegistry = GeneralUtility::makeInstance(MfaProviderRegistry::class);
54
55
        // Check if user has active providers
56
        if (!$mfaProviderRegistry->hasActiveProviders($backendUser)) {
57
            return '';
58
        }
59
60
        // Check locked providers
61
        if ($mfaProviderRegistry->hasLockedProviders($backendUser)) {
62
            $this->tag->addAttribute('class', 'label label-warning');
63
            $this->tag->setContent(htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:lockedMfaProviders')));
64
            return $this->tag->render();
65
        }
66
67
        // Add mfa enabled label since we have active providers and non of them are locked
68
        $this->tag->addAttribute('class', 'label label-info');
69
        $this->tag->setContent(htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:mfaEnabled')));
70
        return $this->tag->render();
71
    }
72
73
    protected function getLanguageService(): LanguageService
74
    {
75
        return $GLOBALS['LANG'];
76
    }
77
}
78