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