english/components/com_users/models/registration.php
/**
	 * Method to save the form data.
	 *
	 * @param	array		The form data.
	 * @return	mixed		The user id on success, false on failure.
	 * @since	1.6
	 */
Method to save the form data.
@param       array           The form data.
@return      mixed           The user id on success, false on failure.
Method to save the form data . @param array The form data . @return mixed The user id on success false on failure .
public function register($temp)
	{
		$config = JFactory::getConfig();
		$params = JComponentHelper::getParams('com_users');
		$user = new JUser;
		$data = (array)$this->getData();
		foreach ($temp as $k => $v) {
			$data[$k] = $v;
		}
		$data['email']		= $data['email1'];
		$data['password']	= $data['password1'];
		$useractivation = $params->get('useractivation');
		if (($useractivation == 1) || ($useractivation == 2)) {
			jimport('joomla.user.helper');
			$data['activation'] = JUtility::getHash(JUserHelper::genRandomPassword());
			$data['block'] = 1;
		}
		if (!$user->bind($data)) {
			$this->setError(JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()));
			return false;
		}
		JPluginHelper::importPlugin('user');
		if (!$user->save()) {
			$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
			return false;
		}
		$data = $user->getProperties();
		$data['fromname']	= $config->get('fromname');
		$data['mailfrom']	= $config->get('mailfrom');
		$data['sitename']	= $config->get('sitename');
		$data['siteurl']	= JUri::base();
		if ($useractivation == 2)
		{
			$uri = JURI::getInstance();
			$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);
			$emailSubject	= JText::sprintf(
				'COM_USERS_EMAIL_ACCOUNT_DETAILS',
				$data['name'],
				$data['sitename']
			);
			$emailBody = JText::sprintf(
				'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY',
				$data['name'],
				$data['sitename'],
				$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'],
				$data['siteurl'],
				$data['username'],
				$data['password_clear']
			);
		}
		else if ($useractivation == 1)
		{
			$uri = JURI::getInstance();
			$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);
			$emailSubject	= JText::sprintf(
				'COM_USERS_EMAIL_ACCOUNT_DETAILS',
				$data['name'],
				$data['sitename']
			);
			$emailBody = JText::sprintf(
				'COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY',
				$data['name'],
				$data['sitename'],
				$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation'],
				$data['siteurl'],
				$data['username'],
				$data['password_clear']
			);
		} else {
			$emailSubject	= JText::sprintf(
				'COM_USERS_EMAIL_ACCOUNT_DETAILS',
				$data['name'],
				$data['sitename']
			);
			$emailBody = JText::sprintf(
				'COM_USERS_EMAIL_REGISTERED_BODY',
				$data['name'],
				$data['sitename'],
				$data['siteurl']
			);
		}
		$return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);
		if ($return !== true) {
			$this->setError(JText::_('COM_USERS_REGISTRATION_SEND_MAIL_FAILED'));
			$db = JFactory::getDBO();
			$q = "SELECT id
				FROM #__users
				WHERE block = 0
				AND sendEmail = 1";
			$db->setQuery($q);
			$sendEmail = $db->loadResultArray();
			if (count($sendEmail) > 0) {
				$jdate = new JDate();
				$q = "INSERT INTO `#__messages` (`user_id_from`, `user_id_to`, `date_time`, `subject`, `message`)
					VALUES ";
				$messages = array();
				foreach ($sendEmail as $userid) {
					$messages[] = "(".$userid.", ".$userid.", '".$jdate->toMySQL()."', '".JText::_('COM_USERS_MAIL_SEND_FAILURE_SUBJECT')."', '".JText::sprintf('COM_USERS_MAIL_SEND_FAILURE_BODY', $return, $data['username'])."')";
				}
				$q .= implode(',', $messages);
				$db->setQuery($q);
				$db->query();
			}
			return false;
		}
		if ($useractivation == 1)
			return "useractivate";
		else if ($useractivation == 2)
			return "adminactivate";
		else
			return $user->id;
	}
