CoreFiles by mySites.guru
WebauthnField.php83 lines, 2,754 bytes, from Joomla_4.4.13-Stable-Full_Package.zip
Raw History Compare with 4.4.12
md5
b649c3ecac707a9c9a01a02d4b3a53f0
sha1
7af1ef4b685bb5f8c94ffce260db013207b8794a
sha256
adc760d577f0575d34512f4ac117d21777e561bab9bbc43b78686b3eb2dafefe
<?php

/**
 * @package     Joomla.Plugin
 * @subpackage  System.Webauthn
 *
 * @copyright   (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Plugin\System\Webauthn\Field;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Plugin\System\Webauthn\Extension\Webauthn;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Custom Joomla Form Field to display the WebAuthn interface
 *
 * @since 4.0.0
 */
class WebauthnField extends FormField
{
    /**
     * Element name
     *
     * @var    string
     *
     * @since  4.0.0
     */
    protected $type = 'Webauthn';

    /**
     * Returns the input field's HTML
     *
     * @return  string
     * @throws  \Exception
     *
     * @since   4.0.0
     */
    public function getInput()
    {
        $userId = $this->form->getData()->get('id', null);

        if (\is_null($userId)) {
            return Text::_('PLG_SYSTEM_WEBAUTHN_ERR_NOUSER');
        }

        Text::script('PLG_SYSTEM_WEBAUTHN_ERR_NO_BROWSER_SUPPORT', true);
        Text::script('PLG_SYSTEM_WEBAUTHN_MANAGE_BTN_SAVE_LABEL', true);
        Text::script('PLG_SYSTEM_WEBAUTHN_MANAGE_BTN_CANCEL_LABEL', true);
        Text::script('PLG_SYSTEM_WEBAUTHN_MSG_SAVED_LABEL', true);
        Text::script('PLG_SYSTEM_WEBAUTHN_ERR_LABEL_NOT_SAVED', true);
        Text::script('PLG_SYSTEM_WEBAUTHN_ERR_XHR_INITCREATE', true);
        Text::script('PLG_SYSTEM_WEBAUTHN_ERR_NOT_DELETED', true);

        $app                  = Factory::getApplication();
        /** @var Webauthn $plugin */
        $plugin               = $app->bootPlugin('webauthn', 'system');

        $app->getDocument()->getWebAssetManager()
            ->registerAndUseScript('plg_system_webauthn.management', 'plg_system_webauthn/management.js', [], ['defer' => true], ['core']);

        $layoutFile  = new FileLayout('plugins.system.webauthn.manage');

        return $layoutFile->render([
                'user' => Factory::getContainer()
                    ->get(UserFactoryInterface::class)
                    ->loadUserById($userId),
                'allow_add'           => $userId == $app->getIdentity()->id,
                'credentials'         => $plugin->getAuthenticationHelper()->getCredentialsRepository()->getAll($userId),
                'knownAuthenticators' => $plugin->getAuthenticationHelper()->getKnownAuthenticators(),
                'attestationSupport'  => $plugin->getAuthenticationHelper()->hasAttestationSupport(),
            ]);
    }
}

The same content is in 180 releases, Joomla 4.4.0-beta3 to 6.2.1-rc1. See them all, or every version of this file.