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

/components/com_users/controllers/reset.php

https://github.com/joebushi/joomla
PHP | 214 lines | 121 code | 25 blank | 68 comment | 9 complexity | 9eebc0c230ddf3f79b00112aea5e74e7 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Site
  5. * @subpackage com_users
  6. * @copyright Copyright (C) 2005 - 2010 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. /**
  11. * Reset controller class for Users.
  12. *
  13. * @package Joomla.Site
  14. * @subpackage com_users
  15. * @version 1.0
  16. */
  17. class UsersControllerReset extends UsersController
  18. {
  19. /**
  20. * Method to request a password reset.
  21. *
  22. * @access public
  23. * @since 1.0
  24. */
  25. 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('User', '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. {
  37. // Get the error message to display.
  38. if ($app->getCfg('error_reporting')) {
  39. $message = $return->getMessage();
  40. } else {
  41. $message = JText::_('USERS_RESET_REQUEST_ERROR');
  42. }
  43. // Get the route to the next page.
  44. $itemid = UsersHelperRoute::getResetRoute();
  45. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  46. $route = 'index.php?option=com_users&view=reset'.$itemid;
  47. // Go back to the request form.
  48. $this->setRedirect(JRoute::_($route, false), $message, 'error');
  49. return false;
  50. }
  51. // The request failed.
  52. elseif ($return === false)
  53. {
  54. // Get the route to the next page.
  55. $itemid = UsersHelperRoute::getResetRoute();
  56. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  57. $route = 'index.php?option=com_users&view=reset'.$itemid;
  58. // Go back to the request form.
  59. $message = JText::sprintf('USERS_RESET_REQUEST_FAILED', $model->getError());
  60. $this->setRedirect(JRoute::_($route, false), $message, 'notice');
  61. return false;
  62. }
  63. // The request succeeded.
  64. else
  65. {
  66. // Get the route to the next page.
  67. $itemid = UsersHelperRoute::getResetRoute();
  68. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  69. $route = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid;
  70. // Proceed to step two.
  71. $message = JText::_('USERS_RESET_REQUEST_SUCCESS');
  72. $this->setRedirect(JRoute::_($route, false), $message);
  73. return true;
  74. }
  75. }
  76. /**
  77. * Method to confirm the password request.
  78. *
  79. * @access public
  80. * @since 1.0
  81. */
  82. function confirm()
  83. {
  84. // Check the request token.
  85. JRequest::checkToken('request') or jexit(JText::_('JInvalid_Token'));
  86. $app = &JFactory::getApplication();
  87. $model = &$this->getModel('User', 'UsersModel');
  88. $data = JRequest::getVar('jform', array(), 'request', 'array');
  89. // Confirm the password reset request.
  90. $return = $model->processResetConfirm($data);
  91. // Check for a hard error.
  92. if (JError::isError($return))
  93. {
  94. // Get the error message to display.
  95. if ($app->getCfg('error_reporting')) {
  96. $message = $return->getMessage();
  97. } else {
  98. $message = JText::_('USERS_RESET_CONFIRM_ERROR');
  99. }
  100. // Get the route to the next page.
  101. $itemid = UsersHelperRoute::getResetRoute();
  102. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  103. $route = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid;
  104. // Go back to the confirm form.
  105. $this->setRedirect(JRoute::_($route, false), $message, 'error');
  106. return false;
  107. }
  108. // Confirm failed.
  109. elseif ($return === false)
  110. {
  111. // Get the route to the next page.
  112. $itemid = UsersHelperRoute::getResetRoute();
  113. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  114. $route = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid;
  115. // Go back to the confirm form.
  116. $message = JText::sprintf('USERS_RESET_CONFIRM_FAILED', $model->getError());
  117. $this->setRedirect(JRoute::_($route, false), $message, 'notice');
  118. return false;
  119. }
  120. // Confirm succeeded.
  121. else
  122. {
  123. // Get the route to the next page.
  124. $itemid = UsersHelperRoute::getResetRoute();
  125. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  126. $route = 'index.php?option=com_users&view=reset&layout=complete'.$itemid;
  127. // Proceed to step three.
  128. $this->setRedirect(JRoute::_($route, false));
  129. return true;
  130. }
  131. }
  132. /**
  133. * Method to complete the password reset process.
  134. *
  135. * @access public
  136. * @since 1.0
  137. */
  138. function complete()
  139. {
  140. // Check for request forgeries
  141. JRequest::checkToken('post') or jexit(JText::_('JInvalid_Token'));
  142. $app = &JFactory::getApplication();
  143. $model = &$this->getModel('User', 'UsersModel');
  144. $data = JRequest::getVar('jform', array(), 'post', 'array');
  145. // Complete the password reset request.
  146. $return = $model->processResetComplete($data);
  147. // Check for a hard error.
  148. if (JError::isError($return))
  149. {
  150. // Get the error message to display.
  151. if ($app->getCfg('error_reporting')) {
  152. $message = $return->getMessage();
  153. } else {
  154. $message = JText::_('USERS_RESET_COMPLETE_ERROR');
  155. }
  156. // Get the route to the next page.
  157. $itemid = UsersHelperRoute::getResetRoute();
  158. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  159. $route = 'index.php?option=com_users&view=reset&layout=complete'.$itemid;
  160. // Go back to the complete form.
  161. $this->setRedirect(JRoute::_($route, false), $message, 'error');
  162. return false;
  163. }
  164. // Complete failed.
  165. elseif ($return === false)
  166. {
  167. // Get the route to the next page.
  168. $itemid = UsersHelperRoute::getResetRoute();
  169. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  170. $route = 'index.php?option=com_users&view=reset&layout=complete'.$itemid;
  171. // Go back to the complete form.
  172. $message = JText::sprintf('USERS_RESET_COMPLETE_FAILED', $model->getError());
  173. $this->setRedirect(JRoute::_($route, false), $message, 'notice');
  174. return false;
  175. }
  176. // Complete succeeded.
  177. else
  178. {
  179. // Get the route to the next page.
  180. $itemid = UsersHelperRoute::getLoginRoute();
  181. $itemid = $itemid !== null ? '&Itemid='.$itemid : '';
  182. $route = 'index.php?option=com_users&view=login'.$itemid;
  183. // Proceed to the login form.
  184. $message = JText::_('USERS_RESET_COMPLETE_SUCCESS');
  185. $this->setRedirect(JRoute::_($route, false), $message);
  186. return true;
  187. }
  188. }
  189. }