Back to UserHelper class

Method activateUser

public static bool
activateUser
(mixed $activation)
Method to activate a user
Parameters
  • string $activation Activation string
Returns
  • bool True on success
Since
  • 1.7.0
Class: UserHelper
Project: Joomla

Method activateUser - Source code

/**
 * Method to activate a user
 *
 * @param   string  $activation  Activation string
 *
 * @return  boolean  True on success
 *
 * @since   1.7.0
 */
public static function activateUser($activation)
{
    $db = Factory::getDbo();
    // Let's get the id of the user we want to activate
    $query = $db->getQuery(true)->select($db->quoteName('id'))->from($db->quoteName('#__users'))->where($db->quoteName('activation') . ' = :activation')->where($db->quoteName('block') . ' = 1')->where($db->quoteName('lastvisitDate') . ' IS NULL')->bind(':activation', $activation);
    $db->setQuery($query);
    $id = (int) $db->loadResult();
    // Is it a valid user to activate?
    if ($id) {
        $user = User::getInstance($id);
        $user->set('block', '0');
        $user->set('activation', '');
        // Time to take care of business.... store the user.
        if (!$user->save()) {
            Log::add($user->getError(), Log::WARNING, 'jerror');
            return false;
        }
    } else {
        Log::add(Text::_('JLIB_USER_ERROR_UNABLE_TO_FIND_USER'), Log::WARNING, 'jerror');
        return false;
    }
    return true;
}