/components/com_users/controllers/reset.php

https://bitbucket.org/eternaware/joomus · PHP · 199 lines · 107 code · 26 blank · 66 comment · 12 complexity · a39856eba28346dc22539c2512c07150 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Site
  4. * @subpackage com_users
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 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. * @since 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. JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
  29. $app = JFactory::getApplication();
  30. $model = $this->getModel('Reset', 'UsersModel');
  31. $data = $this->input->post->get('jform', array(), 'array');
  32. // Submit the password reset request.
  33. $return = $model->processResetRequest($data);
  34. // Check for a hard error.
  35. if ($return instanceof Exception) {
  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));
  67. return true;
  68. }
  69. }
  70. /**
  71. * Method to confirm the password request.
  72. *
  73. * @access public
  74. * @since 1.6
  75. */
  76. public function confirm()
  77. {
  78. // Check the request token.
  79. JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
  80. $app = JFactory::getApplication();
  81. $model = $this->getModel('Reset', 'UsersModel');
  82. $data = $this->input->get('jform', array(), 'array');
  83. // Confirm the password reset request.
  84. $return = $model->processResetConfirm($data);
  85. // Check for a hard error.
  86. if ($return instanceof Exception)
  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. JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
  131. $app = JFactory::getApplication();
  132. $model = $this->getModel('Reset', 'UsersModel');
  133. $data = $this->input->post->get('jform', array(), 'array');
  134. // Complete the password reset request.
  135. $return = $model->processResetComplete($data);
  136. // Check for a hard error.
  137. if ($return instanceof Exception) {
  138. // Get the error message to display.
  139. if ($app->getCfg('error_reporting')) {
  140. $message = $return->getMessage();
  141. } else {
  142. $message = JText::_('COM_USERS_RESET_COMPLETE_ERROR');
  143. }
  144. // Get the route to the next page.
  145. $itemid = UsersHelperRoute::getResetRoute();
  146. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  147. $route = 'index.php?option=com_users&view=reset&layout=complete'.$itemid;
  148. // Go back to the complete form.
  149. $this->setRedirect(JRoute::_($route, false), $message, 'error');
  150. return false;
  151. } elseif ($return === false) {
  152. // Complete failed.
  153. // Get the route to the next page.
  154. $itemid = UsersHelperRoute::getResetRoute();
  155. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  156. $route = 'index.php?option=com_users&view=reset&layout=complete'.$itemid;
  157. // Go back to the complete form.
  158. $message = JText::sprintf('COM_USERS_RESET_COMPLETE_FAILED', $model->getError());
  159. $this->setRedirect(JRoute::_($route, false), $message, 'notice');
  160. return false;
  161. } else {
  162. // Complete succeeded.
  163. // Get the route to the next page.
  164. $itemid = UsersHelperRoute::getLoginRoute();
  165. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  166. $route = 'index.php?option=com_users&view=login'.$itemid;
  167. // Proceed to the login form.
  168. $message = JText::_('COM_USERS_RESET_COMPLETE_SUCCESS');
  169. $this->setRedirect(JRoute::_($route, false), $message);
  170. return true;
  171. }
  172. }
  173. }