/components/com_users/controllers/reset.php
PHP | 199 lines | 107 code | 26 blank | 66 comment | 12 complexity | a39856eba28346dc22539c2512c07150 MD5 | raw file
Possible License(s): LGPL-2.1
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 10defined('_JEXEC') or die; 11 12require_once JPATH_COMPONENT.'/controller.php'; 13 14/** 15 * Reset controller class for Users. 16 * 17 * @package Joomla.Site 18 * @subpackage com_users 19 * @since 1.6 20 */ 21class UsersControllerReset extends UsersController 22{ 23 /** 24 * Method to request a password reset. 25 * 26 * @since 1.6 27 */ 28 public function request() 29 { 30 // Check the request token. 31 JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN')); 32 33 $app = JFactory::getApplication(); 34 $model = $this->getModel('Reset', 'UsersModel'); 35 $data = $this->input->post->get('jform', array(), 'array'); 36 37 // Submit the password reset request. 38 $return = $model->processResetRequest($data); 39 40 // Check for a hard error. 41 if ($return instanceof Exception) { 42 // Get the error message to display. 43 if ($app->getCfg('error_reporting')) { 44 $message = $return->getMessage(); 45 } else { 46 $message = JText::_('COM_USERS_RESET_REQUEST_ERROR'); 47 } 48 49 // Get the route to the next page. 50 $itemid = UsersHelperRoute::getResetRoute(); 51 $itemid = $itemid !== null ? '&Itemid='.$itemid : ''; 52 $route = 'index.php?option=com_users&view=reset'.$itemid; 53 54 // Go back to the request form. 55 $this->setRedirect(JRoute::_($route, false), $message, 'error'); 56 return false; 57 } elseif ($return === false) { 58 // The request failed. 59 // Get the route to the next page. 60 $itemid = UsersHelperRoute::getResetRoute(); 61 $itemid = $itemid !== null ? '&Itemid='.$itemid : ''; 62 $route = 'index.php?option=com_users&view=reset'.$itemid; 63 64 // Go back to the request form. 65 $message = JText::sprintf('COM_USERS_RESET_REQUEST_FAILED', $model->getError()); 66 $this->setRedirect(JRoute::_($route, false), $message, 'notice'); 67 return false; 68 } else { 69 // The request succeeded. 70 // Get the route to the next page. 71 $itemid = UsersHelperRoute::getResetRoute(); 72 $itemid = $itemid !== null ? '&Itemid='.$itemid : ''; 73 $route = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid; 74 75 // Proceed to step two. 76 $this->setRedirect(JRoute::_($route, false)); 77 return true; 78 } 79 } 80 81 /** 82 * Method to confirm the password request. 83 * 84 * @access public 85 * @since 1.6 86 */ 87 public function confirm() 88 { 89 // Check the request token. 90 JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN')); 91 92 $app = JFactory::getApplication(); 93 $model = $this->getModel('Reset', 'UsersModel'); 94 $data = $this->input->get('jform', array(), 'array'); 95 96 // Confirm the password reset request. 97 $return = $model->processResetConfirm($data); 98 99 // Check for a hard error. 100 if ($return instanceof Exception) 101 { 102 // Get the error message to display. 103 if ($app->getCfg('error_reporting')) { 104 $message = $return->getMessage(); 105 } else { 106 $message = JText::_('COM_USERS_RESET_CONFIRM_ERROR'); 107 } 108 109 // Get the route to the next page. 110 $itemid = UsersHelperRoute::getResetRoute(); 111 $itemid = $itemid !== null ? '&Itemid='.$itemid : ''; 112 $route = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid; 113 114 // Go back to the confirm form. 115 $this->setRedirect(JRoute::_($route, false), $message, 'error'); 116 return false; 117 } elseif ($return === false) { 118 // Confirm failed. 119 // Get the route to the next page. 120 $itemid = UsersHelperRoute::getResetRoute(); 121 $itemid = $itemid !== null ? '&Itemid='.$itemid : ''; 122 $route = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid; 123 124 // Go back to the confirm form. 125 $message = JText::sprintf('COM_USERS_RESET_CONFIRM_FAILED', $model->getError()); 126 $this->setRedirect(JRoute::_($route, false), $message, 'notice'); 127 return false; 128 } else { 129 // Confirm succeeded. 130 // Get the route to the next page. 131 $itemid = UsersHelperRoute::getResetRoute(); 132 $itemid = $itemid !== null ? '&Itemid='.$itemid : ''; 133 $route = 'index.php?option=com_users&view=reset&layout=complete'.$itemid; 134 135 // Proceed to step three. 136 $this->setRedirect(JRoute::_($route, false)); 137 return true; 138 } 139 } 140 141 /** 142 * Method to complete the password reset process. 143 * 144 * @since 1.6 145 */ 146 public function complete() 147 { 148 // Check for request forgeries 149 JSession::checkToken('post') or jexit(JText::_('JINVALID_TOKEN')); 150 151 $app = JFactory::getApplication(); 152 $model = $this->getModel('Reset', 'UsersModel'); 153 $data = $this->input->post->get('jform', array(), 'array'); 154 155 // Complete the password reset request. 156 $return = $model->processResetComplete($data); 157 158 // Check for a hard error. 159 if ($return instanceof Exception) { 160 // Get the error message to display. 161 if ($app->getCfg('error_reporting')) { 162 $message = $return->getMessage(); 163 } else { 164 $message = JText::_('COM_USERS_RESET_COMPLETE_ERROR'); 165 } 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 172 // Go back to the complete form. 173 $this->setRedirect(JRoute::_($route, false), $message, 'error'); 174 return false; 175 } elseif ($return === false) { 176 // Complete failed. 177 // Get the route to the next page. 178 $itemid = UsersHelperRoute::getResetRoute(); 179 $itemid = $itemid !== null ? '&Itemid='.$itemid : ''; 180 $route = 'index.php?option=com_users&view=reset&layout=complete'.$itemid; 181 182 // Go back to the complete form. 183 $message = JText::sprintf('COM_USERS_RESET_COMPLETE_FAILED', $model->getError()); 184 $this->setRedirect(JRoute::_($route, false), $message, 'notice'); 185 return false; 186 } else { 187 // Complete succeeded. 188 // Get the route to the next page. 189 $itemid = UsersHelperRoute::getLoginRoute(); 190 $itemid = $itemid !== null ? '&Itemid='.$itemid : ''; 191 $route = 'index.php?option=com_users&view=login'.$itemid; 192 193 // Proceed to the login form. 194 $message = JText::_('COM_USERS_RESET_COMPLETE_SUCCESS'); 195 $this->setRedirect(JRoute::_($route, false), $message); 196 return true; 197 } 198 } 199}