- md5
- 9e153b5f8e73441e345eaf96f7efba08
- sha1
- c45ee0e641481cc8d18b7fe6d0469306dd6adb70
- sha256
- 8685c51a93d388c001cd6745854e3d2d3153b183c16a048881c755442dac1bc4
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
<?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\Factory;
use Joomla\CMS\Log\Log;
use Joomla\Database\DatabaseInterface;
use Joomla\Event\Event;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Delete all WebAuthn credentials for a particular user
*
* @since 4.0.0
*/
trait UserDeletion
{
/**
* Remove all passwordless credential information for the given user ID.
*
* This method is called after user data is deleted from the database.
*
* @param Event $event The event we are handling
*
* @return void
*
* @since 4.0.0
*/
public function onUserAfterDelete(Event $event): void
{
/**
* @var array $user Holds the user data
* @var bool $success True if user was successfully stored in the database
* @var string|null $msg Message
*/
[$user, $success, $msg] = array_values($event->getArguments());
if (!$success) {
$this->returnFromEvent($event, true);
}
$userId = ArrayHelper::getValue($user, 'id', 0, 'int');
if ($userId) {
Log::add("Removing WebAuthn Passwordless Login information for deleted user #{$userId}", Log::DEBUG, 'webauthn.system');
/** @var DatabaseInterface $db */
$db = Factory::getContainer()->get(DatabaseInterface::class);
$query = $db->getQuery(true)
->delete($db->quoteName('#__webauthn_credentials'))
->where($db->quoteName('user_id') . ' = :userId')
->bind(':userId', $userId);
try {
$db->setQuery($query)->execute();
} catch (\Exception $e) {
// Don't worry if this fails
}
$this->returnFromEvent($event, true);
}
}
}
The same content is in 92 releases, Joomla 4.4.0-beta1 to 5.3.0-beta1. See them all, or every version of this file.