english/components/com_users/models/registration.php
/**
	 * Method to activate a user account.
	 *
	 * @param	string		The activation token.
	 * @return	mixed		False on failure, user object on success.
	 * @since	1.6
	 */
Method to activate a user account.
@param       string          The activation token.
@return      mixed           False on failure, user object on success.
Method to activate a user account . @param string The activation token . @return mixed False on failure user object on success .
public function activate($token)
	{
		$config	= JFactory::getConfig();
		$userParams	= JComponentHelper::getParams('com_users');
		$db		= $this->getDbo();
		$db->setQuery(
			'SELECT `id` FROM `#__users`' .
			' WHERE `activation` = '.$db->Quote($token) .
			' AND `block` = 1' .
			' AND `lastvisitDate` = '.$db->Quote($db->getNullDate())
		);
		$userId = (int) $db->loadResult();
		if (!$userId) {
			$this->setError(JText::_('COM_USERS_ACTIVATION_TOKEN_NOT_FOUND'));
			return false;
		}
		JPluginHelper::importPlugin('user');
		$user = JFactory::getUser($userId);
		if (($userParams->get('useractivation') == 2) && !$user->getParam('activate', 0))
		{
			$uri = JURI::getInstance();
			jimport('joomla.user.helper');
			$data = $user->getProperties();
			$data['activation'] = JUtility::getHash(JUserHelper::genRandomPassword());
			$user->set('activation', $data['activation']);
			$data['siteurl']	= JUri::base();
			$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);
			$emailSubject	= JText::sprintf(
				'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_SUBJECT',
				$data['name'],
				$data['sitename']
			);
			$emailBody = JText::sprintf(
				'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY',
				$data['sitename'],
				$data['name'],
				$data['email'],
				$data['username'],
				$data['siteurl'].'index.php?option=com_users&task=registration.activate&token='.$data['activation']
			);
			$query = 'SELECT name, email, sendEmail' .
						' FROM #__users' .
						' WHERE sendEmail=1';
			$db->setQuery( $query );
			$rows = $db->loadObjectList();
			foreach( $rows as $row )
			{
				$return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBody);
				if ($return !== true) {
					$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
					return false;
				}
			}
		}
		else if (($userParams->get('useractivation') == 2) && $user->getParam('activate', 0))
		{
			$user->set('activation', '');
			$user->set('block', '0');
			$uri = JURI::getInstance();
			jimport('joomla.user.helper');
			$data = $user->getProperties();
			$user->setParam('activate', 0);
			$data['fromname'] = $config->get('fromname');
			$data['mailfrom'] = $config->get('mailfrom');
			$data['sitename'] = $config->get('sitename');
			$data['siteurl']	= JUri::base();
			$emailSubject	= JText::sprintf(
				'COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_SUBJECT',
				$data['name'],
				$data['sitename']
			);
			$emailBody = JText::sprintf(
				'COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_BODY',
				$data['name'],
				$data['siteurl'],
				$data['username']
			);
			$return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody);
			if ($return !== true) {
				$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
				return false;
			}
		}
		else
		{
			$user->set('activation', '');
			$user->set('block', '0');
		}
		if (!$user->save()) {
			$this->setError(JText::sprintf('COM_USERS_REGISTRATION_ACTIVATION_SAVE_FAILED', $user->getError()));
			return false;
		}
		return $user;
	}
