JUserHelper/activateUser: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Method to activate a user
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowi... |
m preparing for archive only |
||
| (One intermediate revision by the same user not shown) | |||
| Line 2: | Line 2: | ||
Method to activate a user | Method to activate a user | ||
===Syntax=== | ===Syntax=== | ||
| Line 72: | Line 70: | ||
</source> | </source> | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=activateUser | category=activateUser | ||
category=JUserHelper | category=JUserHelper | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
Latest revision as of 02:16, 25 March 2017
Description
Method to activate a user
Syntax
static 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
public static 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;
}
Examples
Code Examples