[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  com_users
   6   *
   7   * @copyright   (C) 2010 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\Site\Model;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Form\Form;
  15  use Joomla\CMS\Language\Multilanguage;
  16  use Joomla\CMS\MVC\Model\FormModel;
  17  use Joomla\CMS\Uri\Uri;
  18  use Joomla\Database\ParameterType;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * Login model class for Users.
  26   *
  27   * @since  1.6
  28   */
  29  class LoginModel extends FormModel
  30  {
  31      /**
  32       * Method to get the login form.
  33       *
  34       * The base form is loaded from XML and then an event is fired
  35       * for users plugins to extend the form with extra fields.
  36       *
  37       * @param   array    $data      An optional array of data for the form to interrogate.
  38       * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
  39       *
  40       * @return  Form    A Form object on success, false on failure
  41       *
  42       * @since   1.6
  43       */
  44      public function getForm($data = array(), $loadData = true)
  45      {
  46          // Get the form.
  47          $form = $this->loadForm('com_users.login', 'login', array('load_data' => $loadData));
  48  
  49          if (empty($form)) {
  50              return false;
  51          }
  52  
  53          return $form;
  54      }
  55  
  56      /**
  57       * Method to get the data that should be injected in the form.
  58       *
  59       * @return  array  The default data is an empty array.
  60       *
  61       * @since   1.6
  62       * @throws  \Exception
  63       */
  64      protected function loadFormData()
  65      {
  66          // Check the session for previously entered login form data.
  67          $app  = Factory::getApplication();
  68          $data = $app->getUserState('users.login.form.data', array());
  69  
  70          $input = $app->input->getInputForRequestMethod();
  71  
  72          // Check for return URL from the request first
  73          if ($return = $input->get('return', '', 'BASE64')) {
  74              $data['return'] = base64_decode($return);
  75  
  76              if (!Uri::isInternal($data['return'])) {
  77                  $data['return'] = '';
  78              }
  79          }
  80  
  81          $app->setUserState('users.login.form.data', $data);
  82  
  83          $this->preprocessData('com_users.login', $data);
  84  
  85          return $data;
  86      }
  87  
  88      /**
  89       * Method to auto-populate the model state.
  90       *
  91       * Calling getState in this method will result in recursion.
  92       *
  93       * @return  void
  94       *
  95       * @since   1.6
  96       * @throws  \Exception
  97       */
  98      protected function populateState()
  99      {
 100          // Get the application object.
 101          $params = Factory::getApplication()->getParams('com_users');
 102  
 103          // Load the parameters.
 104          $this->setState('params', $params);
 105      }
 106  
 107      /**
 108       * Override Joomla\CMS\MVC\Model\AdminModel::preprocessForm to ensure the correct plugin group is loaded.
 109       *
 110       * @param   Form    $form   A Form object.
 111       * @param   mixed   $data   The data expected for the form.
 112       * @param   string  $group  The name of the plugin group to import (defaults to "content").
 113       *
 114       * @return  void
 115       *
 116       * @since   1.6
 117       * @throws  \Exception if there is an error in the form event.
 118       */
 119      protected function preprocessForm(Form $form, $data, $group = 'user')
 120      {
 121          parent::preprocessForm($form, $data, $group);
 122      }
 123  
 124      /**
 125       * Returns the language for the given menu id.
 126       *
 127       * @param  int  $id  The menu id
 128       *
 129       * @return string
 130       *
 131       * @since  4.2.0
 132       */
 133      public function getMenuLanguage(int $id): string
 134      {
 135          if (!Multilanguage::isEnabled()) {
 136              return '';
 137          }
 138  
 139          $db    = $this->getDatabase();
 140          $query = $db->getQuery(true)
 141              ->select($db->quoteName('language'))
 142              ->from($db->quoteName('#__menu'))
 143              ->where($db->quoteName('client_id') . ' = 0')
 144              ->where($db->quoteName('id') . ' = :id')
 145              ->bind(':id', $id, ParameterType::INTEGER);
 146  
 147          $db->setQuery($query);
 148  
 149          try {
 150              return $db->loadResult();
 151          } catch (\RuntimeException $e) {
 152              return '';
 153          }
 154      }
 155  }


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