[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_users/src/Controller/ -> CallbackController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_users
   6   *
   7   * @copyright   (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Users\Administrator\Controller;
  12  
  13  use Joomla\CMS\Application\CMSApplication;
  14  use Joomla\CMS\Event\MultiFactor\Callback;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\MVC\Controller\BaseController;
  17  use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
  18  use Joomla\CMS\Plugin\PluginHelper;
  19  use Joomla\Input\Input;
  20  use RuntimeException;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('_JEXEC') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * Multi-factor Authentication plugins' AJAX callback controller
  28   *
  29   * @since 4.2.0
  30   */
  31  class CallbackController extends BaseController
  32  {
  33      /**
  34       * Public constructor
  35       *
  36       * @param   array                     $config   Plugin configuration
  37       * @param   MVCFactoryInterface|null  $factory  MVC Factory for the com_users component
  38       * @param   CMSApplication|null       $app      CMS application object
  39       * @param   Input|null                $input    Joomla CMS input object
  40       *
  41       * @since 4.2.0
  42       */
  43      public function __construct(array $config = [], MVCFactoryInterface $factory = null, ?CMSApplication $app = null, ?Input $input = null)
  44      {
  45          parent::__construct($config, $factory, $app, $input);
  46  
  47          $this->registerDefaultTask('callback');
  48      }
  49  
  50      /**
  51       * Implement a callback feature, typically used for OAuth2 authentication
  52       *
  53       * @param   bool         $cachable    Can this view be cached
  54       * @param   array|bool   $urlparams   An array of safe url parameters and their variable types, for valid values see
  55       *                                    {@link JFilterInput::clean()}.
  56       *
  57       * @return  void
  58       * @since 4.2.0
  59       */
  60      public function callback($cachable = false, $urlparams = false): void
  61      {
  62          $app = $this->app;
  63  
  64          // Get the Method and make sure it's non-empty
  65          $method = $this->input->getCmd('method', '');
  66  
  67          if (empty($method)) {
  68              throw new RuntimeException(Text::_('JERROR_ALERTNOAUTHOR'), 403);
  69          }
  70  
  71          PluginHelper::importPlugin('multifactorauth');
  72  
  73          $event = new Callback($method);
  74          $this->app->getDispatcher()->dispatch($event->getName(), $event);
  75  
  76          /**
  77           * The first plugin to handle the request should either redirect or close the application. If we are still here
  78           * no plugin handled the request successfully. Show an error.
  79           */
  80          throw new RuntimeException(Text::_('JERROR_ALERTNOAUTHOR'), 403);
  81      }
  82  }


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