Source for file reset.php
Documentation is available at reset.php
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Rest model class for Users.
* Method to get the password reset request form.
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return JForm A JForm object on success, false on failure
public function getForm($data =
array(), $loadData =
true)
$form =
$this->loadForm('com_users.reset_request', 'reset_request', array('control' =>
'jform', 'load_data' =>
$loadData));
* Method to get the password reset complete form.
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return JForm A JForm object on success, false on failure
$form =
$this->loadForm('com_users.reset_complete', 'reset_complete', $options =
array('control' =>
'jform'));
* Method to get the password reset confirm form.
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return JForm A JForm object on success, false on failure
$form =
$this->loadForm('com_users.reset_confirm', 'reset_confirm', $options =
array('control' =>
'jform'));
* Override preprocessForm to load the user plugin group instead of content.
* @param object A form object.
* @param mixed The data expected for the form.
* @throws Exception if there is an error in the form event.
protected function preprocessForm(JForm $form, $data, $group =
'user')
* Method to auto-populate the model state.
* Note. Calling getState in this method will result in recursion.
// Get the application object.
if ($form instanceof
Exception)
// Filter and validate the form data.
$data =
$form->filter($data);
$return =
$form->validate($data);
if ($return instanceof
Exception)
// Check the validation results.
// Get the validation messages from the form.
foreach ($form->getErrors() as $formError)
$this->setError($formError->getMessage());
// Get the token and user id from the confirmation process.
$token =
$app->getUserState('com_users.reset.token', null);
$userId =
$app->getUserState('com_users.reset.user', null);
// Check the token and user id.
if (empty($token) ||
empty($userId))
return new JException(JText::_('COM_USERS_RESET_COMPLETE_TOKENS_MISSING'), 403);
// Check for a user and that the tokens match.
if (empty($user) ||
$user->activation !==
$token)
// Make sure the user isn't blocked.
// Generate the new password hash.
$password =
$crypted .
':' .
$salt;
// Update the user object.
$user->password =
$password;
$user->password_clear =
$data['password1'];
// Save the user to the database.
// Flush the user data from the session.
$app->setUserState('com_users.reset.token', null);
$app->setUserState('com_users.reset.user', null);
if ($form instanceof
Exception)
// Filter and validate the form data.
$data =
$form->filter($data);
$return =
$form->validate($data);
if ($return instanceof
Exception)
// Check the validation results.
// Get the validation messages from the form.
foreach ($form->getErrors() as $formError)
$this->setError($formError->getMessage());
// Find the user id for the given token.
$query =
$db->getQuery(true)
->from($db->quoteName('#__users'))
->where($db->quoteName('username') .
' = ' .
$db->quote($data['username']));
$user =
$db->loadObject();
catch
(RuntimeException $e)
$parts =
explode(':', $user->activation);
if (!($crypt ==
$testcrypt))
// Make sure the user isn't blocked.
// Push the user data into the session.
$app->setUserState('com_users.reset.token', $crypt .
':' .
$salt);
$app->setUserState('com_users.reset.user', $user->id);
* Method to start the password reset process.
if ($form instanceof
Exception)
// Filter and validate the form data.
$data =
$form->filter($data);
$return =
$form->validate($data);
if ($return instanceof
Exception)
// Check the validation results.
// Get the validation messages from the form.
foreach ($form->getErrors() as $formError)
$this->setError($formError->getMessage());
// Find the user id for the given email address.
$query =
$db->getQuery(true)
->from($db->quoteName('#__users'))
->where($db->quoteName('email') .
' = ' .
$db->quote($data['email']));
$userId =
$db->loadResult();
catch
(RuntimeException $e)
// Make sure the user isn't blocked.
// Make sure the user isn't a Super Admin.
if ($user->authorise('core.admin'))
// Make sure the user has not exceeded the reset limit
// Set the confirmation token.
$hashedToken =
md5($token .
$salt) .
':' .
$salt;
$user->activation =
$hashedToken;
// Save the user to the database.
// Assemble the password reset confirmation link.
$mode =
$config->get('force_ssl', 0) ==
2 ?
1 : -
1;
$itemid =
$itemid !==
null ?
'&Itemid=' .
$itemid :
'';
$link =
'index.php?option=com_users&view=reset&layout=confirm' .
$itemid;
// Put together the email template data.
$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);
'COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT',
'COM_USERS_EMAIL_PASSWORD_RESET_BODY',
// Send the password reset request email.
$return =
JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $user->email, $subject, $body);
* Method to check if user reset limit has been exceeded within the allowed time period.
* @param JUser the user doing the password reset
* @return boolean true if user can do the reset, false if limit exceeded
$maxCount = (int)
$params->get('reset_count');
$resetHours = (int)
$params->get('reset_time');
// If it's been long enough, start a new reset count
if ($hoursSinceLastReset >
$resetHours)
// If we are under the max count, just increment the counter
elseif ($user->resetCount <
$maxCount)
// At this point, we know we have exceeded the maximum resets for the time period
Documentation generated on Tue, 19 Nov 2013 15:11:51 +0100 by phpDocumentor 1.4.3