PageRenderTime 59ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_users/controllers/reset.php

https://bitbucket.org/ian_maclennan/joomla-cms
PHP | 198 lines | 106 code | 26 blank | 66 comment | 12 complexity | be639ea1d3d9e383f2ac3693399e0d0a MD5 | raw file
Possible License(s): JSON, GPL-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Site
  5. * @subpackage com_users
  6. * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. require_once JPATH_COMPONENT.'/controller.php';
  11. /**
  12. * Reset controller class for Users.
  13. *
  14. * @package Joomla.Site
  15. * @subpackage com_users
  16. * @version 1.6
  17. */
  18. class UsersControllerReset extends UsersController
  19. {
  20. /**
  21. * Method to request a password reset.
  22. *
  23. * @since 1.6
  24. */
  25. public function request()
  26. {
  27. // Check the request token.
  28. JRequest::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
  29. $app = JFactory::getApplication();
  30. $model = $this->getModel('Reset', 'UsersModel');
  31. $data = JRequest::getVar('jform', array(), 'post', 'array');
  32. // Submit the password reset request.
  33. $return = $model->processResetRequest($data);
  34. // Check for a hard error.
  35. if (JError::isError($return)) {
  36. // Get the error message to display.
  37. if ($app->getCfg('error_reporting')) {
  38. $message = $return->getMessage();
  39. } else {
  40. $message = JText::_('COM_USERS_RESET_REQUEST_ERROR');
  41. }
  42. // Get the route to the next page.
  43. $itemid = UsersHelperRoute::getResetRoute();
  44. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  45. $route = 'index.php?option=com_users&view=reset'.$itemid;
  46. // Go back to the request form.
  47. $this->setRedirect(JRoute::_($route, false), $message, 'error');
  48. return false;
  49. } elseif ($return === false) {
  50. // The request failed.
  51. // Get the route to the next page.
  52. $itemid = UsersHelperRoute::getResetRoute();
  53. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  54. $route = 'index.php?option=com_users&view=reset'.$itemid;
  55. // Go back to the request form.
  56. $message = JText::sprintf('COM_USERS_RESET_REQUEST_FAILED', $model->getError());
  57. $this->setRedirect(JRoute::_($route, false), $message, 'notice');
  58. return false;
  59. } else {
  60. // The request succeeded.
  61. // Get the route to the next page.
  62. $itemid = UsersHelperRoute::getResetRoute();
  63. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  64. $route = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid;
  65. // Proceed to step two.
  66. $this->setRedirect(JRoute::_($route, false), $message);
  67. return true;
  68. }
  69. }
  70. /**
  71. * Method to confirm the password request.
  72. *
  73. * @access public
  74. * @since 1.0
  75. */
  76. function confirm()
  77. {
  78. // Check the request token.
  79. JRequest::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
  80. $app = JFactory::getApplication();
  81. $model = $this->getModel('Reset', 'UsersModel');
  82. $data = JRequest::getVar('jform', array(), 'request', 'array');
  83. // Confirm the password reset request.
  84. $return = $model->processResetConfirm($data);
  85. // Check for a hard error.
  86. if (JError::isError($return))
  87. {
  88. // Get the error message to display.
  89. if ($app->getCfg('error_reporting')) {
  90. $message = $return->getMessage();
  91. } else {
  92. $message = JText::_('COM_USERS_RESET_CONFIRM_ERROR');
  93. }
  94. // Get the route to the next page.
  95. $itemid = UsersHelperRoute::getResetRoute();
  96. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  97. $route = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid;
  98. // Go back to the confirm form.
  99. $this->setRedirect(JRoute::_($route, false), $message, 'error');
  100. return false;
  101. } elseif ($return === false) {
  102. // Confirm failed.
  103. // Get the route to the next page.
  104. $itemid = UsersHelperRoute::getResetRoute();
  105. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  106. $route = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid;
  107. // Go back to the confirm form.
  108. $message = JText::sprintf('COM_USERS_RESET_CONFIRM_FAILED', $model->getError());
  109. $this->setRedirect(JRoute::_($route, false), $message, 'notice');
  110. return false;
  111. } else {
  112. // Confirm succeeded.
  113. // Get the route to the next page.
  114. $itemid = UsersHelperRoute::getResetRoute();
  115. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  116. $route = 'index.php?option=com_users&view=reset&layout=complete'.$itemid;
  117. // Proceed to step three.
  118. $this->setRedirect(JRoute::_($route, false));
  119. return true;
  120. }
  121. }
  122. /**
  123. * Method to complete the password reset process.
  124. *
  125. * @since 1.6
  126. */
  127. public function complete()
  128. {
  129. // Check for request forgeries
  130. JRequest::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
  131. $app = JFactory::getApplication();
  132. $model = $this->getModel('Reset', 'UsersModel'); $data = JRequest::getVar('jform', array(), 'post', 'array');
  133. // Complete the password reset request.
  134. $return = $model->processResetComplete($data);
  135. // Check for a hard error.
  136. if (JError::isError($return)) {
  137. // Get the error message to display.
  138. if ($app->getCfg('error_reporting')) {
  139. $message = $return->getMessage();
  140. } else {
  141. $message = JText::_('COM_USERS_RESET_COMPLETE_ERROR');
  142. }
  143. // Get the route to the next page.
  144. $itemid = UsersHelperRoute::getResetRoute();
  145. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  146. $route = 'index.php?option=com_users&view=reset&layout=complete'.$itemid;
  147. // Go back to the complete form.
  148. $this->setRedirect(JRoute::_($route, false), $message, 'error');
  149. return false;
  150. } elseif ($return === false) {
  151. // Complete failed.
  152. // Get the route to the next page.
  153. $itemid = UsersHelperRoute::getResetRoute();
  154. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  155. $route = 'index.php?option=com_users&view=reset&layout=complete'.$itemid;
  156. // Go back to the complete form.
  157. $message = JText::sprintf('COM_USERS_RESET_COMPLETE_FAILED', $model->getError());
  158. $this->setRedirect(JRoute::_($route, false), $message, 'notice');
  159. return false;
  160. } else {
  161. // Complete succeeded.
  162. // Get the route to the next page.
  163. $itemid = UsersHelperRoute::getLoginRoute();
  164. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  165. $route = 'index.php?option=com_users&view=login'.$itemid;
  166. // Proceed to the login form.
  167. $message = JText::_('COM_USERS_RESET_COMPLETE_SUCCESS');
  168. $this->setRedirect(JRoute::_($route, false), $message);
  169. return true;
  170. }
  171. }
  172. }