API15

JUserHelper/activateUser

From Joomla! Documentation

< API15:JUserHelper
Revision as of 13:57, 12 May 2013 by JoomlaWikiBot (talk | contribs) (removing red link to edit, no existant pages)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Method to activate a user

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax[edit]

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

Returns[edit]

boolean True on success

Defined in[edit]

libraries/joomla/user/helper.php

Importing[edit]

jimport( 'joomla.user.helper' );

Source Body[edit]

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;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

<CodeExamplesForm />