Source for file registration.php
Documentation is available at registration.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
* Registration model class for Users.
* @var object The user registration data.
* Method to activate a user account.
* @param string $token The activation token.
* @return mixed False on failure, user object on success.
// Get the user id based on the token.
$query =
$db->getQuery(true);
$query->select($db->quoteName('id'))
->from($db->quoteName('#__users'))
->where($db->quoteName('activation') .
' = ' .
$db->quote($token))
->where($db->quoteName('block') .
' = ' .
1)
->where($db->quoteName('lastvisitDate') .
' = ' .
$db->quote($db->getNullDate()));
$userId = (int)
$db->loadResult();
catch
(RuntimeException $e)
// Check for a valid user id.
// Load the users plugin group.
// Admin activation is on and user is verifying their email
if (($userParams->get('useractivation') ==
2) &&
!$user->getParam('activate', 0))
// Compile the admin notification mail values.
$data =
$user->getProperties();
$user->set('activation', $data['activation']);
$base =
$uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$data['activate'] =
$base .
JRoute::_('index.php?option=com_users&task=registration.activate&token=' .
$data['activation'], false);
$data['fromname'] =
$config->get('fromname');
$data['mailfrom'] =
$config->get('mailfrom');
$data['sitename'] =
$config->get('sitename');
$user->setParam('activate', 1);
'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_SUBJECT',
'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY',
->select($db->quoteName(array('name', 'email', 'sendEmail', 'id')))
->from($db->quoteName('#__users'))
->where($db->quoteName('sendEmail') .
' = ' .
1);
$rows =
$db->loadObjectList();
catch
(RuntimeException $e)
// Send mail to all users with users creating permissions and receiving system emails
if ($usercreator->authorise('core.create', 'com_users'))
$return =
JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBody);
$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
// Admin activation is on and admin is activating the account
elseif (($userParams->get('useractivation') ==
2) &&
$user->getParam('activate', 0))
$user->set('activation', '');
$user->set('block', '0');
// Compile the user activated notification mail values.
$data =
$user->getProperties();
$user->setParam('activate', 0);
$data['fromname'] =
$config->get('fromname');
$data['mailfrom'] =
$config->get('mailfrom');
$data['sitename'] =
$config->get('sitename');
'COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_SUBJECT',
'COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_BODY',
$return =
JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);
$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
$user->set('activation', '');
$user->set('block', '0');
// Store the user object.
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_ACTIVATION_SAVE_FAILED', $user->getError()));
* Method to get the registration form data.
* The base form data is loaded and then an event is fired
* for users plugins to extend the data.
* @return mixed Data object on success, false on failure.
if ($this->data ===
null)
$this->data =
new stdClass;
// Override the base user data with any data in the session.
$temp = (array)
$app->getUserState('com_users.registration.data', array());
foreach ($temp as $k =>
$v)
// Get the groups the user should be added to after registration.
$this->data->groups =
array();
// Get the default new user group, Registered if not specified.
$system =
$params->get('new_usertype', 2);
$this->data->groups[] =
$system;
unset
($this->data->password1);
unset
($this->data->password2);
// Get the dispatcher and load the users plugins.
// Trigger the data preparation event.
$results =
$dispatcher->trigger('onContentPrepareData', array('com_users.registration', $this->data));
// Check for errors encountered while preparing the data.
$this->setError($dispatcher->getError());
* Method to get the registration form.
* The base form is loaded from XML and then an event is fired
* for users plugins to extend the form with extra fields.
* @param array $data An optional array of data for the form to interogate.
* @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.registration', 'registration', array('control' =>
'jform', 'load_data' =>
$loadData));
* Method to get the data that should be injected in the form.
* @return mixed The data for the form.
* Override preprocessForm to load the user plugin group instead of content.
* @param JForm $form A JForm object.
* @param mixed $data The data expected for the form.
* @param string $group The name of the plugin group to import (defaults to "content").
* @throws Exception if there is an error in the form event.
protected function preprocessForm(JForm $form, $data, $group =
'user')
//Add the choice for site language at registration time
if ($userParams->get('site_language') ==
1 &&
$userParams->get('frontend_userparams') ==
1)
$form->loadFile('sitelang', false);
* Method to auto-populate the model state.
* Note. Calling getState in this method will result in recursion.
// Get the application object.
$params =
$app->getParams('com_users');
* Method to save the form data.
* @param array $temp The form data.
* @return mixed The user id on success, false on failure.
// Initialise the table with JUser.
// Merge in the registration data.
foreach ($temp as $k =>
$v)
// Prepare the data for the user object.
$data['password'] =
$data['password1'];
$useractivation =
$params->get('useractivation');
$sendpassword =
$params->get('sendpassword', 1);
// Check if the user needs to activate their account.
if (($useractivation ==
1) ||
($useractivation ==
2))
// Load the users plugin group.
$query =
$db->getQuery(true);
// Compile the notification mail values.
$data =
$user->getProperties();
$data['fromname'] =
$config->get('fromname');
$data['mailfrom'] =
$config->get('mailfrom');
$data['sitename'] =
$config->get('sitename');
// Handle account activation/confirmation emails.
if ($useractivation ==
2)
// Set the link to confirm the user email.
$base =
$uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$data['activate'] =
$base .
JRoute::_('index.php?option=com_users&task=registration.activate&token=' .
$data['activation'], false);
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY',
'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY_NOPW',
elseif ($useractivation ==
1)
// Set the link to activate the user account.
$base =
$uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$data['activate'] =
$base .
JRoute::_('index.php?option=com_users&task=registration.activate&token=' .
$data['activation'], false);
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
'COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY',
'COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW',
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
'COM_USERS_EMAIL_REGISTERED_BODY',
'COM_USERS_EMAIL_REGISTERED_BODY_NOPW',
// Send the registration email.
$return =
JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);
// Send Notification mail to administrators
if (($params->get('useractivation') <
2) &&
($params->get('mail_to_admin') ==
1))
'COM_USERS_EMAIL_ACCOUNT_DETAILS',
'COM_USERS_EMAIL_REGISTERED_NOTIFICATION_TO_ADMIN_BODY',
->select($db->quoteName(array('name', 'email', 'sendEmail')))
->from($db->quoteName('#__users'))
->where($db->quoteName('sendEmail') .
' = ' .
1);
$rows =
$db->loadObjectList();
catch
(RuntimeException $e)
// Send mail to all superadministrators id
$return =
JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBodyAdmin);
$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
// Send a system message to administrators receiving system mails
->select($db->quoteName(array('name', 'email', 'sendEmail', 'id')))
->from($db->quoteName('#__users'))
->where($db->quoteName('block') .
' = ' . (int)
0)
->where($db->quoteName('sendEmail') .
' = ' . (int)
1);
$sendEmail =
$db->loadColumn();
catch
(RuntimeException $e)
if (count($sendEmail) >
0)
// Build the query to add the messages
foreach ($sendEmail as $userid)
$values =
array($db->quote($userid), $db->quote($userid), $db->quote($jdate->toSql()), $db->quote(JText::_('COM_USERS_MAIL_SEND_FAILURE_SUBJECT')), $db->quote(JText::sprintf('COM_USERS_MAIL_SEND_FAILURE_BODY', $return, $data['username'])));
->insert($db->quoteName('#__messages'))
->columns($db->quoteName(array('user_id_from', 'user_id_to', 'date_time', 'subject', 'message')))
catch
(RuntimeException $e)
if ($useractivation ==
1)
elseif ($useractivation ==
2)
Documentation generated on Tue, 19 Nov 2013 15:11:41 +0100 by phpDocumentor 1.4.3