english/components/com_users/models/reset.php
/**
	 * Method to start the password reset process.
	 *
	 * @since	1.6
	 */
Method to start the password reset process.
Method to start the password reset process .
public function processResetRequest($data)
	{
		$config	= JFactory::getConfig();
		$form = $this->getForm();
		if (JError::isError($form)) {
			return $form;
		}
		$data	= $form->filter($data);
		$return	= $form->validate($data);
		if (JError::isError($return)) {
			return $return;
		}
		if ($return === false) {
			foreach ($form->getErrors() as $message) {
				$this->setError($message);
			}
			return false;
		}
		jimport('joomla.user.helper');
		$db	= $this->getDbo();
		$query	= $db->getQuery(true);
		$query->select('id');
		$query->from('`#__users`');
		$query->where('`email` = '.$db->Quote($data['email']));
		$db->setQuery((string) $query);
		$userId = $db->loadResult();
		if ($db->getErrorNum()) {
			$this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $db->getErrorMsg()), 500);
			return false;
		}
		if (empty($userId)) {
			$this->setError(JText::_('COM_USERS_INVALID_EMAIL'));
			return false;
		}
		$user = JUser::getInstance($userId);
		if ($user->block) {
			$this->setError(JText::_('COM_USERS_USER_BLOCKED'));
			return false;
		}
		if ($user->authorise('core.admin')) {
			$this->setError(JText::_('COM_USERS_REMIND_SUPERADMIN_ERROR'));
			return false;
		}
		$token = JUtility::getHash(JUserHelper::genRandomPassword());
		$salt = JUserHelper::getSalt('crypt-md5');
		$hashedToken = md5($token.$salt).':'.$salt;
		$user->activation = $hashedToken;
		if (!$user->save(true)) {
			return new JException(JText::sprintf('COM_USERS_USER_SAVE_FAILED', $user->getError()), 500);
		}
		$mode = $config->get('force_ssl', 0) == 2 ? 1 : -1;
		$itemid = UsersHelperRoute::getLoginRoute();
		$itemid = $itemid !== null ? '&Itemid='.$itemid : '';
		$link = 'index.php?option=com_users&view=reset&layout=confirm'.$itemid;
		$data = $user->getProperties();
		$data['fromname']	= $config->get('fromname');
		$data['mailfrom']	= $config->get('mailfrom');
		$data['sitename']	= $config->get('sitename');
		$data['link_text']	= JRoute::_($link, false, $mode);
		$data['link_html']	= JRoute::_($link, true, $mode);
		$data['token']		= $token;
		$subject = JText::sprintf(
			'COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT',
			$data['sitename']
		);
		$body = JText::sprintf(
			'COM_USERS_EMAIL_PASSWORD_RESET_BODY',
			$data['sitename'],
			$data['token'],
			$data['link_text']
		);
		$return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $user->email, $subject, $body);
		if ($return !== true) {
			return new JException(JText::_('COM_USERS_MAIL_FAILED'), 500);
		}
		return true;
	}
public function processResetRequest ( $ data ) { $ config = JFactory :: getConfig ( ) ; $ form = $ this -> getForm ( ) ; if ( JError :: isError ( $ form ) ) { return $ form ; } $ data = $ form -> filter ( $ data ) ; $ return = $ form -> validate ( $ data ) ; if ( JError :: isError ( $ return ) ) { return $ return ; } if ( $ return === false ) { foreach ( $ form -> getErrors ( ) as $ message ) { $ this -> setError ( $ message ) ; } return false ; } jimport ( 'joomla.user.helper' ) ; $ db = $ this -> getDbo ( ) ; $ query = $ db -> getQuery ( true ) ; $ query -> select ( 'id' ) ; $ query -> from ( '`#__users`' ) ; $ query -> where ( '`email` = ' . $ db -> Quote ( $ data [ 'email' ] ) ) ; $ db -> setQuery ( ( string ) $ query ) ; $ userId = $ db -> loadResult ( ) ; if ( $ db -> getErrorNum ( ) ) { $ this -> setError ( JText :: sprintf ( 'COM_USERS_DATABASE_ERROR' , $ db -> getErrorMsg ( ) ) , 500 ) ; return false ; } if ( empty ( $ userId ) ) { $ this -> setError ( JText :: _ ( 'COM_USERS_INVALID_EMAIL' ) ) ; return false ; } $ user = JUser :: getInstance ( $ userId ) ; if ( $ user -> block ) { $ this -> setError ( JText :: _ ( 'COM_USERS_USER_BLOCKED' ) ) ; return false ; } if ( $ user -> authorise ( 'core.admin' ) ) { $ this -> setError ( JText :: _ ( 'COM_USERS_REMIND_SUPERADMIN_ERROR' ) ) ; return false ; } $ token = JUtility :: getHash ( JUserHelper :: genRandomPassword ( ) ) ; $ salt = JUserHelper :: getSalt ( 'crypt-md5' ) ; $ hashedToken = md5 ( $ token . $ salt ) . ':' . $ salt ; $ user -> activation = $ hashedToken ; if ( ! $ user -> save ( true ) ) { return new JException ( JText :: sprintf ( 'COM_USERS_USER_SAVE_FAILED' , $ user -> getError ( ) ) , 500 ) ; } $ mode = $ config -> get ( 'force_ssl' , 0 ) == 2 ? 1 : - 1 ; $ itemid = UsersHelperRoute :: getLoginRoute ( ) ; $ itemid = $ itemid !== null ? '&Itemid=' . $ itemid : '' ; $ link = 'index.php?option=com_users&view=reset&layout=confirm' . $ itemid ; $ data = $ user -> getProperties ( ) ; $ data [ 'fromname' ] = $ config -> get ( 'fromname' ) ; $ data [ 'mailfrom' ] = $ config -> get ( 'mailfrom' ) ; $ data [ 'sitename' ] = $ config -> get ( 'sitename' ) ; $ data [ 'link_text' ] = JRoute :: _ ( $ link , false , $ mode ) ; $ data [ 'link_html' ] = JRoute :: _ ( $ link , true , $ mode ) ; $ data [ 'token' ] = $ token ; $ subject = JText :: sprintf ( 'COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT' , $ data [ 'sitename' ] ) ; $ body = JText :: sprintf ( 'COM_USERS_EMAIL_PASSWORD_RESET_BODY' , $ data [ 'sitename' ] , $ data [ 'token' ] , $ data [ 'link_text' ] ) ; $ return = JUtility :: sendMail ( $ data [ 'mailfrom' ] , $ data [ 'fromname' ] , $ user -> email , $ subject , $ body ) ; if ( $ return !== true ) { return new JException ( JText :: _ ( 'COM_USERS_MAIL_FAILED' ) , 500 ) ; } return true ; }
Method to start the password reset process.
Method to start the password reset process .
// Get the form. // Check for an error. // Filter and validate the form data. // Check for an error. // Check the validation results. // Get the validation messages from the form. // Find the user id for the given email address. // Get the user object. // Check for an error. // Check for a user. // Get the user object. // Make sure the user isn't blocked. // Make sure the user isn't a Super Admin. // Set the confirmation token. // Save the user to the database. // Assemble the password reset confirmation link. // Put together the email template data. // Send the password reset request email. // Check for an error.