PageRenderTime 36ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

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

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