[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/layouts/plugins/system/webauthn/ -> manage.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  System.webauthn
   6   *
   7   * @copyright   (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  defined('_JEXEC') or die;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\HTML\HTMLHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\Layout\FileLayout;
  17  use Joomla\CMS\User\User;
  18  use Webauthn\PublicKeyCredentialSource;
  19  
  20  /**
  21   * Passwordless Login management interface
  22   *
  23   * Generic data
  24   *
  25   * @var   FileLayout $this        The Joomla layout renderer
  26   * @var   array      $displayData The data in array format. DO NOT USE.
  27   *
  28   * Layout specific data
  29   *
  30   * @var   User       $user                The Joomla user whose passwordless login we are managing
  31   * @var   bool       $allow_add           Are we allowed to add passwordless login methods
  32   * @var   array      $credentials         The already stored credentials for the user
  33   * @var   string     $error               Any error messages
  34   * @var   array      $knownAuthenticators Known authenticator metadata
  35   * @var   boolean    $attestationSupport  Is authenticator attestation supported in the plugin?
  36   */
  37  
  38  // Extract the data. Do not remove until the unset() line.
  39  try {
  40      $app          = Factory::getApplication();
  41      $loggedInUser = $app->getIdentity();
  42  
  43      $app->getDocument()->getWebAssetManager()
  44          ->registerAndUseStyle('plg_system_webauthn.backend', 'plg_system_webauthn/backend.css');
  45  } catch (Exception $e) {
  46      $loggedInUser = new User();
  47  }
  48  
  49  $defaultDisplayData = [
  50          'user'                => $loggedInUser,
  51          'allow_add'           => false,
  52          'credentials'         => [],
  53          'error'               => '',
  54          'knownAuthenticators' => [],
  55          'attestationSupport'  => true,
  56  ];
  57  extract(array_merge($defaultDisplayData, $displayData));
  58  
  59  if ($displayData['allow_add'] === false) {
  60      $error = Text::_('PLG_SYSTEM_WEBAUTHN_CANNOT_ADD_FOR_A_USER');
  61      $allow_add = false;
  62  }
  63  
  64  // Ensure the GMP or BCmath extension is loaded in PHP - as this is required by third party library
  65  if ($allow_add && function_exists('gmp_intval') === false && function_exists('bccomp') === false) {
  66      $error = Text::_('PLG_SYSTEM_WEBAUTHN_REQUIRES_GMP');
  67      $allow_add = false;
  68  }
  69  
  70  Text::script('JGLOBAL_CONFIRM_DELETE');
  71  
  72  HTMLHelper::_('bootstrap.tooltip', '.plg_system_webauth-has-tooltip');
  73  ?>
  74  <div class="plg_system_webauthn" id="plg_system_webauthn-management-interface">
  75      <?php
  76      if (is_string($error) && !empty($error)) : ?>
  77          <div class="alert alert-danger">
  78              <?php echo htmlentities($error) ?>
  79          </div>
  80      <?php endif; ?>
  81  
  82      <table class="table table-striped">
  83          <caption class="visually-hidden">
  84              <?php echo Text::_('PLG_SYSTEM_WEBAUTHN_TABLE_CAPTION'); ?>,
  85          </caption>
  86          <thead class="table-dark">
  87          <tr>
  88              <th <?php if ($attestationSupport) :
  89                  ?>colspan="2"<?php
  90                  endif; ?> scope="col">
  91                  <?php echo Text::_('PLG_SYSTEM_WEBAUTHN_MANAGE_FIELD_KEYLABEL_LABEL') ?>
  92              </th>
  93              <th scope="col"><?php echo Text::_('PLG_SYSTEM_WEBAUTHN_MANAGE_HEADER_ACTIONS_LABEL') ?></th>
  94          </tr>
  95          </thead>
  96          <tbody>
  97          <?php
  98          foreach ($credentials as $method) : ?>
  99              <tr data-credential_id="<?php echo $method['id'] ?>">
 100                  <?php
 101                  if ($attestationSupport) :
 102                      $aaguid = ($method['credential'] instanceof PublicKeyCredentialSource) ? $method['credential']->getAaguid() : '';
 103                      $authMetadata = $knownAuthenticators[$aaguid->toString()] ?? $knownAuthenticators[''];
 104                      ?>
 105                  <td class="text-center">
 106                      <img class="plg_system_webauth-has-tooltip bg-secondary"
 107                           style="max-width: 6em; max-height: 3em"
 108                           src="<?php echo $authMetadata->icon ?>"
 109                           alt="<?php echo $authMetadata->description ?>"
 110                           title="<?php echo $authMetadata->description ?>">
 111                  </td>
 112                  <?php endif; ?>
 113                  <th scope="row" class="webauthnManagementCell"><?php echo htmlentities($method['label']) ?></th>
 114                  <td class="webauthnManagementCell">
 115                      <button class="plg_system_webauthn-manage-edit btn btn-secondary">
 116                          <span class="icon-edit" aria-hidden="true"></span>
 117                          <?php echo Text::_('PLG_SYSTEM_WEBAUTHN_MANAGE_BTN_EDIT_LABEL') ?>
 118                      </button>
 119                      <button class="plg_system_webauthn-manage-delete btn btn-danger">
 120                          <span class="icon-minus" aria-hidden="true"></span>
 121                          <?php echo Text::_('PLG_SYSTEM_WEBAUTHN_MANAGE_BTN_DELETE_LABEL') ?>
 122                      </button>
 123                  </td>
 124              </tr>
 125          <?php endforeach; ?>
 126          <?php
 127          if (empty($credentials)) : ?>
 128              <tr>
 129                  <td colspan="<?php echo $attestationSupport ? '3' : '2'; ?>">
 130                      <?php echo Text::_('PLG_SYSTEM_WEBAUTHN_MANAGE_HEADER_NOMETHODS_LABEL') ?>
 131                  </td>
 132              </tr>
 133          <?php endif; ?>
 134          </tbody>
 135      </table>
 136  
 137      <?php
 138      if ($allow_add) : ?>
 139          <p class="plg_system_webauthn-manage-add-container">
 140              <button
 141                  type="button"
 142                  id="plg_system_webauthn-manage-add"
 143                  class="btn btn-success w-100">
 144                  <span class="icon-plus" aria-hidden="true"></span>
 145                  <?php echo Text::_('PLG_SYSTEM_WEBAUTHN_MANAGE_BTN_ADD_LABEL') ?>
 146              </button>
 147          </p>
 148      <?php endif; ?>
 149  </div>


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer