[ 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\Captive; 12 13 use Exception; 14 use Joomla\CMS\Event\MultiFactor\BeforeDisplayMethods; 15 use Joomla\CMS\Event\MultiFactor\NotifyActionLog; 16 use Joomla\CMS\Factory; 17 use Joomla\CMS\Language\Text; 18 use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; 19 use Joomla\CMS\Plugin\PluginHelper; 20 use Joomla\CMS\Toolbar\Button\BasicButton; 21 use Joomla\CMS\Toolbar\Toolbar; 22 use Joomla\CMS\Toolbar\ToolbarHelper; 23 use Joomla\CMS\User\UserFactoryInterface; 24 use Joomla\Component\Users\Administrator\Helper\Mfa as MfaHelper; 25 use Joomla\Component\Users\Administrator\Model\BackupcodesModel; 26 use Joomla\Component\Users\Administrator\Model\CaptiveModel; 27 use Joomla\Component\Users\Administrator\View\SiteTemplateTrait; 28 use stdClass; 29 30 // phpcs:disable PSR1.Files.SideEffects 31 \defined('_JEXEC') or die; 32 // phpcs:enable PSR1.Files.SideEffects 33 34 /** 35 * View for Multi-factor Authentication captive page 36 * 37 * @since 4.2.0 38 */ 39 class HtmlView extends BaseHtmlView 40 { 41 use SiteTemplateTrait; 42 43 /** 44 * The MFA Method records for the current user which correspond to enabled plugins 45 * 46 * @var array 47 * @since 4.2.0 48 */ 49 public $records = []; 50 51 /** 52 * The currently selected MFA Method record against which we'll be authenticating 53 * 54 * @var null|stdClass 55 * @since 4.2.0 56 */ 57 public $record = null; 58 59 /** 60 * The Captive MFA page's rendering options 61 * 62 * @var array|null 63 * @since 4.2.0 64 */ 65 public $renderOptions = null; 66 67 /** 68 * The title to display at the top of the page 69 * 70 * @var string 71 * @since 4.2.0 72 */ 73 public $title = ''; 74 75 /** 76 * Is this an administrator page? 77 * 78 * @var boolean 79 * @since 4.2.0 80 */ 81 public $isAdmin = false; 82 83 /** 84 * Does the currently selected Method allow authenticating against all of its records? 85 * 86 * @var boolean 87 * @since 4.2.0 88 */ 89 public $allowEntryBatching = false; 90 91 /** 92 * All enabled MFA Methods (plugins) 93 * 94 * @var array 95 * @since 4.2.0 96 */ 97 public $mfaMethods; 98 99 /** 100 * Execute and display a template script. 101 * 102 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 103 * 104 * @return void A string if successful, otherwise an Error object. 105 * 106 * @throws Exception 107 * @since 4.2.0 108 */ 109 public function display($tpl = null) 110 { 111 $this->setSiteTemplateStyle(); 112 113 $app = Factory::getApplication(); 114 $user = Factory::getApplication()->getIdentity() 115 ?: Factory::getContainer()->get(UserFactoryInterface::class)->loadUserById(0); 116 117 PluginHelper::importPlugin('multifactorauth'); 118 $event = new BeforeDisplayMethods($user); 119 $app->getDispatcher()->dispatch($event->getName(), $event); 120 121 /** @var CaptiveModel $model */ 122 $model = $this->getModel(); 123 124 // Load data from the model 125 $this->isAdmin = $app->isClient('administrator'); 126 $this->records = $this->get('records'); 127 $this->record = $this->get('record'); 128 $this->mfaMethods = MfaHelper::getMfaMethods(); 129 130 if (!empty($this->records)) { 131 /** @var BackupcodesModel $codesModel */ 132 $codesModel = $this->getModel('Backupcodes'); 133 $backupCodesRecord = $codesModel->getBackupCodesRecord(); 134 135 if (!is_null($backupCodesRecord)) { 136 $backupCodesRecord->title = Text::_('COM_USERS_USER_BACKUPCODES'); 137 $this->records[] = $backupCodesRecord; 138 } 139 } 140 141 // If we only have one record there's no point asking the user to select a MFA Method 142 if (empty($this->record) && !empty($this->records)) { 143 // Default to the first record 144 $this->record = reset($this->records); 145 146 // If we have multiple records try to make this record the default 147 if (count($this->records) > 1) { 148 foreach ($this->records as $record) { 149 if ($record->default) { 150 $this->record = $record; 151 152 break; 153 } 154 } 155 } 156 } 157 158 // Set the correct layout based on the availability of a MFA record 159 $this->setLayout('default'); 160 161 // If we have no record selected or explicitly asked to run the 'select' task use the correct layout 162 if (is_null($this->record) || ($model->getState('task') == 'select')) { 163 $this->setLayout('select'); 164 } 165 166 switch ($this->getLayout()) { 167 case 'select': 168 $this->allowEntryBatching = 1; 169 170 $event = new NotifyActionLog('onComUsersCaptiveShowSelect', []); 171 Factory::getApplication()->getDispatcher()->dispatch($event->getName(), $event); 172 break; 173 174 case 'default': 175 default: 176 $this->renderOptions = $model->loadCaptiveRenderOptions($this->record); 177 $this->allowEntryBatching = $this->renderOptions['allowEntryBatching'] ?? 0; 178 179 $event = new NotifyActionLog( 180 'onComUsersCaptiveShowCaptive', 181 [ 182 $this->escape($this->record->title), 183 ] 184 ); 185 Factory::getApplication()->getDispatcher()->dispatch($event->getName(), $event); 186 break; 187 } 188 189 // Which title should I use for the page? 190 $this->title = $this->get('PageTitle'); 191 192 // Back-end: always show a title in the 'title' module position, not in the page body 193 if ($this->isAdmin) { 194 ToolbarHelper::title(Text::_('COM_USERS_HEADING_MFA'), 'users user-lock'); 195 $this->title = ''; 196 } 197 198 if ($this->isAdmin && $this->getLayout() === 'default') { 199 $bar = Toolbar::getInstance(); 200 $button = (new BasicButton('user-mfa-submit')) 201 ->text($this->renderOptions['submit_text']) 202 ->icon($this->renderOptions['submit_icon']); 203 $bar->appendButton($button); 204 205 $button = (new BasicButton('user-mfa-logout')) 206 ->text('COM_USERS_MFA_LOGOUT') 207 ->buttonClass('btn btn-danger') 208 ->icon('icon icon-lock'); 209 $bar->appendButton($button); 210 211 if (count($this->records) > 1) { 212 $arrow = Factory::getApplication()->getLanguage()->isRtl() ? 'arrow-right' : 'arrow-left'; 213 $button = (new BasicButton('user-mfa-choose-another')) 214 ->text('COM_USERS_MFA_USE_DIFFERENT_METHOD') 215 ->icon('icon-' . $arrow); 216 $bar->appendButton($button); 217 } 218 } 219 220 // Display the view 221 parent::display($tpl); 222 } 223 }
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 |