public function activate ( $ token ) { $ config = JFactory :: getConfig ( ) ; $ userParams = JComponentHelper :: getParams ( 'com_users' ) ; $ db = $ this -> getDbo ( ) ; $ db -> setQuery ( 'SELECT `id` FROM `#__users`' . ' WHERE `activation` = ' . $ db -> Quote ( $ token ) . ' AND `block` = 1' . ' AND `lastvisitDate` = ' . $ db -> Quote ( $ db -> getNullDate ( ) ) ) ; $ userId = ( int ) $ db -> loadResult ( ) ; if ( ! $ userId ) { $ this -> setError ( JText :: _ ( 'COM_USERS_ACTIVATION_TOKEN_NOT_FOUND' ) ) ; return false ; } JPluginHelper :: importPlugin ( 'user' ) ; $ user = JFactory :: getUser ( $ userId ) ; if ( ( $ userParams -> get ( 'useractivation' ) == 2 ) && ! $ user -> getParam ( 'activate' , 0 ) ) { $ uri = JURI :: getInstance ( ) ; jimport ( 'joomla.user.helper' ) ; $ data = $ user -> getProperties ( ) ; $ data [ 'activation' ] = JUtility :: getHash ( JUserHelper :: genRandomPassword ( ) ) ; $ user -> set ( 'activation' , $ data [ 'activation' ] ) ; $ data [ 'siteurl' ] = JUri :: base ( ) ; $ 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 ) ; $ emailSubject = JText :: sprintf ( 'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_SUBJECT' , $ data [ 'name' ] , $ data [ 'sitename' ] ) ; $ emailBody = JText :: sprintf ( 'COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY' , $ data [ 'sitename' ] , $ data [ 'name' ] , $ data [ 'email' ] , $ data [ 'username' ] , $ data [ 'siteurl' ] . 'index.php?option=com_users&task=registration.activate&token=' . $ data [ 'activation' ] ) ; $ query = 'SELECT name, email, sendEmail' . ' FROM #__users' . ' WHERE sendEmail=1' ; $ db -> setQuery ( $ query ) ; $ rows = $ db -> loadObjectList ( ) ; foreach ( $ rows as $ row ) { $ return = JUtility :: sendMail ( $ data [ 'mailfrom' ] , $ data [ 'fromname' ] , $ row -> email , $ emailSubject , $ emailBody ) ; if ( $ return !== true ) { $ this -> setError ( JText :: _ ( 'COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED' ) ) ; return false ; } } } else if ( ( $ userParams -> get ( 'useractivation' ) == 2 ) && $ user -> getParam ( 'activate' , 0 ) ) { $ user -> set ( 'activation' , '' ) ; $ user -> set ( 'block' , '0' ) ; $ uri = JURI :: getInstance ( ) ; jimport ( 'joomla.user.helper' ) ; $ data = $ user -> getProperties ( ) ; $ user -> setParam ( 'activate' , 0 ) ; $ data [ 'fromname' ] = $ config -> get ( 'fromname' ) ; $ data [ 'mailfrom' ] = $ config -> get ( 'mailfrom' ) ; $ data [ 'sitename' ] = $ config -> get ( 'sitename' ) ; $ data [ 'siteurl' ] = JUri :: base ( ) ; $ emailSubject = JText :: sprintf ( 'COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_SUBJECT' , $ data [ 'name' ] , $ data [ 'sitename' ] ) ; $ emailBody = JText :: sprintf ( 'COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_BODY' , $ data [ 'name' ] , $ data [ 'siteurl' ] , $ data [ 'username' ] ) ; $ return = JUtility :: sendMail ( $ data [ 'mailfrom' ] , $ data [ 'fromname' ] , $ data [ 'email' ] , $ emailSubject , $ emailBody ) ; if ( $ return !== true ) { $ this -> setError ( JText :: _ ( 'COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED' ) ) ; return false ; } } else { $ user -> set ( 'activation' , '' ) ; $ user -> set ( 'block' , '0' ) ; } if ( ! $ user -> save ( ) ) { $ this -> setError ( JText :: sprintf ( 'COM_USERS_REGISTRATION_ACTIVATION_SAVE_FAILED' , $ user -> getError ( ) ) ) ; return false ; } return $ user ; }
Method to activate a user account.
Method to activate a user account .
// Get the user id based on the token. // Check for a valid user id. // Load the users plugin group. // Activate the user. // Admin activation is on and user is verifying their email // Compile the admin notification mail values. // get all admin users // Send mail to all superadministrators id // Check for an error. //Admin activation is on and admin is activating the account // Compile the user activated notification mail values. // Check for an error. // Store the user object.