- md5
- 4bcc7d6e4967130aff3d6291dee09324
- sha1
- 62d01c6a2e06aaf105d3cd0e96b3c49fa119b243
- sha256
- c65316bab4b820dbf92e498406d3e0ab6673142c734e9f7d48f1c7c321ed66cf
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
<?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\PluginTraits;
// Protect from unauthorized access
\defined('_JEXEC') or die();
use Exception;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\Plugin\System\Webauthn\CredentialRepository;
/**
* Ajax handler for akaction=savelabel
*
* Stores a new label for a security key
*
* @since 4.0.0
*/
trait AjaxHandlerSaveLabel
{
/**
* Handle the callback to rename an authenticator
*
* @return boolean
*
* @throws Exception
*
* @since 4.0.0
*/
public function onAjaxWebauthnSavelabel(): bool
{
// Initialize objects
/** @var CMSApplication $app */
$app = Factory::getApplication();
$input = $app->input;
$repository = new CredentialRepository;
// Retrieve data from the request
$credentialId = $input->getBase64('credential_id', '');
$newLabel = $input->getString('new_label', '');
// Is this a valid credential?
if (empty($credentialId))
{
return false;
}
$credentialId = base64_decode($credentialId);
if (empty($credentialId) || !$repository->has($credentialId))
{
return false;
}
// Make sure I am editing my own key
try
{
$credentialHandle = $repository->getUserHandleFor($credentialId);
$myHandle = $repository->getHandleFromUserId($app->getIdentity()->id);
}
catch (Exception $e)
{
return false;
}
if ($credentialHandle !== $myHandle)
{
return false;
}
// Make sure the new label is not empty
if (empty($newLabel))
{
return false;
}
// Save the new label
try
{
$repository->setLabel($credentialId, $newLabel);
}
catch (Exception $e)
{
return false;
}
return true;
}
}
The same content is in 51 releases, Joomla 4.0.0-beta6 to 4.2.0-beta2. See them all, or every version of this file.