Source for file remind.php

Documentation is available at remind.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_users
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Remind model class for Users.
  14.  *
  15.  * @package     Joomla.Site
  16.  * @subpackage  com_users
  17.  * @since       1.5
  18.  */
  19. class UsersModelRemind extends JModelForm
  20. {
  21.     /**
  22.      * Method to get the username remind request form.
  23.      *
  24.      * @param   array      $data        An optional array of data for the form to interogate.
  25.      * @param   boolean    $loadData    True if the form is to load its own data (default case), false if not.
  26.      * @return  JForm    A JForm object on success, false on failure
  27.      * @since   1.6
  28.      */
  29.     public function getForm($data array()$loadData true)
  30.     {
  31.         // Get the form.
  32.         $form $this->loadForm('com_users.remind''remind'array('control' => 'jform''load_data' => $loadData));
  33.         if (empty($form))
  34.         {
  35.             return false;
  36.         }
  37.  
  38.         return $form;
  39.     }
  40.  
  41.     /**
  42.      * Override preprocessForm to load the user plugin group instead of content.
  43.      *
  44.      * @param   object    form object.
  45.      * @param   mixed     The data expected for the form.
  46.      * @throws    Exception if there is an error in the form event.
  47.      * @since   1.6
  48.      */
  49.     protected function preprocessForm(JForm $form$data$group 'user')
  50.     {
  51.         parent::preprocessForm($form$data'user');
  52.     }
  53.  
  54.     /**
  55.      * Method to auto-populate the model state.
  56.      *
  57.      * Note. Calling getState in this method will result in recursion.
  58.      *
  59.      * @since   1.6
  60.      */
  61.     protected function populateState()
  62.     {
  63.         // Get the application object.
  64.         $app JFactory::getApplication();
  65.         $params $app->getParams('com_users');
  66.  
  67.         // Load the parameters.
  68.         $this->setState('params'$params);
  69.     }
  70.  
  71.     /**
  72.      * @since   1.6
  73.      */
  74.     public function processRemindRequest($data)
  75.     {
  76.         // Get the form.
  77.         $form $this->getForm();
  78.         $data['email'JStringPunycode::emailToPunycode($data['email']);
  79.  
  80.         // Check for an error.
  81.         if (empty($form))
  82.         {
  83.             return false;
  84.         }
  85.  
  86.         // Validate the data.
  87.         $data $this->validate($form$data);
  88.  
  89.         // Check for an error.
  90.         if ($data instanceof Exception)
  91.         {
  92.             return false;
  93.         }
  94.  
  95.         // Check the validation results.
  96.         if ($data === false)
  97.         {
  98.             // Get the validation messages from the form.
  99.             foreach ($form->getErrors(as $formError)
  100.             {
  101.                 $this->setError($formError->getMessage());
  102.             }
  103.             return false;
  104.         }
  105.  
  106.         // Find the user id for the given email address.
  107.         $db $this->getDbo();
  108.         $query $db->getQuery(true)
  109.             ->select('*')
  110.             ->from($db->quoteName('#__users'))
  111.             ->where($db->quoteName('email'' = ' $db->quote($data['email']));
  112.  
  113.         // Get the user id.
  114.         $db->setQuery($query);
  115.  
  116.         try
  117.         {
  118.             $user $db->loadObject();
  119.         }
  120.         catch (RuntimeException $e)
  121.         {
  122.             $this->setError(JText::sprintf('COM_USERS_DATABASE_ERROR'$e->getMessage())500);
  123.             return false;
  124.         }
  125.  
  126.         // Check for a user.
  127.         if (empty($user))
  128.         {
  129.             $this->setError(JText::_('COM_USERS_USER_NOT_FOUND'));
  130.             return false;
  131.         }
  132.  
  133.         // Make sure the user isn't blocked.
  134.         if ($user->block)
  135.         {
  136.             $this->setError(JText::_('COM_USERS_USER_BLOCKED'));
  137.             return false;
  138.         }
  139.  
  140.         $config JFactory::getConfig();
  141.  
  142.         // Assemble the login link.
  143.         $itemid UsersHelperRoute::getLoginRoute();
  144.         $itemid $itemid !== null '&Itemid=' $itemid '';
  145.         $link 'index.php?option=com_users&view=login' $itemid;
  146.         $mode $config->get('force_ssl'0== : -1;
  147.  
  148.         // Put together the email template data.
  149.         $data JArrayHelper::fromObject($user);
  150.         $data['fromname'$config->get('fromname');
  151.         $data['mailfrom'$config->get('mailfrom');
  152.         $data['sitename'$config->get('sitename');
  153.         $data['link_text'JRoute::_($linkfalse$mode);
  154.         $data['link_html'JRoute::_($linktrue$mode);
  155.  
  156.         $subject JText::sprintf(
  157.             'COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT',
  158.             $data['sitename']
  159.         );
  160.         $body JText::sprintf(
  161.             'COM_USERS_EMAIL_USERNAME_REMINDER_BODY',
  162.             $data['sitename'],
  163.             $data['username'],
  164.             $data['link_text']
  165.         );
  166.  
  167.         // Send the password reset request email.
  168.         $return JFactory::getMailer()->sendMail($data['mailfrom']$data['fromname']$user->email$subject$body);
  169.  
  170.         // Check for an error.
  171.         if ($return !== true)
  172.         {
  173.             $this->setError(JText::_('COM_USERS_MAIL_FAILED')500);
  174.             return false;
  175.         }
  176.  
  177.         return true;
  178.     }
  179. }

Documentation generated on Tue, 19 Nov 2013 15:11:47 +0100 by phpDocumentor 1.4.3