Ejemplo n.º 1
0
 /**
  * Method to start the password reset process.
  *
  * @since	1.6
  */
 public function processResetRequest($data)
 {
     $config = JFactory::getConfig();
     // Get the form.
     $form = $this->getForm();
     // Check for an error.
     if ($form instanceof Exception) {
         return $form;
     }
     // Filter and validate the form data.
     $data = $form->filter($data);
     $return = $form->validate($data);
     // Check for an error.
     if ($return instanceof Exception) {
         return $return;
     }
     // Check the validation results.
     if ($return === false) {
         // Get the validation messages from the form.
         foreach ($form->getErrors() as $message) {
             $this->setError($message);
         }
         return false;
     }
     // Find the user id for the given email address.
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $query->select('id');
     $query->from($db->quoteName('#__users'));
     $query->where($db->quoteName('email') . ' = ' . $db->Quote($data['email']));
     // Get the user object.
     $db->setQuery((string) $query);
     $userId = $db->loadResult();
     // Check for an error.
     if ($db->getErrorNum()) {
         $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR', $db->getErrorMsg()), 500);
         return false;
     }
     // Check for a user.
     if (empty($userId)) {
         $this->setError(JText::_('COM_USERS_INVALID_EMAIL'));
         return false;
     }
     // Get the user object.
     $user = JUser::getInstance($userId);
     // Make sure the user isn't blocked.
     if ($user->block) {
         $this->setError(JText::_('COM_USERS_USER_BLOCKED'));
         return false;
     }
     // Make sure the user isn't a Super Admin.
     if ($user->authorise('core.admin')) {
         $this->setError(JText::_('COM_USERS_REMIND_SUPERADMIN_ERROR'));
         return false;
     }
     // Make sure the user has not exceeded the reset limit
     if (!$this->checkResetLimit($user)) {
         $resetLimit = (int) JFactory::getApplication()->getParams()->get('reset_time');
         $this->setError(JText::plural('COM_USERS_REMIND_LIMIT_ERROR_N_HOURS', $resetLimit));
         return false;
     }
     // Set the confirmation token.
     $token = JApplication::getHash(JUserHelper::genRandomPassword());
     $salt = JUserHelper::getSalt('crypt-md5');
     $hashedToken = md5($token . $salt) . ':' . $salt;
     $user->activation = $hashedToken;
     $db = JFactory::getDbo();
     $query = 'UPDATE #__users SET activation = "' . $hashedToken . '" WHERE id=' . (int) $userId;
     $db->setQuery($query);
     $success1 = $db->query();
     // Save the user to the database.
     //if (!$user->save()) {
     if (!$success1) {
         return new JException(JText::sprintf('COM_USERS_USER_SAVE_FAILED', $user->getError()), 500);
     }
     // Assemble the password reset confirmation link.
     $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;
     $link = 'http://www.ideary.co/index.php?forgot=confirm';
     // 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'] = $link;
     $data['link_html'] = $link;
     $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']);
     $body = ideary::emailBodyTableForgotPass($token, $data['link_text']);
     // Send the password reset request email.
     //$return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $user->email, $subject, $body);
     $headers = 'MIME-Version: 1.0' . "\r\n";
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     $headers .= 'From: ' . $data['fromname'] . ' <' . $data['mailfrom'] . '>' . "\r\n";
     $return = mail($user->email, $subject, $body, $headers);
     //var_dump($return);
     // Check for an error.
     if ($return !== true) {
         return new JException(JText::_('COM_USERS_MAIL_FAILED'), 500);
     }
     return true;
 }