[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/components/com_user/models/ -> remind.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: remind.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla
   5   * @subpackage    User
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant to the
   9   * GNU General Public License, and as distributed it includes or is derivative
  10   * of works licensed under the GNU General Public License or other free or open
  11   * source software licenses. See COPYRIGHT.php for copyright notices and
  12   * details.
  13   */
  14  
  15  // No direct access
  16  defined('_JEXEC') or die;
  17  
  18  jimport('joomla.application.component.model');
  19  
  20  /**
  21   * User Component Remind Model
  22   *
  23   * @package        Joomla
  24   * @subpackage    User
  25   * @since        1.5
  26   */
  27  class UserModelRemind extends JModel
  28  {
  29      /**
  30       * Registry namespace prefix
  31       *
  32       * @var    string
  33       */
  34      var $_namespace    = 'com_user.remind.';
  35  
  36      /**
  37       * Takes a user supplied e-mail address, looks
  38       * it up in the database to find the username
  39       * and then e-mails the username to the e-mail
  40       * address given.
  41       *
  42       * @since    1.5
  43       * @param    string    E-mail address
  44       * @return    bool    True on success/false on failure
  45       */
  46  	function remindUsername($email)
  47      {
  48          jimport('joomla.mail.helper');
  49  
  50          global $mainframe;
  51  
  52          // Validate the e-mail address
  53          if (!JMailHelper::isEmailAddress($email))
  54          {
  55              $this->setError(JText::_('INVALID_EMAIL_ADDRESS'));
  56              return false;
  57          }
  58  
  59          $db = &JFactory::getDBO();
  60          $db->setQuery('SELECT username FROM #__users WHERE email = '.$db->Quote($email), 0, 1);
  61  
  62          // Get the username
  63          if (!($username = $db->loadResult()))
  64          {
  65              $this->setError(JText::_('COULD_NOT_FIND_EMAIL'));
  66              return false;
  67          }
  68  
  69          // Push the email address into the session
  70          $mainframe->setUserState($this->_namespace.'email', $email);
  71  
  72          // Send the reminder email
  73          if (!$this->_sendReminderMail($email, $username))
  74          {
  75              return false;
  76          }
  77  
  78          return true;
  79      }
  80  
  81      /**
  82       * Sends a username reminder to the e-mail address
  83       * specified containing the specified username.
  84       *
  85       * @since    1.5
  86       * @param    string    A user's e-mail address
  87       * @param    string    A user's username
  88       * @return    bool    True on success/false on failure
  89       */
  90  	function _sendReminderMail($email, $username)
  91      {
  92          $config        = &JFactory::getConfig();
  93          $uri        = &JFactory::getURI();
  94          $url        = $uri->toString( array('scheme', 'host', 'port')).JRoute::_('index.php?option=com_user&view=login', false);
  95  
  96          $from        = $config->getValue('mailfrom');
  97          $fromname    = $config->getValue('fromname');
  98          $subject    = JText::sprintf('USERNAME_REMINDER_EMAIL_TITLE', $config->getValue('sitename'));
  99          $body        = JText::sprintf('USERNAME_REMINDER_EMAIL_TEXT', $config->getValue('sitename'), $username, $url);
 100  
 101          if (!JUtility::sendMail($from, $fromname, $email, $subject, $body))
 102          {
 103              $this->setError('ERROR_SENDING_REMINDER_EMAIL');
 104              return false;
 105          }
 106  
 107          return true;
 108      }
 109  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1