/components/com_users/src/Controller/ResetController.php

https://github.com/Hackwar/joomla-cms · PHP · 199 lines · 106 code · 29 blank · 64 comment · 6 complexity · d7797a5f95420c3a157dec13d6d013ca MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Site
  4. * @subpackage com_users
  5. *
  6. * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. namespace Joomla\Component\Users\Site\Controller;
  10. \defined('_JEXEC') or die;
  11. use Joomla\CMS\Language\Text;
  12. use Joomla\CMS\MVC\Controller\BaseController;
  13. use Joomla\CMS\Router\Route;
  14. /**
  15. * Reset controller class for Users.
  16. *
  17. * @since 1.6
  18. */
  19. class ResetController extends BaseController
  20. {
  21. /**
  22. * Method to request a password reset.
  23. *
  24. * @return boolean
  25. *
  26. * @since 1.6
  27. */
  28. public function request()
  29. {
  30. // Check the request token.
  31. $this->checkToken('post');
  32. $app = $this->app;
  33. /** @var \Joomla\Component\Users\Site\Model\ResetModel $model */
  34. $model = $this->getModel('Reset', 'Site');
  35. $data = $this->input->post->get('jform', array(), 'array');
  36. // Submit the password reset request.
  37. $return = $model->processResetRequest($data);
  38. // Check for a hard error.
  39. if ($return instanceof \Exception)
  40. {
  41. // Get the error message to display.
  42. if ($app->get('error_reporting'))
  43. {
  44. $message = $return->getMessage();
  45. }
  46. else
  47. {
  48. $message = Text::_('COM_USERS_RESET_REQUEST_ERROR');
  49. }
  50. // Go back to the request form.
  51. $this->setRedirect(Route::_('index.php?option=com_users&view=reset', false), $message, 'error');
  52. return false;
  53. }
  54. elseif ($return === false)
  55. {
  56. // The request failed.
  57. // Go back to the request form.
  58. $message = Text::sprintf('COM_USERS_RESET_REQUEST_FAILED', $model->getError());
  59. $this->setRedirect(Route::_('index.php?option=com_users&view=reset', false), $message, 'notice');
  60. return false;
  61. }
  62. else
  63. {
  64. // The request succeeded.
  65. // Proceed to step two.
  66. $this->setRedirect(Route::_('index.php?option=com_users&view=reset&layout=confirm', false));
  67. return true;
  68. }
  69. }
  70. /**
  71. * Method to confirm the password request.
  72. *
  73. * @return boolean
  74. *
  75. * @access public
  76. * @since 1.6
  77. */
  78. public function confirm()
  79. {
  80. // Check the request token.
  81. $this->checkToken('request');
  82. $app = $this->app;
  83. /** @var \Joomla\Component\Users\Site\Model\ResetModel $model */
  84. $model = $this->getModel('Reset', 'Site');
  85. $data = $this->input->get('jform', array(), 'array');
  86. // Confirm the password reset request.
  87. $return = $model->processResetConfirm($data);
  88. // Check for a hard error.
  89. if ($return instanceof \Exception)
  90. {
  91. // Get the error message to display.
  92. if ($app->get('error_reporting'))
  93. {
  94. $message = $return->getMessage();
  95. }
  96. else
  97. {
  98. $message = Text::_('COM_USERS_RESET_CONFIRM_ERROR');
  99. }
  100. // Go back to the confirm form.
  101. $this->setRedirect(Route::_('index.php?option=com_users&view=reset&layout=confirm', false), $message, 'error');
  102. return false;
  103. }
  104. elseif ($return === false)
  105. {
  106. // Confirm failed.
  107. // Go back to the confirm form.
  108. $message = Text::sprintf('COM_USERS_RESET_CONFIRM_FAILED', $model->getError());
  109. $this->setRedirect(Route::_('index.php?option=com_users&view=reset&layout=confirm', false), $message, 'notice');
  110. return false;
  111. }
  112. else
  113. {
  114. // Confirm succeeded.
  115. // Proceed to step three.
  116. $this->setRedirect(Route::_('index.php?option=com_users&view=reset&layout=complete', false));
  117. return true;
  118. }
  119. }
  120. /**
  121. * Method to complete the password reset process.
  122. *
  123. * @return boolean
  124. *
  125. * @since 1.6
  126. */
  127. public function complete()
  128. {
  129. // Check for request forgeries
  130. $this->checkToken('post');
  131. $app = $this->app;
  132. /** @var \Joomla\Component\Users\Site\Model\ResetModel $model */
  133. $model = $this->getModel('Reset', 'Site');
  134. $data = $this->input->post->get('jform', array(), 'array');
  135. // Complete the password reset request.
  136. $return = $model->processResetComplete($data);
  137. // Check for a hard error.
  138. if ($return instanceof \Exception)
  139. {
  140. // Get the error message to display.
  141. if ($app->get('error_reporting'))
  142. {
  143. $message = $return->getMessage();
  144. }
  145. else
  146. {
  147. $message = Text::_('COM_USERS_RESET_COMPLETE_ERROR');
  148. }
  149. // Go back to the complete form.
  150. $this->setRedirect(Route::_('index.php?option=com_users&view=reset&layout=complete', false), $message, 'error');
  151. return false;
  152. }
  153. elseif ($return === false)
  154. {
  155. // Complete failed.
  156. // Go back to the complete form.
  157. $message = Text::sprintf('COM_USERS_RESET_COMPLETE_FAILED', $model->getError());
  158. $this->setRedirect(Route::_('index.php?option=com_users&view=reset&layout=complete', false), $message, 'notice');
  159. return false;
  160. }
  161. else
  162. {
  163. // Complete succeeded.
  164. // Proceed to the login form.
  165. $message = Text::_('COM_USERS_RESET_COMPLETE_SUCCESS');
  166. $this->setRedirect(Route::_('index.php?option=com_users&view=login', false), $message);
  167. return true;
  168. }
  169. }
  170. }