‪TYPO3CMS  ‪main
MfaStatusViewHelper.php
Go to the documentation of this file.
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 
19 
24 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
25 
31 final 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', 'badge badge-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', 'badge badge-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 
74  {
75  return ‪$GLOBALS['LANG'];
76  }
77 }
‪TYPO3\CMS\Beuser\ViewHelpers\MfaStatusViewHelper\$tagName
‪$tagName
Definition: MfaStatusViewHelper.php:33
‪TYPO3\CMS\Beuser\ViewHelpers
Definition: ArrayElementViewHelper.php:18
‪TYPO3\CMS\Beuser\ViewHelpers\MfaStatusViewHelper\getLanguageService
‪getLanguageService()
Definition: MfaStatusViewHelper.php:73
‪TYPO3\CMS\Beuser\ViewHelpers\MfaStatusViewHelper\initializeArguments
‪initializeArguments()
Definition: MfaStatusViewHelper.php:35
‪TYPO3\CMS\Beuser\ViewHelpers\MfaStatusViewHelper
Definition: MfaStatusViewHelper.php:32
‪TYPO3\CMS\Beuser\ViewHelpers\MfaStatusViewHelper\render
‪render()
Definition: MfaStatusViewHelper.php:42
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Authentication\Mfa\MfaProviderRegistry
Definition: MfaProviderRegistry.php:28