Actions

API15

JUserHelper/activateUser

From Joomla! Documentation

< API15:JUserHelper
Revision as of 17:10, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Method to activate a user

[Edit Descripton]

Description:JUserHelper/activateUser

Syntax

activateUser($activation)
Parameter Name Default Value Description
$activation $activation Activation string

Returns

boolean True on success

Defined in

libraries/joomla/user/helper.php

Importing

jimport( 'joomla.user.helper' );

Source Body

function activateUser($activation)
{
        //Initialize some variables
        $db = & JFactory::getDBO();
 
        // Lets get the id of the user we want to activate
        $query = 'SELECT id'
        . ' FROM #__users'
        . ' WHERE activation = '.$db->Quote($activation)
        . ' AND block = 1'
        . ' AND lastvisitDate = '.$db->Quote('0000-00-00 00:00:00');
        ;
        $db->setQuery( $query );
        $id = intval( $db->loadResult() );
 
        // Is it a valid user to activate?
        if ($id)
        {
                $user =& JUser::getInstance( (int) $id );
 
                $user->set('block', '0');
                $user->set('activation', '');
 
                // Time to take care of business.... store the user.
                if (!$user->save())
                {
                        JError::raiseWarning( "SOME_ERROR_CODE", $user->getError() );
                        return false;
                }
        }
        else
        {
                JError::raiseWarning( "SOME_ERROR_CODE", JText::_('UNABLE TO FIND A USER WITH GIVEN ACTIVATION STRING') );
                return false;
        }
 
        return true;
}

[Edit See Also] SeeAlso:JUserHelper/activateUser

Examples

<CodeExamplesForm />