PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_users/controllers/reset.php

https://github.com/prma85/joomla-cms
PHP | 225 lines | 130 code | 29 blank | 66 comment | 6 complexity | b85fb7379fc300b44d9e17fb5836da0b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, Apache-2.0
  1. <?php
  2. /**
  3. * @package Joomla.Site
  4. * @subpackage com_users
  5. *
  6. * @copyright Copyright (C) 2005 - 2014 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. {
  37. // Get the error message to display.
  38. if ($app->get('error_reporting'))
  39. {
  40. $message = $return->getMessage();
  41. }
  42. else
  43. {
  44. $message = JText::_('COM_USERS_RESET_REQUEST_ERROR');
  45. }
  46. // Get the route to the next page.
  47. $itemid = UsersHelperRoute::getResetRoute();
  48. $itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
  49. $route = 'index.php?option=com_users&view=reset' . $itemid;
  50. // Go back to the request form.
  51. $this->setRedirect(JRoute::_($route, false), $message, 'error');
  52. return false;
  53. }
  54. elseif ($return === false)
  55. {
  56. // The request failed.
  57. // Get the route to the next page.
  58. $itemid = UsersHelperRoute::getResetRoute();
  59. $itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
  60. $route = 'index.php?option=com_users&view=reset' . $itemid;
  61. // Go back to the request form.
  62. $message = JText::sprintf('COM_USERS_RESET_REQUEST_FAILED', $model->getError());
  63. $this->setRedirect(JRoute::_($route, false), $message, 'notice');
  64. return false;
  65. }
  66. else
  67. {
  68. // The request succeeded.
  69. // Get the route to the next page.
  70. $itemid = UsersHelperRoute::getResetRoute();
  71. $itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
  72. $route = 'index.php?option=com_users&view=reset&layout=confirm' . $itemid;
  73. // Proceed to step two.
  74. $this->setRedirect(JRoute::_($route, false));
  75. return true;
  76. }
  77. }
  78. /**
  79. * Method to confirm the password request.
  80. *
  81. * @access public
  82. * @since 1.6
  83. */
  84. public function confirm()
  85. {
  86. // Check the request token.
  87. JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
  88. $app = JFactory::getApplication();
  89. $model = $this->getModel('Reset', 'UsersModel');
  90. $data = $this->input->get('jform', array(), 'array');
  91. // Confirm the password reset request.
  92. $return = $model->processResetConfirm($data);
  93. // Check for a hard error.
  94. if ($return instanceof Exception)
  95. {
  96. // Get the error message to display.
  97. if ($app->get('error_reporting'))
  98. {
  99. $message = $return->getMessage();
  100. }
  101. else
  102. {
  103. $message = JText::_('COM_USERS_RESET_CONFIRM_ERROR');
  104. }
  105. // Get the route to the next page.
  106. $itemid = UsersHelperRoute::getResetRoute();
  107. $itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
  108. $route = 'index.php?option=com_users&view=reset&layout=confirm' . $itemid;
  109. // Go back to the confirm form.
  110. $this->setRedirect(JRoute::_($route, false), $message, 'error');
  111. return false;
  112. }
  113. elseif ($return === false)
  114. {
  115. // Confirm failed.
  116. // Get the route to the next page.
  117. $itemid = UsersHelperRoute::getResetRoute();
  118. $itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
  119. $route = 'index.php?option=com_users&view=reset&layout=confirm' . $itemid;
  120. // Go back to the confirm form.
  121. $message = JText::sprintf('COM_USERS_RESET_CONFIRM_FAILED', $model->getError());
  122. $this->setRedirect(JRoute::_($route, false), $message, 'notice');
  123. return false;
  124. }
  125. else
  126. {
  127. // Confirm succeeded.
  128. // Get the route to the next page.
  129. $itemid = UsersHelperRoute::getResetRoute();
  130. $itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
  131. $route = 'index.php?option=com_users&view=reset&layout=complete' . $itemid;
  132. // Proceed to step three.
  133. $this->setRedirect(JRoute::_($route, false));
  134. return true;
  135. }
  136. }
  137. /**
  138. * Method to complete the password reset process.
  139. *
  140. * @since 1.6
  141. */
  142. public function complete()
  143. {
  144. // Check for request forgeries
  145. JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN'));
  146. $app = JFactory::getApplication();
  147. $model = $this->getModel('Reset', 'UsersModel');
  148. $data = $this->input->post->get('jform', array(), 'array');
  149. // Complete the password reset request.
  150. $return = $model->processResetComplete($data);
  151. // Check for a hard error.
  152. if ($return instanceof Exception)
  153. {
  154. // Get the error message to display.
  155. if ($app->get('error_reporting'))
  156. {
  157. $message = $return->getMessage();
  158. }
  159. else
  160. {
  161. $message = JText::_('COM_USERS_RESET_COMPLETE_ERROR');
  162. }
  163. // Get the route to the next page.
  164. $itemid = UsersHelperRoute::getResetRoute();
  165. $itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
  166. $route = 'index.php?option=com_users&view=reset&layout=complete' . $itemid;
  167. // Go back to the complete form.
  168. $this->setRedirect(JRoute::_($route, false), $message, 'error');
  169. return false;
  170. }
  171. elseif ($return === false)
  172. {
  173. // Complete failed.
  174. // Get the route to the next page.
  175. $itemid = UsersHelperRoute::getResetRoute();
  176. $itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
  177. $route = 'index.php?option=com_users&view=reset&layout=complete' . $itemid;
  178. // Go back to the complete form.
  179. $message = JText::sprintf('COM_USERS_RESET_COMPLETE_FAILED', $model->getError());
  180. $this->setRedirect(JRoute::_($route, false), $message, 'notice');
  181. return false;
  182. }
  183. else
  184. {
  185. // Complete succeeded.
  186. // Get the route to the next page.
  187. $itemid = UsersHelperRoute::getLoginRoute();
  188. $itemid = $itemid !== null ? '&Itemid=' . $itemid : '';
  189. $route = 'index.php?option=com_users&view=login' . $itemid;
  190. // Proceed to the login form.
  191. $message = JText::_('COM_USERS_RESET_COMPLETE_SUCCESS');
  192. $this->setRedirect(JRoute::_($route, false), $message);
  193. return true;
  194. }
  195. }
  196. }