[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_login/src/Model/ -> LoginModel.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_login
   6   *
   7   * @copyright   (C) 2009 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\Login\Administrator\Model;
  12  
  13  use Joomla\CMS\Cache\Exception\CacheExceptionInterface;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\MVC\Model\BaseDatabaseModel;
  17  use Joomla\CMS\Uri\Uri;
  18  use Joomla\Database\Exception\ExecutionFailureException;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * Login Model
  26   *
  27   * @since  1.5
  28   */
  29  class LoginModel extends BaseDatabaseModel
  30  {
  31      /**
  32       * Method to auto-populate the model state.
  33       *
  34       * Note. Calling getState in this method will result in recursion.
  35       *
  36       * @return  void
  37       *
  38       * @since   1.6
  39       */
  40      protected function populateState()
  41      {
  42          $input = Factory::getApplication()->input->getInputForRequestMethod();
  43  
  44          $credentials = array(
  45              'username'  => $input->get('username', '', 'USERNAME'),
  46              'password'  => $input->get('passwd', '', 'RAW'),
  47              'secretkey' => $input->get('secretkey', '', 'RAW'),
  48          );
  49  
  50          $this->setState('credentials', $credentials);
  51  
  52          // Check for return URL from the request first.
  53          if ($return = $input->get('return', '', 'BASE64')) {
  54              $return = base64_decode($return);
  55  
  56              if (!Uri::isInternal($return)) {
  57                  $return = '';
  58              }
  59          }
  60  
  61          // Set the return URL if empty.
  62          if (empty($return)) {
  63              $return = 'index.php';
  64          }
  65  
  66          $this->setState('return', $return);
  67      }
  68  
  69      /**
  70       * Get the administrator login module by name (real, eg 'login' or folder, eg 'mod_login').
  71       *
  72       * @param   string  $name   The name of the module.
  73       * @param   string  $title  The title of the module, optional.
  74       *
  75       * @return  object  The Module object.
  76       *
  77       * @since   1.7.0
  78       */
  79      public static function getLoginModule($name = 'mod_login', $title = null)
  80      {
  81          $result = null;
  82          $modules = self::_load($name);
  83          $total = count($modules);
  84  
  85          for ($i = 0; $i < $total; $i++) {
  86              // Match the title if we're looking for a specific instance of the module.
  87              if (!$title || $modules[$i]->title == $title) {
  88                  $result = $modules[$i];
  89                  break;
  90              }
  91          }
  92  
  93          // If we didn't find it, and the name is mod_something, create a dummy object.
  94          if (is_null($result) && substr($name, 0, 4) == 'mod_') {
  95              $result = new \stdClass();
  96              $result->id = 0;
  97              $result->title = '';
  98              $result->module = $name;
  99              $result->position = '';
 100              $result->content = '';
 101              $result->showtitle = 0;
 102              $result->control = '';
 103              $result->params = '';
 104              $result->user = 0;
 105          }
 106  
 107          return $result;
 108      }
 109  
 110      /**
 111       * Load login modules.
 112       *
 113       * Note that we load regardless of state or access level since access
 114       * for public is the only thing that makes sense since users are not logged in
 115       * and the module lets them log in.
 116       * This is put in as a failsafe to avoid super user lock out caused by an unpublished
 117       * login module or by a module set to have a viewing access level that is not Public.
 118       *
 119       * @param   string  $module  The name of the module.
 120       *
 121       * @return  array
 122       *
 123       * @since   1.7.0
 124       */
 125      protected static function _load($module)
 126      {
 127          static $clean;
 128  
 129          if (isset($clean)) {
 130              return $clean;
 131          }
 132  
 133          $app      = Factory::getApplication();
 134          $lang     = Factory::getLanguage()->getTag();
 135          $clientId = (int) $app->getClientId();
 136  
 137          /** @var \Joomla\CMS\Cache\Controller\CallbackController $cache */
 138          $cache = Factory::getCache('com_modules', 'callback');
 139  
 140          $loader = function () use ($app, $lang, $module) {
 141              $db = Factory::getDbo();
 142  
 143              $query = $db->getQuery(true)
 144                  ->select(
 145                      $db->quoteName(
 146                          [
 147                              'm.id',
 148                              'm.title',
 149                              'm.module',
 150                              'm.position',
 151                              'm.showtitle',
 152                              'm.params'
 153                          ]
 154                      )
 155                  )
 156                  ->from($db->quoteName('#__modules', 'm'))
 157                  ->where($db->quoteName('m.module') . ' = :module')
 158                  ->where($db->quoteName('m.client_id') . ' = 1')
 159                  ->join(
 160                      'LEFT',
 161                      $db->quoteName('#__extensions', 'e'),
 162                      $db->quoteName('e.element') . ' = ' . $db->quoteName('m.module') .
 163                      ' AND ' . $db->quoteName('e.client_id') . ' = ' . $db->quoteName('m.client_id')
 164                  )
 165                  ->where($db->quoteName('e.enabled') . ' = 1')
 166                  ->bind(':module', $module);
 167  
 168              // Filter by language.
 169              if ($app->isClient('site') && $app->getLanguageFilter()) {
 170                  $query->whereIn($db->quoteName('m.language'), [$lang, '*']);
 171              }
 172  
 173              $query->order('m.position, m.ordering');
 174  
 175              // Set the query.
 176              $db->setQuery($query);
 177  
 178              return $db->loadObjectList();
 179          };
 180  
 181          try {
 182              return $clean = $cache->get($loader, array(), md5(serialize(array($clientId, $lang))));
 183          } catch (CacheExceptionInterface $cacheException) {
 184              try {
 185                  return $loader();
 186              } catch (ExecutionFailureException $databaseException) {
 187                  Factory::getApplication()->enqueueMessage(
 188                      Text::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $databaseException->getMessage()),
 189                      'error'
 190                  );
 191  
 192                  return array();
 193              }
 194          } catch (ExecutionFailureException $databaseException) {
 195              Factory::getApplication()->enqueueMessage(Text::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $databaseException->getMessage()), 'error');
 196  
 197              return array();
 198          }
 199      }
 200  }


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