[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_users 6 * 7 * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Users\Administrator\View\Methods; 12 13 use Joomla\CMS\Event\MultiFactor\NotifyActionLog; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Language\Text; 16 use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; 17 use Joomla\CMS\Router\Route; 18 use Joomla\CMS\Toolbar\ToolbarHelper; 19 use Joomla\CMS\User\User; 20 use Joomla\CMS\User\UserFactoryInterface; 21 use Joomla\Component\Users\Administrator\DataShape\MethodDescriptor; 22 use Joomla\Component\Users\Administrator\Model\BackupcodesModel; 23 use Joomla\Component\Users\Administrator\Model\MethodsModel; 24 use Joomla\Component\Users\Administrator\View\SiteTemplateTrait; 25 26 // phpcs:disable PSR1.Files.SideEffects 27 \defined('_JEXEC') or die; 28 // phpcs:enable PSR1.Files.SideEffects 29 30 /** 31 * View for Multi-factor Authentication methods list page 32 * 33 * @since 4.2.0 34 */ 35 class HtmlView extends BaseHtmlView 36 { 37 use SiteTemplateTrait; 38 39 /** 40 * Is this an administrator page? 41 * 42 * @var boolean 43 * @since 4.2.0 44 */ 45 public $isAdmin = false; 46 47 /** 48 * The MFA Methods available for this user 49 * 50 * @var array 51 * @since 4.2.0 52 */ 53 public $methods = []; 54 55 /** 56 * The return URL to use for all links and forms 57 * 58 * @var string 59 * @since 4.2.0 60 */ 61 public $returnURL = null; 62 63 /** 64 * Are there any active MFA Methods at all? 65 * 66 * @var boolean 67 * @since 4.2.0 68 */ 69 public $mfaActive = false; 70 71 /** 72 * Which Method has the default record? 73 * 74 * @var string 75 * @since 4.2.0 76 */ 77 public $defaultMethod = ''; 78 79 /** 80 * The user object used to display this page 81 * 82 * @var User 83 * @since 4.2.0 84 */ 85 public $user = null; 86 87 /** 88 * Is this page part of the mandatory Multi-factor Authentication setup? 89 * 90 * @var boolean 91 * @since 4.2.0 92 */ 93 public $isMandatoryMFASetup = false; 94 95 /** 96 * Execute and display a template script. 97 * 98 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 99 * 100 * @return void 101 * 102 * @throws \Exception 103 * @see \JViewLegacy::loadTemplate() 104 * @since 4.2.0 105 */ 106 public function display($tpl = null): void 107 { 108 $this->setSiteTemplateStyle(); 109 110 $app = Factory::getApplication(); 111 112 if (empty($this->user)) { 113 $this->user = Factory::getApplication()->getIdentity() 114 ?: Factory::getContainer()->get(UserFactoryInterface::class)->loadUserById(0); 115 } 116 117 /** @var MethodsModel $model */ 118 $model = $this->getModel(); 119 120 if ($this->getLayout() !== 'firsttime') { 121 $this->setLayout('default'); 122 } 123 124 $this->methods = $model->getMethods($this->user); 125 $this->isAdmin = $app->isClient('administrator'); 126 $activeRecords = 0; 127 128 foreach ($this->methods as $methodName => $method) { 129 $methodActiveRecords = count($method['active']); 130 131 if (!$methodActiveRecords) { 132 continue; 133 } 134 135 $activeRecords += $methodActiveRecords; 136 $this->mfaActive = true; 137 138 foreach ($method['active'] as $record) { 139 if ($record->default) { 140 $this->defaultMethod = $methodName; 141 142 break; 143 } 144 } 145 } 146 147 // If there are no backup codes yet we should create new ones 148 /** @var BackupcodesModel $model */ 149 $model = $this->getModel('backupcodes'); 150 $backupCodes = $model->getBackupCodes($this->user); 151 152 if ($activeRecords && empty($backupCodes)) { 153 $model->regenerateBackupCodes($this->user); 154 } 155 156 $backupCodesRecord = $model->getBackupCodesRecord($this->user); 157 158 if (!is_null($backupCodesRecord)) { 159 $this->methods = array_merge( 160 [ 161 'backupcodes' => new MethodDescriptor( 162 [ 163 'name' => 'backupcodes', 164 'display' => Text::_('COM_USERS_USER_BACKUPCODES'), 165 'shortinfo' => Text::_('COM_USERS_USER_BACKUPCODES_DESC'), 166 'image' => 'media/com_users/images/emergency.svg', 167 'canDisable' => false, 168 'active' => [$backupCodesRecord], 169 ] 170 ) 171 ], 172 $this->methods 173 ); 174 } 175 176 $this->isMandatoryMFASetup = $activeRecords === 0 && $app->getSession()->get('com_users.mandatory_mfa_setup', 0) === 1; 177 178 // Back-end: always show a title in the 'title' module position, not in the page body 179 if ($this->isAdmin) { 180 ToolbarHelper::title(Text::_('COM_USERS_MFA_LIST_PAGE_HEAD'), 'users user-lock'); 181 182 if (Factory::getApplication()->getIdentity()->authorise('core.manage', 'com_users')) { 183 ToolbarHelper::back('JTOOLBAR_BACK', Route::_('index.php?option=com_users')); 184 } 185 } 186 187 // Display the view 188 parent::display($tpl); 189 190 $event = new NotifyActionLog('onComUsersViewMethodsAfterDisplay', [$this]); 191 Factory::getApplication()->getDispatcher()->dispatch($event->getName(), $event); 192 193 Text::script('JGLOBAL_CONFIRM_DELETE'); 194 } 195 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |