/** * Get an user object. * * Returns the global {@link User} object, only creating it if it doesn't already exist. * * @param integer $id The user to load - Can be an integer or string - If string, it is converted to ID automatically. * * @return User object * * @see JUser * @since 11.1 */ public static function getUser($id = null) { $instance = self::getSession()->get('user'); if (is_null($id)) { if (!$instance instanceof User) { $instance = User::getInstance(); } } elseif (!$instance instanceof User || $instance->id != $id) { $instance = User::getInstance($id); } return $instance; }
/** * Method to activate a user * * @param string $activation Activation string * * @return boolean True on success * * @since 11.1 */ public static function activateUser($activation) { // Initialize some variables. $db = Factory::getDbo(); $query = $db->getQuery(true); // Let's get the id of the user we want to activate $query->select($db->quoteName('id')); $query->from($db->quoteName('#__users')); $query->where($db->quoteName('activation') . ' = ' . $db->quote($activation)); $query->where($db->quoteName('block') . ' = 1'); $query->where($db->quoteName('lastvisitDate') . ' = ' . $db->quote('0000-00-00 00:00:00')); $db->setQuery($query); $id = (int) $db->loadResult(); // Is it a valid user to activate? if ($id) { $user = User::getInstance((int) $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; }