public function register ( $ temp ) { $ config = JFactory :: getConfig ( ) ; $ params = JComponentHelper :: getParams ( 'com_users' ) ; $ user = new JUser ; $ data = ( array ) $ this -> getData ( ) ; foreach ( $ temp as $ k => $ v ) { $ data [ $ k ] = $ v ; } $ data [ 'email' ] = $ data [ 'email1' ] ; $ data [ 'password' ] = $ data [ 'password1' ] ; $ useractivation = $ params -> get ( 'useractivation' ) ; if ( ( $ useractivation == 1 ) || ( $ useractivation == 2 ) ) { jimport ( 'joomla.user.helper' ) ; $ data [ 'activation' ] = JUtility :: getHash ( JUserHelper :: genRandomPassword ( ) ) ; $ data [ 'block' ] = 1 ; } if ( ! $ user -> bind ( $ data ) ) { $ this -> setError ( JText :: sprintf ( 'COM_USERS_REGISTRATION_BIND_FAILED' , $ user -> getError ( ) ) ) ; return false ; } JPluginHelper :: importPlugin ( 'user' ) ; if ( ! $ user -> save ( ) ) { $ this -> setError ( JText :: sprintf ( 'COM_USERS_REGISTRATION_SAVE_FAILED' , $ user -> getError ( ) ) ) ; return false ; } $ data = $ user -> getProperties ( ) ; $ data [ 'fromname' ] = $ config -> get ( 'fromname' ) ; $ data [ 'mailfrom' ] = $ config -> get ( 'mailfrom' ) ; $ data [ 'sitename' ] = $ config -> get ( 'sitename' ) ; $ data [ 'siteurl' ] = JUri :: base ( ) ; if ( $ useractivation == 2 ) { $ uri = JURI :: getInstance ( ) ; $ 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 ) ; $ emailSubject = JText :: sprintf ( 'COM_USERS_EMAIL_ACCOUNT_DETAILS' , $ data [ 'name' ] , $ data [ 'sitename' ] ) ; $ emailBody = JText :: sprintf ( 'COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY' , $ data [ 'name' ] , $ data [ 'sitename' ] , $ data [ 'siteurl' ] . 'index.php?option=com_users&task=registration.activate&token=' . $ data [ 'activation' ] , $ data [ 'siteurl' ] , $ data [ 'username' ] , $ data [ 'password_clear' ] ) ; } else if ( $ useractivation == 1 ) { $ uri = JURI :: getInstance ( ) ; $ 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 ) ; $ emailSubject = JText :: sprintf ( 'COM_USERS_EMAIL_ACCOUNT_DETAILS' , $ data [ 'name' ] , $ data [ 'sitename' ] ) ; $ emailBody = JText :: sprintf ( 'COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY' , $ data [ 'name' ] , $ data [ 'sitename' ] , $ data [ 'siteurl' ] . 'index.php?option=com_users&task=registration.activate&token=' . $ data [ 'activation' ] , $ data [ 'siteurl' ] , $ data [ 'username' ] , $ data [ 'password_clear' ] ) ; } else { $ emailSubject = JText :: sprintf ( 'COM_USERS_EMAIL_ACCOUNT_DETAILS' , $ data [ 'name' ] , $ data [ 'sitename' ] ) ; $ emailBody = JText :: sprintf ( 'COM_USERS_EMAIL_REGISTERED_BODY' , $ data [ 'name' ] , $ data [ 'sitename' ] , $ data [ 'siteurl' ] ) ; } $ return = JUtility :: sendMail ( $ data [ 'mailfrom' ] , $ data [ 'fromname' ] , $ data [ 'email' ] , $ emailSubject , $ emailBody ) ; if ( $ return !== true ) { $ this -> setError ( JText :: _ ( 'COM_USERS_REGISTRATION_SEND_MAIL_FAILED' ) ) ; $ db = JFactory :: getDBO ( ) ; $ q = " SELECT id
				FROM #__users
				WHERE block = 0
				AND sendEmail = 1 " ; $ db -> setQuery ( $ q ) ; $ sendEmail = $ db -> loadResultArray ( ) ; if ( count ( $ sendEmail ) > 0 ) { $ jdate = new JDate ( ) ; $ q = " INSERT INTO `#__messages` (`user_id_from`, `user_id_to`, `date_time`, `subject`, `message`)
					VALUES  " ; $ messages = array ( ) ; foreach ( $ sendEmail as $ userid ) { $ messages [ ] = " ( " . $ userid . " ,  " . $ userid . " , ' " . $ jdate -> toMySQL ( ) . " ', ' " . JText :: _ ( 'COM_USERS_MAIL_SEND_FAILURE_SUBJECT' ) . " ', ' " . JText :: sprintf ( 'COM_USERS_MAIL_SEND_FAILURE_BODY' , $ return , $ data [ 'username' ] ) . " ') " ; } $ q .= implode ( ',' , $ messages ) ; $ db -> setQuery ( $ q ) ; $ db -> query ( ) ; } return false ; } if ( $ useractivation == 1 ) return " useractivate " ; else if ( $ useractivation == 2 ) return " adminactivate " ; else return $ user -> id ; }
Method to save the form data.
Method to save the form data .
// Initialise the table with JUser. // Merge in the registration data. // Prepare the data for the user object. // Check if the user needs to activate their account. // Bind the data. // Load the users plugin group. // Store the data. // Compile the notification mail values. // Handle account activation/confirmation emails. // Set the link to confirm the user email. // Set the link to activate the user account. // Send the registration email. // Check for an error. // Send a system message to administrators receiving system mails // Build the query to add the messages