- md5
- 25db6d70ce86187234b2e06ede4c57fd
- sha1
- 7ee6d29212ea8ba970862adf85b1481b461bd5fc
- sha256
- f644174b3c5accc1c9e5113f0b13655862f4704a399a738a5cd598d1e3e0b842
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
<?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;
use Joomla\CMS\Event\Plugin\System\Webauthn\AjaxSaveLabel;
use Joomla\CMS\User\User;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* 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
*
* @param AjaxSaveLabel $event The event we are handling
*
* @return void
*
* @since 4.0.0
*/
public function onAjaxWebauthnSavelabel(AjaxSaveLabel $event): void
{
// Load plugin language files
$this->loadLanguage();
// Initialize objects
$input = $this->getApplication()->getInput();
$repository = $this->authenticationHelper->getCredentialsRepository();
// Retrieve data from the request
$credentialId = $input->getBase64('credential_id', '');
$newLabel = $input->getString('new_label', '');
// Is this a valid credential?
if (empty($credentialId)) {
$event->addResult(false);
return;
}
$credentialId = base64_decode($credentialId);
if (empty($credentialId) || !$repository->has($credentialId)) {
$event->addResult(false);
return;
}
// Make sure I am editing my own key
try {
$credentialHandle = $repository->getUserHandleFor($credentialId);
$user = $this->getApplication()->getIdentity() ?? new User();
$myHandle = $repository->getHandleFromUserId($user->id);
} catch (\Exception $e) {
$event->addResult(false);
return;
}
if ($credentialHandle !== $myHandle) {
$event->addResult(false);
return;
}
// Make sure the new label is not empty
if (empty($newLabel)) {
$event->addResult(false);
return;
}
// Save the new label
try {
$repository->setLabel($credentialId, $newLabel);
} catch (\Exception $e) {
$event->addResult(false);
return;
}
$event->addResult(true);
}
}
The same content is in 57 releases, Joomla 5.0.0-beta2 to 5.3.0-beta1. See them all, or every version of this file.