PageRenderTime 49ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_login/models/login.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip
PHP | 157 lines | 84 code | 23 blank | 50 comment | 15 complexity | 090f8cf122c212fc6f122446ef62808d MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, JSON, GPL-2.0, BSD-3-Clause, LGPL-2.1, MIT
  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  4. * @license GNU General Public License, see LICENSE.php
  5. */
  6. defined('_JEXEC') or die;
  7. /**
  8. * Login Model
  9. *
  10. * @package Joomla.Administrator
  11. * @subpackage com_login
  12. * @since 1.5
  13. */
  14. class LoginModelLogin extends JModelLegacy
  15. {
  16. /**
  17. * Method to auto-populate the model state.
  18. *
  19. * Note. Calling getState in this method will result in recursion.
  20. *
  21. * @since 1.6
  22. */
  23. protected function populateState()
  24. {
  25. $credentials = array(
  26. 'username' => JRequest::getVar('username', '', 'method', 'username'),
  27. 'password' => JRequest::getVar('passwd', '', 'post', 'string', JREQUEST_ALLOWRAW)
  28. );
  29. $this->setState('credentials', $credentials);
  30. // check for return URL from the request first
  31. if ($return = JRequest::getVar('return', '', 'method', 'base64')) {
  32. $return = base64_decode($return);
  33. if (!JURI::isInternal($return)) {
  34. $return = '';
  35. }
  36. }
  37. // Set the return URL if empty.
  38. if (empty($return)) {
  39. $return = 'index.php';
  40. }
  41. $this->setState('return', $return);
  42. }
  43. /**
  44. * Get the administrator login module by name (real, eg 'login' or folder, eg 'mod_login')
  45. *
  46. * @param string $name The name of the module
  47. * @param string $title The title of the module, optional
  48. *
  49. * @return object The Module object
  50. *
  51. * @since 11.1
  52. */
  53. public static function getLoginModule($name = 'mod_login', $title = null)
  54. {
  55. $result = null;
  56. $modules = LoginModelLogin::_load($name);
  57. $total = count($modules);
  58. for ($i = 0; $i < $total; $i++)
  59. {
  60. // Match the title if we're looking for a specific instance of the module
  61. if (!$title || $modules[$i]->title == $title) {
  62. $result = $modules[$i];
  63. break; // Found it
  64. }
  65. }
  66. // If we didn't find it, and the name is mod_something, create a dummy object
  67. if (is_null($result) && substr($name, 0, 4) == 'mod_') {
  68. $result = new stdClass;
  69. $result->id = 0;
  70. $result->title = '';
  71. $result->module = $name;
  72. $result->position = '';
  73. $result->content = '';
  74. $result->showtitle = 0;
  75. $result->control = '';
  76. $result->params = '';
  77. $result->user = 0;
  78. }
  79. return $result;
  80. }
  81. /**
  82. * Load login modules.
  83. *
  84. * Note that we load regardless of state or access level since access
  85. * for public is the only thing that makes sense since users are not logged in
  86. * and the module lets them log in.
  87. * This is put in as a failsafe to avoid super user lock out caused by an unpublished
  88. * login module or by a module set to have a viewing access level that is not Public.
  89. *
  90. * @param string $name The name of the module
  91. *
  92. * @return array
  93. *
  94. * @since 11.1
  95. */
  96. protected static function _load($module)
  97. {
  98. static $clean;
  99. if (isset($clean)) {
  100. return $clean;
  101. }
  102. $app = JFactory::getApplication();
  103. $lang = JFactory::getLanguage()->getTag();
  104. $clientId = (int) $app->getClientId();
  105. $cache = JFactory::getCache ('com_modules', '');
  106. $cacheid = md5(serialize(array( $clientId, $lang)));
  107. $loginmodule = array();
  108. if (!($clean = $cache->get($cacheid))) {
  109. $db = JFactory::getDbo();
  110. $query = $db->getQuery(true);
  111. $query->select('m.id, m.title, m.module, m.position, m.showtitle, m.params');
  112. $query->from('#__modules AS m');
  113. $query->where('m.module =' . $db->Quote($module) .' AND m.client_id = 1');
  114. $query->join('LEFT', '#__extensions AS e ON e.element = m.module AND e.client_id = m.client_id');
  115. $query->where('e.enabled = 1');
  116. // Filter by language
  117. if ($app->isSite() && $app->getLanguageFilter()) {
  118. $query->where('m.language IN (' . $db->Quote($lang) . ',' . $db->Quote('*') . ')');
  119. }
  120. $query->order('m.position, m.ordering');
  121. // Set the query
  122. $db->setQuery($query);
  123. $modules = $db->loadObjectList();
  124. if ($db->getErrorNum()){
  125. JError::raiseWarning(500, JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $db->getErrorMsg()));
  126. return $loginmodule;
  127. }
  128. // Return to simple indexing that matches the query order.
  129. $loginmodule = $modules;
  130. $cache->store($loginmodule, $cacheid);
  131. }
  132. return $loginmodule;
  133. }
  134. }