AAAAPK ?\UD4d* d* authentication.phpnu W+A _state;
}
/**
* Attach an observer object
*
* @param object $observer An observer object to attach
*
* @return void
*
* @since 11.1
*/
public function attach($observer)
{
if (is_array($observer))
{
if (!isset($observer['handler']) || !isset($observer['event']) || !is_callable($observer['handler']))
{
return;
}
// Make sure we haven't already attached this array as an observer
foreach ($this->_observers as $check)
{
if (is_array($check) && $check['event'] == $observer['event'] && $check['handler'] == $observer['handler'])
{
return;
}
}
$this->_observers[] = $observer;
end($this->_observers);
$methods = array($observer['event']);
}
else
{
if (!($observer instanceof JAuthentication))
{
return;
}
// Make sure we haven't already attached this object as an observer
$class = get_class($observer);
foreach ($this->_observers as $check)
{
if ($check instanceof $class)
{
return;
}
}
$this->_observers[] = $observer;
$methods = array_diff(get_class_methods($observer), get_class_methods('JPlugin'));
}
$key = key($this->_observers);
foreach ($methods as $method)
{
$method = strtolower($method);
if (!isset($this->_methods[$method]))
{
$this->_methods[$method] = array();
}
$this->_methods[$method][] = $key;
}
}
/**
* Detach an observer object
*
* @param object $observer An observer object to detach.
*
* @return boolean True if the observer object was detached.
*
* @since 11.1
*/
public function detach($observer)
{
// Initialise variables.
$retval = false;
$key = array_search($observer, $this->_observers);
if ($key !== false)
{
unset($this->_observers[$key]);
$retval = true;
foreach ($this->_methods as &$method)
{
$k = array_search($key, $method);
if ($k !== false)
{
unset($method[$k]);
}
}
}
return $retval;
}
/**
* Finds out if a set of login credentials are valid by asking all observing
* objects to run their respective authentication routines.
*
* @param array $credentials Array holding the user credentials.
* @param array $options Array holding user options.
*
* @return JAuthenticationResponse Response object with status variable filled in for last plugin or first successful plugin.
*
* @see JAuthenticationResponse
* @since 11.1
*/
public function authenticate($credentials, $options = array())
{
// Get plugins
$plugins = JPluginHelper::getPlugin('authentication');
// Create authentication response
$response = new JAuthenticationResponse;
/*
* Loop through the plugins and check of the credentials can be used to authenticate
* the user
*
* Any errors raised in the plugin should be returned via the JAuthenticationResponse
* and handled appropriately.
*/
foreach ($plugins as $plugin)
{
$className = 'plg' . $plugin->type . $plugin->name;
if (class_exists($className))
{
$plugin = new $className($this, (array) $plugin);
}
else
{
// Bail here if the plugin can't be created
JError::raiseWarning(50, JText::sprintf('JLIB_USER_ERROR_AUTHENTICATION_FAILED_LOAD_PLUGIN', $className));
continue;
}
// Try to authenticate
$plugin->onUserAuthenticate($credentials, $options, $response);
// If authentication is successful break out of the loop
if ($response->status === JAuthentication::STATUS_SUCCESS)
{
if (empty($response->type))
{
$response->type = isset($plugin->_name) ? $plugin->_name : $plugin->name;
}
break;
}
}
if (empty($response->username))
{
$response->username = $credentials['username'];
}
if (empty($response->fullname))
{
$response->fullname = $credentials['username'];
}
if (empty($response->password))
{
$response->password = $credentials['password'];
}
return $response;
}
/**
* Authorises that a particular user should be able to login
*
* @param JAuthenticationResponse $response response including username of the user to authorise
* @param array $options list of options
*
* @return array[JAuthenticationResponse] results of authorisation
*
* @since 11.2
*/
public static function authorise($response, $options = array())
{
// Get plugins in case they haven't been loaded already
JPluginHelper::getPlugin('user');
JPluginHelper::getPlugin('authentication');
$dispatcher = JDispatcher::getInstance();
$results = $dispatcher->trigger('onUserAuthorisation', array($response, $options));
return $results;
}
}
/**
* Authentication response class, provides an object for storing user and error details
*
* @package Joomla.Platform
* @subpackage User
* @since 11.1
*/
class JAuthenticationResponse extends JObject
{
/**
* Response status (see status codes)
*
* @var string
* @since 11.1
*/
public $status = JAuthentication::STATUS_FAILURE;
/**
* The type of authentication that was successful
*
* @var string
* @since 11.1
*/
public $type = '';
/**
* The error message
*
* @var string
* @since 11.1
*/
public $error_message = '';
/**
* Any UTF-8 string that the End User wants to use as a username.
*
* @var string
* @since 11.1
*/
public $username = '';
/**
* Any UTF-8 string that the End User wants to use as a password.
*
* @var string
* @since 11.1
*/
public $password = '';
/**
* The email address of the End User as specified in section 3.4.1 of [RFC2822]
*
* @var string
* @since 11.1
*/
public $email = '';
/**
* UTF-8 string free text representation of the End User's full name.
*
* @var string
* @since 11.1
*
*/
public $fullname = '';
/**
* The End User's date of birth as YYYY-MM-DD. Any values whose representation uses
* fewer than the specified number of digits should be zero-padded. The length of this
* value MUST always be 10. If the End User user does not want to reveal any particular
* component of this value, it MUST be set to zero.
*
* For instance, if a End User wants to specify that his date of birth is in 1980, but
* not the month or day, the value returned SHALL be "1980-00-00".
*
* @var string
* @since 11.1
*/
public $birthdate = '';
/**
* The End User's gender, "M" for male, "F" for female.
*
* @var string
* @since 11.1
*/
public $gender = '';
/**
* UTF-8 string free text that SHOULD conform to the End User's country's postal system.
*
* @var postcode string
* @since 11.1
*/
public $postcode = '';
/**
* The End User's country of residence as specified by ISO3166.
*
* @var string
* @since 11.1
*/
public $country = '';
/**
* End User's preferred language as specified by ISO639.
*
* @var string
* @since 11.1
*/
public $language = '';
/**
* ASCII string from TimeZone database
*
* @var string
* @since 11.1
*/
public $timezone = '';
/**
* Constructor
*
* @since 11.1
*/
public function __construct()
{
}
}
PK ?\) .htaccessnu W+A
Order allow,deny
Deny from all
PK ?\π5B 5B
helper.phpnu W+A groups))
{
// Get the title of the group.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('title'));
$query->from($db->quoteName('#__usergroups'));
$query->where($db->quoteName('id') . ' = ' . (int) $groupId);
$db->setQuery($query);
$title = $db->loadResult();
// Check for a database error.
if ($db->getErrorNum())
{
return new Exception($db->getErrorMsg());
}
// If the group does not exist, return an exception.
if (!$title)
{
return new Exception(JText::_('JLIB_USER_EXCEPTION_ACCESS_USERGROUP_INVALID'));
}
// Add the group data to the user object.
$user->groups[$title] = $groupId;
// Store the user object.
if (!$user->save())
{
return new Exception($user->getError());
}
}
// Set the group data for any preloaded user objects.
$temp = JFactory::getUser((int) $userId);
$temp->groups = $user->groups;
// Set the group data for the user object in the session.
$temp = JFactory::getUser();
if ($temp->id == $userId)
{
$temp->groups = $user->groups;
}
return true;
}
/**
* Method to get a list of groups a user is in.
*
* @param integer $userId The id of the user.
*
* @return mixed Array on success, JException on error.
*
* @since 11.1
*/
public static function getUserGroups($userId)
{
// Get the user object.
$user = JUser::getInstance((int) $userId);
return isset($user->groups) ? $user->groups : array();
}
/**
* Method to remove a user from a group.
*
* @param integer $userId The id of the user.
* @param integer $groupId The id of the group.
*
* @return mixed Boolean true on success, JException on error.
*
* @since 11.1
*/
public static function removeUserFromGroup($userId, $groupId)
{
// Get the user object.
$user = JUser::getInstance((int) $userId);
// Remove the user from the group if necessary.
$key = array_search($groupId, $user->groups);
if ($key !== false)
{
// Remove the user from the group.
unset($user->groups[$key]);
// Store the user object.
if (!$user->save())
{
return new JException($user->getError());
}
}
// Set the group data for any preloaded user objects.
$temp = JFactory::getUser((int) $userId);
$temp->groups = $user->groups;
// Set the group data for the user object in the session.
$temp = JFactory::getUser();
if ($temp->id == $userId)
{
$temp->groups = $user->groups;
}
return true;
}
/**
* Method to set the groups for a user.
*
* @param integer $userId The id of the user.
* @param array $groups An array of group ids to put the user in.
*
* @return mixed Boolean true on success, Exception on error.
*
* @since 11.1
*/
public static function setUserGroups($userId, $groups)
{
// Get the user object.
$user = JUser::getInstance((int) $userId);
// Set the group ids.
JArrayHelper::toInteger($groups);
$user->groups = $groups;
// Get the titles for the user groups.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('id') . ', ' . $db->quoteName('title'));
$query->from($db->quoteName('#__usergroups'));
$query->where($db->quoteName('id') . ' = ' . implode(' OR ' . $db->quoteName('id') . ' = ', $user->groups));
$db->setQuery($query);
$results = $db->loadObjectList();
// Check for a database error.
if ($db->getErrorNum())
{
return new Exception($db->getErrorMsg());
}
// Set the titles for the user groups.
for ($i = 0, $n = count($results); $i < $n; $i++)
{
$user->groups[$results[$i]->id] = $results[$i]->title;
}
// Store the user object.
if (!$user->save())
{
return new Exception($user->getError());
}
// Set the group data for any preloaded user objects.
$temp = JFactory::getUser((int) $userId);
$temp->groups = $user->groups;
// Set the group data for the user object in the session.
$temp = JFactory::getUser();
if ($temp->id == $userId)
{
$temp->groups = $user->groups;
}
return true;
}
/**
* Gets the user profile information
*
* @param integer $userId The id of the user.
*
* @return object
*
* @since 11.1
*/
public static function getProfile($userId = 0)
{
if ($userId == 0)
{
$user = JFactory::getUser();
$userId = $user->id;
}
// Get the dispatcher and load the user's plugins.
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('user');
$data = new JObject;
$data->id = $userId;
// Trigger the data preparation event.
$dispatcher->trigger('onContentPrepareData', array('com_users.profile', &$data));
return $data;
}
/**
* 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 = JFactory::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 = 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::_('JLIB_USER_ERROR_UNABLE_TO_FIND_USER'));
return false;
}
return true;
}
/**
* Returns userid if a user exists
*
* @param string $username The username to search on.
*
* @return integer The user id or 0 if not found.
*
* @since 11.1
*/
public static function getUserId($username)
{
// Initialise some variables
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('id'));
$query->from($db->quoteName('#__users'));
$query->where($db->quoteName('username') . ' = ' . $db->quote($username));
$db->setQuery($query, 0, 1);
return $db->loadResult();
}
/**
* Hashes a password using the current encryption.
*
* @param string $password The plaintext password to encrypt.
*
* @return string The encrypted password.
*
* @since 3.2.1
*/
public static function hashPassword($password)
{
// Use PHPass's portable hashes with a cost of 10.
$phpass = new PasswordHash(10, true);
return $phpass->HashPassword($password);
}
/**
* Formats a password using the current encryption. If the user ID is given
* and the hash does not fit the current hashing algorithm, it automatically
* updates the hash.
*
* @param string $password The plaintext password to check.
* @param string $hash The hash to verify against.
* @param integer $user_id ID of the user if the password hash should be updated
*
* @return boolean True if the password and hash match, false otherwise
*
* @since 3.2.1
*/
public static function verifyPassword($password, $hash, $user_id = 0)
{
$rehash = false;
$match = false;
// If we are using phpass
if (strpos($hash, '$P$') === 0)
{
// Use PHPass's portable hashes with a cost of 10.
$phpass = new PasswordHash(10, true);
$match = $phpass->CheckPassword($password, $hash);
$rehash = false;
}
else
{
// Check the password
$parts = explode(':', $hash);
$crypt = $parts[0];
$salt = @$parts[1];
$rehash = true;
$testcrypt = md5($password . $salt) . ($salt ? ':' . $salt : '');
$match = JCrypt::timingSafeCompare($hash, $testcrypt);
}
// If we have a match and rehash = true, rehash the password with the current algorithm.
if ((int) $user_id > 0 && $match && $rehash)
{
$user = new JUser($user_id);
$user->password = self::hashPassword($password);
$user->save();
}
return $match;
}
/**
* Formats a password using the current encryption.
*
* @param string $plaintext The plaintext password to encrypt.
* @param string $salt The salt to use to encrypt the password. []
* If not present, a new salt will be
* generated.
* @param string $encryption The kind of password encryption to use.
* Defaults to md5-hex.
* @param boolean $show_encrypt Some password systems prepend the kind of
* encryption to the crypted password ({SHA},
* etc). Defaults to false.
*
* @return string The encrypted password.
*
* @since 11.1
*
* @deprecated 4.0
*/
public static function getCryptedPassword($plaintext, $salt = '', $encryption = 'md5-hex', $show_encrypt = false)
{
// Get the salt to use.
$salt = JUserHelper::getSalt($encryption, $salt, $plaintext);
// Encrypt the password.
switch ($encryption)
{
case 'plain':
return $plaintext;
case 'sha':
$encrypted = base64_encode(mhash(MHASH_SHA1, $plaintext));
return ($show_encrypt) ? '{SHA}' . $encrypted : $encrypted;
case 'crypt':
case 'crypt-des':
case 'crypt-md5':
case 'crypt-blowfish':
return ($show_encrypt ? '{crypt}' : '') . crypt($plaintext, $salt);
case 'md5-base64':
$encrypted = base64_encode(mhash(MHASH_MD5, $plaintext));
return ($show_encrypt) ? '{MD5}' . $encrypted : $encrypted;
case 'ssha':
$encrypted = base64_encode(mhash(MHASH_SHA1, $plaintext . $salt) . $salt);
return ($show_encrypt) ? '{SSHA}' . $encrypted : $encrypted;
case 'smd5':
$encrypted = base64_encode(mhash(MHASH_MD5, $plaintext . $salt) . $salt);
return ($show_encrypt) ? '{SMD5}' . $encrypted : $encrypted;
case 'aprmd5':
$length = strlen($plaintext);
$context = $plaintext . '$apr1$' . $salt;
$binary = JUserHelper::_bin(md5($plaintext . $salt . $plaintext));
for ($i = $length; $i > 0; $i -= 16)
{
$context .= substr($binary, 0, ($i > 16 ? 16 : $i));
}
for ($i = $length; $i > 0; $i >>= 1)
{
$context .= ($i & 1) ? chr(0) : $plaintext[0];
}
$binary = JUserHelper::_bin(md5($context));
for ($i = 0; $i < 1000; $i++)
{
$new = ($i & 1) ? $plaintext : substr($binary, 0, 16);
if ($i % 3)
{
$new .= $salt;
}
if ($i % 7)
{
$new .= $plaintext;
}
$new .= ($i & 1) ? substr($binary, 0, 16) : $plaintext;
$binary = JUserHelper::_bin(md5($new));
}
$p = array();
for ($i = 0; $i < 5; $i++)
{
$k = $i + 6;
$j = $i + 12;
if ($j == 16)
{
$j = 5;
}
$p[] = JUserHelper::_toAPRMD5((ord($binary[$i]) << 16) | (ord($binary[$k]) << 8) | (ord($binary[$j])), 5);
}
return '$apr1$' . $salt . '$' . implode('', $p) . JUserHelper::_toAPRMD5(ord($binary[11]), 3);
case 'md5-hex':
default:
$encrypted = ($salt) ? md5($plaintext . $salt) : md5($plaintext);
return ($show_encrypt) ? '{MD5}' . $encrypted : $encrypted;
}
}
/**
* Returns a salt for the appropriate kind of password encryption.
* Optionally takes a seed and a plaintext password, to extract the seed
* of an existing password, or for encryption types that use the plaintext
* in the generation of the salt.
*
* @param string $encryption The kind of password encryption to use.
* Defaults to md5-hex.
* @param string $seed The seed to get the salt from (probably a
* previously generated password). Defaults to
* generating a new seed.
* @param string $plaintext The plaintext password that we're generating
* a salt for. Defaults to none.
*
* @return string The generated or extracted salt.
*
* @since 11.1
*/
public static function getSalt($encryption = 'md5-hex', $seed = '', $plaintext = '')
{
// Encrypt the password.
switch ($encryption)
{
case 'crypt':
case 'crypt-des':
if ($seed)
{
return substr(preg_replace('|^{crypt}|i', '', $seed), 0, 2);
}
else
{
return substr(md5(mt_rand()), 0, 2);
}
break;
case 'crypt-md5':
if ($seed)
{
return substr(preg_replace('|^{crypt}|i', '', $seed), 0, 12);
}
else
{
return '$1$' . substr(md5(mt_rand()), 0, 8) . '$';
}
break;
case 'crypt-blowfish':
if ($seed)
{
return substr(preg_replace('|^{crypt}|i', '', $seed), 0, 16);
}
else
{
return '$2$' . substr(md5(mt_rand()), 0, 12) . '$';
}
break;
case 'ssha':
if ($seed)
{
return substr(preg_replace('|^{SSHA}|', '', $seed), -20);
}
else
{
return mhash_keygen_s2k(MHASH_SHA1, $plaintext, substr(pack('h*', md5(mt_rand())), 0, 8), 4);
}
break;
case 'smd5':
if ($seed)
{
return substr(preg_replace('|^{SMD5}|', '', $seed), -16);
}
else
{
return mhash_keygen_s2k(MHASH_MD5, $plaintext, substr(pack('h*', md5(mt_rand())), 0, 8), 4);
}
break;
case 'aprmd5': /* 64 characters that are valid for APRMD5 passwords. */
$APRMD5 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
if ($seed)
{
return substr(preg_replace('/^\$apr1\$(.{8}).*/', '\\1', $seed), 0, 8);
}
else
{
$salt = '';
for ($i = 0; $i < 8; $i++)
{
$salt .= $APRMD5{rand(0, 63)};
}
return $salt;
}
break;
default:
$salt = '';
if ($seed)
{
$salt = $seed;
}
return $salt;
break;
}
}
/**
* Generate a random password
*
* @param integer $length Length of the password to generate
*
* @return string Random Password
*
* @since 11.1
*/
public static function genRandomPassword($length = 8)
{
$salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$base = strlen($salt);
$makepass = '';
/*
* Start with a cryptographic strength random string, then convert it to
* a string with the numeric base of the salt.
* Shift the base conversion on each character so the character
* distribution is even, and randomize the start shift so it's not
* predictable.
*/
$random = JCrypt::genRandomBytes($length + 1);
$shift = ord($random[0]);
for ($i = 1; $i <= $length; ++$i)
{
$makepass .= $salt[($shift + ord($random[$i])) % $base];
$shift += ord($random[$i]);
}
return $makepass;
}
/**
* Converts to allowed 64 characters for APRMD5 passwords.
*
* @param string $value The value to convert.
* @param integer $count The number of characters to convert.
*
* @return string $value converted to the 64 MD5 characters.
*
* @since 11.1
*/
protected static function _toAPRMD5($value, $count)
{
/* 64 characters that are valid for APRMD5 passwords. */
$APRMD5 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$aprmd5 = '';
$count = abs($count);
while (--$count)
{
$aprmd5 .= $APRMD5[$value & 0x3f];
$value >>= 6;
}
return $aprmd5;
}
/**
* Converts hexadecimal string to binary data.
*
* @param string $hex Hex data.
*
* @return string Binary data.
*
* @since 11.1
*/
private static function _bin($hex)
{
$bin = '';
$length = strlen($hex);
for ($i = 0; $i < $length; $i += 2)
{
$tmp = sscanf(substr($hex, $i, 2), '%x');
$bin .= chr(array_shift($tmp));
}
return $bin;
}
}
PK ?\P P user.phpnu W+A _params = new JRegistry;
// Load the user if it exists
if (!empty($identifier))
{
$this->load($identifier);
}
else
{
//initialise
$this->id = 0;
$this->sendEmail = 0;
$this->aid = 0;
$this->guest = 1;
}
}
/**
* Returns the global User object, only creating it if it
* doesn't already exist.
*
* @param integer $identifier The user to load - Can be an integer or string - If string, it is converted to ID automatically.
*
* @return JUser The User object.
*
* @since 11.1
*/
public static function getInstance($identifier = 0)
{
// Find the user id
if (!is_numeric($identifier))
{
if (!$id = JUserHelper::getUserId($identifier))
{
JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('JLIB_USER_ERROR_ID_NOT_EXISTS', $identifier));
$retval = false;
return $retval;
}
}
else
{
$id = $identifier;
}
// If the $id is zero, just return an empty JUser.
// Note: don't cache this user because it'll have a new ID on save!
if ($id === 0)
{
return new JUser;
}
if (empty(self::$instances[$id]))
{
$user = new JUser($id);
self::$instances[$id] = $user;
}
return self::$instances[$id];
}
/**
* Method to get a parameter value
*
* @param string $key Parameter key
* @param mixed $default Parameter default value
*
* @return mixed The value or the default if it did not exist
*
* @since 11.1
*/
public function getParam($key, $default = null)
{
return $this->_params->get($key, $default);
}
/**
* Method to set a parameter
*
* @param string $key Parameter key
* @param mixed $value Parameter value
*
* @return mixed Set parameter value
*
* @since 11.1
*/
public function setParam($key, $value)
{
return $this->_params->set($key, $value);
}
/**
* Method to set a default parameter if it does not exist
*
* @param string $key Parameter key
* @param mixed $value Parameter value
*
* @return mixed Set parameter value
*
* @since 11.1
*/
public function defParam($key, $value)
{
return $this->_params->def($key, $value);
}
/**
* Proxy to authorise
*
* @param string $action The name of the action to check for permission.
* @param string $assetname The name of the asset on which to perform the action.
*
* @return boolean True if authorised
*
* @deprecated 12.1
* @note Use the authorise method instead.
* @since 11.1
*/
public function authorize($action, $assetname = null)
{
// Deprecation warning.
JLog::add('JUser::authorize() is deprecated.', JLog::WARNING, 'deprecated');
return $this->authorise($action, $assetname);
}
/**
* Method to check JUser object authorisation against an access control
* object and optionally an access extension object
*
* @param string $action The name of the action to check for permission.
* @param string $assetname The name of the asset on which to perform the action.
*
* @return boolean True if authorised
*
* @since 11.1
*/
public function authorise($action, $assetname = null)
{
// Make sure we only check for core.admin once during the run.
if ($this->isRoot === null)
{
$this->isRoot = false;
// Check for the configuration file failsafe.
$config = JFactory::getConfig();
$rootUser = $config->get('root_user');
// The root_user variable can be a numeric user ID or a username.
if (is_numeric($rootUser) && $this->id > 0 && $this->id == $rootUser)
{
$this->isRoot = true;
}
elseif ($this->username && $this->username == $rootUser)
{
$this->isRoot = true;
}
else
{
// Get all groups against which the user is mapped.
$identities = $this->getAuthorisedGroups();
array_unshift($identities, $this->id * -1);
if (JAccess::getAssetRules(1)->allow('core.admin', $identities))
{
$this->isRoot = true;
return true;
}
}
}
return $this->isRoot ? true : JAccess::check($this->id, $action, $assetname);
}
/**
* Gets an array of the authorised access levels for the user
*
* @return array
*
* @deprecated 12.1
* @note Use the getAuthorisedViewLevels method instead.
* @since 11.1
*/
public function authorisedLevels()
{
// Deprecation warning.
JLog::add('JUser::authorisedLevels() is deprecated.', JLog::WARNING, 'deprecated');
return $this->getAuthorisedViewLevels();
}
/**
* Method to return a list of all categories that a user has permission for a given action
*
* @param string $component The component from which to retrieve the categories
* @param string $action The name of the section within the component from which to retrieve the actions.
*
* @return array List of categories that this group can do this action to (empty array if none). Categories must be published.
*
* @since 11.1
*/
public function getAuthorisedCategories($component, $action)
{
// Brute force method: get all published category rows for the component and check each one
// TODO: Modify the way permissions are stored in the db to allow for faster implementation and better scaling
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select('c.id AS id, a.name AS asset_name')->from('#__categories AS c')
->innerJoin('#__assets AS a ON c.asset_id = a.id')->where('c.extension = ' . $db->quote($component))->where('c.published = 1');
$db->setQuery($query);
$allCategories = $db->loadObjectList('id');
$allowedCategories = array();
foreach ($allCategories as $category)
{
if ($this->authorise($action, $category->asset_name))
{
$allowedCategories[] = (int) $category->id;
}
}
return $allowedCategories;
}
/**
* Gets an array of the authorised access levels for the user
*
* @return array
*
* @since 11.1
*/
public function getAuthorisedViewLevels()
{
if ($this->_authLevels === null)
{
$this->_authLevels = array();
}
if (empty($this->_authLevels))
{
$this->_authLevels = JAccess::getAuthorisedViewLevels($this->id);
}
return $this->_authLevels;
}
/**
* Gets an array of the authorised user groups
*
* @return array
*
* @since 11.1
*/
public function getAuthorisedGroups()
{
if ($this->_authGroups === null)
{
$this->_authGroups = array();
}
if (empty($this->_authGroups))
{
$this->_authGroups = JAccess::getGroupsByUser($this->id);
}
return $this->_authGroups;
}
/**
* Pass through method to the table for setting the last visit date
*
* @param integer $timestamp The timestamp, defaults to 'now'.
*
* @return boolean True on success.
*
* @since 11.1
*/
public function setLastVisit($timestamp = null)
{
// Create the user table object
$table = $this->getTable();
$table->load($this->id);
return $table->setLastVisit($timestamp);
}
/**
* Method to get the user parameters
*
* This function tries to load an XML file based on the user's usertype. The filename of the xml
* file is the same as the usertype. The functionals has a static variable to store the parameters
* setup file base path. You can call this function statically to set the base path if needed.
*
* @param boolean $loadsetupfile If true, loads the parameters setup file. Default is false.
* @param path $path Set the parameters setup file base path to be used to load the user parameters.
*
* @return object The user parameters object.
*
* @since 11.1
*/
public function getParameters($loadsetupfile = false, $path = null)
{
static $parampath;
// Set a custom parampath if defined
if (isset($path))
{
$parampath = $path;
}
// Set the default parampath if not set already
if (!isset($parampath))
{
$parampath = JPATH_ADMINISTRATOR . 'components/com_users/models';
}
if ($loadsetupfile)
{
$type = str_replace(' ', '_', strtolower($this->usertype));
$file = $parampath . '/' . $type . '.xml';
if (!file_exists($file))
{
$file = $parampath . '/' . 'user.xml';
}
$this->_params->loadSetupFile($file);
}
return $this->_params;
}
/**
* Method to get the user parameters
*
* @param object $params The user parameters object
*
* @return void
*
* @since 11.1
*/
public function setParameters($params)
{
$this->_params = $params;
}
/**
* Method to get the user table object
*
* This function uses a static variable to store the table name of the user table to
* instantiate. You can call this function statically to set the table name if
* needed.
*
* @param string $type The user table name to be used
* @param string $prefix The user table prefix to be used
*
* @return object The user table object
*
* @since 11.1
*/
public static function getTable($type = null, $prefix = 'JTable')
{
static $tabletype;
// Set the default tabletype;
if (!isset($tabletype))
{
$tabletype['name'] = 'user';
$tabletype['prefix'] = 'JTable';
}
// Set a custom table type is defined
if (isset($type))
{
$tabletype['name'] = $type;
$tabletype['prefix'] = $prefix;
}
// Create the user table object
return JTable::getInstance($tabletype['name'], $tabletype['prefix']);
}
/**
* Method to bind an associative array of data to a user object
*
* @param array &$array The associative array to bind to the object
*
* @return boolean True on success
*
* @since 11.1
*/
public function bind(&$array)
{
// Let's check to see if the user is new or not
if (empty($this->id))
{
// Check the password and create the crypted password
if (empty($array['password']))
{
$array['password'] = JUserHelper::genRandomPassword();
$array['password2'] = $array['password'];
}
// TODO: Backend controller checks the password, frontend doesn't but should.
// Hence this code is required:
if (isset($array['password2']) && $array['password'] != $array['password2'])
{
$this->setError(JText::_('JLIB_USER_ERROR_PASSWORD_NOT_MATCH'));
return false;
}
$this->password_clear = JArrayHelper::getValue($array, 'password', '', 'string');
$array['password'] = JUserHelper::hashPassword($array['password']);
// Set the registration timestamp
$this->set('registerDate', JFactory::getDate()->toSql());
// Check that username is not greater than 150 characters
$username = $this->get('username');
if (strlen($username) > 150)
{
$username = substr($username, 0, 150);
$this->set('username', $username);
}
// Check that password is not greater than 100 characters
$password = $this->get('password');
if (strlen($password) > 100)
{
$password = substr($password, 0, 100);
$this->set('password', $password);
}
}
else
{
// Updating an existing user
if (!empty($array['password']))
{
if ($array['password'] != $array['password2'])
{
$this->setError(JText::_('JLIB_USER_ERROR_PASSWORD_NOT_MATCH'));
return false;
}
$this->password_clear = JArrayHelper::getValue($array, 'password', '', 'string');
$array['password'] = JUserHelper::hashPassword($array['password']);
}
else
{
$array['password'] = $this->password;
}
}
// TODO: this will be deprecated as of the ACL implementation
// $db = JFactory::getDbo();
if (array_key_exists('params', $array))
{
$params = '';
$this->_params->loadArray($array['params']);
if (is_array($array['params']))
{
$params = (string) $this->_params;
}
else
{
$params = $array['params'];
}
$this->params = $params;
}
// Bind the array
if (!$this->setProperties($array))
{
$this->setError(JText::_('JLIB_USER_ERROR_BIND_ARRAY'));
return false;
}
// Make sure its an integer
$this->id = (int) $this->id;
return true;
}
/**
* Method to save the JUser object to the database
*
* @param boolean $updateOnly Save the object only if not a new user
* Currently only used in the user reset password method.
*
* @return boolean True on success
*
* @since 11.1
* @throws exception
*/
public function save($updateOnly = false)
{
// Create the user table object
$table = $this->getTable();
$this->params = (string) $this->_params;
$table->bind($this->getProperties());
// Allow an exception to be thrown.
try
{
// Check and store the object.
if (!$table->check())
{
$this->setError($table->getError());
return false;
}
// If user is made a Super Admin group and user is NOT a Super Admin
//
// @todo ACL - this needs to be acl checked
//
$my = JFactory::getUser();
//are we creating a new user
$isNew = empty($this->id);
// If we aren't allowed to create new users return
if ($isNew && $updateOnly)
{
return true;
}
// Get the old user
$oldUser = new JUser($this->id);
//
// Access Checks
//
// The only mandatory check is that only Super Admins can operate on other Super Admin accounts.
// To add additional business rules, use a user plugin and throw an Exception with onUserBeforeSave.
// Check if I am a Super Admin
$iAmSuperAdmin = $my->authorise('core.admin');
$iAmRehashingSuperadmin = false;
if (($my->id == 0 && !$isNew) && $this->id == $oldUser->id && $oldUser->authorise('core.admin') && $oldUser->password != $this->password)
{
$iAmRehashingSuperadmin = true;
}
// We are only worried about edits to this account if I am not a Super Admin.
if ($iAmSuperAdmin != true && $iAmRehashingSuperadmin != true)
{
if ($isNew)
{
// Check if the new user is being put into a Super Admin group.
foreach ($this->groups as $groupId)
{
if (JAccess::checkGroup($groupId, 'core.admin'))
{
throw new Exception(JText::_('JLIB_USER_ERROR_NOT_SUPERADMIN'));
}
}
}
else
{
// I am not a Super Admin, and this one is, so fail.
if (JAccess::check($this->id, 'core.admin'))
{
throw new Exception(JText::_('JLIB_USER_ERROR_NOT_SUPERADMIN'));
}
if ($this->groups != null)
{
// I am not a Super Admin and I'm trying to make one.
foreach ($this->groups as $groupId)
{
if (JAccess::checkGroup($groupId, 'core.admin'))
{
throw new Exception(JText::_('JLIB_USER_ERROR_NOT_SUPERADMIN'));
}
}
}
}
}
// Fire the onUserBeforeSave event.
JPluginHelper::importPlugin('user');
$dispatcher = JDispatcher::getInstance();
$result = $dispatcher->trigger('onUserBeforeSave', array($oldUser->getProperties(), $isNew, $this->getProperties()));
if (in_array(false, $result, true))
{
// Plugin will have to raise its own error or throw an exception.
return false;
}
// Store the user data in the database
if (!($result = $table->store()))
{
throw new Exception($table->getError());
}
// Set the id for the JUser object in case we created a new user.
if (empty($this->id))
{
$this->id = $table->get('id');
}
if ($my->id == $table->id)
{
$registry = new JRegistry;
$registry->loadString($table->params);
$my->setParameters($registry);
}
// Fire the onUserAfterSave event
$dispatcher->trigger('onUserAfterSave', array($this->getProperties(), $isNew, $result, $this->getError()));
}
catch (Exception $e)
{
$this->setError($e->getMessage());
return false;
}
return $result;
}
/**
* Method to delete the JUser object from the database
*
* @return boolean True on success
*
* @since 11.1
*/
public function delete()
{
JPluginHelper::importPlugin('user');
// Trigger the onUserBeforeDelete event
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('onUserBeforeDelete', array($this->getProperties()));
// Create the user table object
$table = $this->getTable();
$result = false;
if (!$result = $table->delete($this->id))
{
$this->setError($table->getError());
}
// Trigger the onUserAfterDelete event
$dispatcher->trigger('onUserAfterDelete', array($this->getProperties(), $result, $this->getError()));
return $result;
}
/**
* Method to load a JUser object by user id number
*
* @param mixed $id The user id of the user to load
*
* @return boolean True on success
*
* @since 11.1
*/
public function load($id)
{
// Create the user table object
$table = $this->getTable();
// Load the JUserModel object based on the user id or throw a warning.
if (!$table->load($id))
{
JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('JLIB_USER_ERROR_UNABLE_TO_LOAD_USER', $id));
return false;
}
// Set the user parameters using the default XML file. We might want to
// extend this in the future to allow for the ability to have custom
// user parameters, but for right now we'll leave it how it is.
$this->_params->loadString($table->params);
// Assuming all is well at this point lets bind the data
$this->setProperties($table->getProperties());
return true;
}
}
PK ?\V
index.htmlnu W+A
PK ?\V profile/fields/index.htmlnu W+A
PK ?\) profile/fields/.htaccessnu W+A
Order allow,deny
Deny from all
PK ?\%;|
|
profile/fields/tos.phpnu W+A hidden)
{
return $label;
}
// Get the label text from the XML element, defaulting to the element name.
$text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
$text = $this->translateLabel ? JText::_($text) : $text;
// Set required to true as this field is not displayed at all if not required.
$this->required = true;
// Add CSS and JS for the TOS field
$doc = JFactory::getDocument();
$css = "#jform_profile_tos {width: 18em; margin: 0 !important; padding: 0 2px !important;}
#jform_profile_tos input {margin:0 5px 0 0 !important; width:10px !important;}
#jform_profile_tos label {margin:0 15px 0 0 !important; width:auto;}
";
$doc->addStyleDeclaration($css);
JHtml::_('behavior.modal');
// Build the class for the label.
$class = !empty($this->description) ? 'hasTip' : '';
$class =$class . ' required';
$class = !empty($this->labelClass) ? $class . ' ' . $this->labelClass : $class;
// Add the opening label tag and main attributes attributes.
$label .= '';
return $label;
}
}
PK ?\) profile/profiles/.htaccessnu W+A
Order allow,deny
Deny from all
PK ?\k k profile/profiles/profile.xmlnu W+A
PK ?\V profile/profiles/index.htmlnu W+A
PK ?\V profile/index.htmlnu W+A
PK ?\۫(" " profile/profile.xmlnu W+A
plg_user_profileJoomla! ProjectJanuary 2008(C) 2005 - 2014 Open Source Matters. All rights reserved.GNU General Public License version 2 or later; see LICENSE.txtadmin@joomla.orgwww.joomla.org2.5.0PLG_USER_PROFILE_XML_DESCRIPTIONprofile.phpindex.htmlprofilesen-GB.plg_user_profile.inien-GB.plg_user_profile.sys.ini
PK ?\6.I I profile/profile.phpnu W+A loadLanguage();
JFormHelper::addFieldPath(dirname(__FILE__) . '/fields');
}
/**
* @param string $context The context for the data
* @param int $data The user id
* @param object
*
* @return boolean
* @since 1.6
*/
function onContentPrepareData($context, $data)
{
// Check we are manipulating a valid form.
if (!in_array($context, array('com_users.profile', 'com_users.user', 'com_users.registration', 'com_admin.profile')))
{
return true;
}
if (is_object($data))
{
$userId = isset($data->id) ? $data->id : 0;
if (!isset($data->profile) and $userId > 0)
{
// Load the profile data from the database.
$db = JFactory::getDbo();
$db->setQuery(
'SELECT profile_key, profile_value FROM #__user_profiles' .
' WHERE user_id = '.(int) $userId." AND profile_key LIKE 'profile.%'" .
' ORDER BY ordering'
);
$results = $db->loadRowList();
// Check for a database error.
if ($db->getErrorNum())
{
$this->_subject->setError($db->getErrorMsg());
return false;
}
// Merge the profile data.
$data->profile = array();
foreach ($results as $v)
{
$k = str_replace('profile.', '', $v[0]);
$data->profile[$k] = json_decode($v[1], true);
if ($data->profile[$k] === null)
{
$data->profile[$k] = $v[1];
}
}
}
if (!JHtml::isRegistered('users.url'))
{
JHtml::register('users.url', array(__CLASS__, 'url'));
}
if (!JHtml::isRegistered('users.calendar'))
{
JHtml::register('users.calendar', array(__CLASS__, 'calendar'));
}
if (!JHtml::isRegistered('users.tos'))
{
JHtml::register('users.tos', array(__CLASS__, 'tos'));
}
}
return true;
}
public static function url($value)
{
if (empty($value))
{
return JHtml::_('users.value', $value);
}
else
{
$value = htmlspecialchars($value);
if (substr ($value, 0, 4) == "http")
{
return ''.$value.'';
}
else
{
return ''.$value.'';
}
}
}
public static function calendar($value)
{
if (empty($value))
{
return JHtml::_('users.value', $value);
}
else
{
return JHtml::_('date', $value, null, null);
}
}
public static function tos($value)
{
if ($value)
{
return JText::_('JYES');
}
else
{
return JText::_('JNO');
}
}
/**
* @param JForm $form The form to be altered.
* @param array $data The associated data for the form.
*
* @return boolean
* @since 1.6
*/
function onContentPrepareForm($form, $data)
{
if (!($form instanceof JForm))
{
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check we are manipulating a valid form.
$name = $form->getName();
if (!in_array($name, array('com_admin.profile', 'com_users.user', 'com_users.profile', 'com_users.registration')))
{
return true;
}
// Add the registration fields to the form.
JForm::addFormPath(dirname(__FILE__) . '/profiles');
$form->loadFile('profile', false);
$fields = array(
'address1',
'address2',
'city',
'region',
'country',
'postal_code',
'phone',
'website',
'favoritebook',
'aboutme',
'dob',
'tos',
);
$tosarticle = $this->params->get('register_tos_article');
$tosenabled = $this->params->get('register-require_tos', 0);
// We need to be in the registration form, field needs to be enabled and we need an article ID
if ($name != 'com_users.registration' || !$tosenabled || !$tosarticle)
{
// We only want the TOS in the registration form
$form->removeField('tos', 'profile');
}
else
{
// Push the TOS article ID into the TOS field.
$form->setFieldAttribute('tos', 'article', $tosarticle, 'profile');
}
foreach ($fields as $field)
{
// Case using the users manager in admin
if ($name == 'com_users.user')
{
// Remove the field if it is disabled in registration and profile
if ($this->params->get('register-require_' . $field, 1) == 0
&& $this->params->get('profile-require_' . $field, 1) == 0)
{
$form->removeField($field, 'profile');
}
}
// Case registration
elseif ($name == 'com_users.registration')
{
// Toggle whether the field is required.
if ($this->params->get('register-require_' . $field, 1) > 0)
{
$form->setFieldAttribute($field, 'required', ($this->params->get('register-require_' . $field) == 2) ? 'required' : '', 'profile');
}
else
{
$form->removeField($field, 'profile');
}
}
// Case profile in site or admin
elseif ($name == 'com_users.profile' || $name == 'com_admin.profile')
{
// Toggle whether the field is required.
if ($this->params->get('profile-require_' . $field, 1) > 0)
{
$form->setFieldAttribute($field, 'required', ($this->params->get('profile-require_' . $field) == 2) ? 'required' : '', 'profile');
}
else
{
$form->removeField($field, 'profile');
}
}
}
return true;
}
function onUserAfterSave($data, $isNew, $result, $error)
{
$userId = JArrayHelper::getValue($data, 'id', 0, 'int');
if ($userId && $result && isset($data['profile']) && (count($data['profile'])))
{
try
{
//Sanitize the date
if (!empty($data['profile']['dob']))
{
$date = new JDate($data['profile']['dob']);
$data['profile']['dob'] = $date->format('Y-m-d');
}
$db = JFactory::getDbo();
$db->setQuery(
'DELETE FROM #__user_profiles WHERE user_id = '.$userId .
" AND profile_key LIKE 'profile.%'"
);
if (!$db->query())
{
throw new Exception($db->getErrorMsg());
}
$tuples = array();
$order = 1;
foreach ($data['profile'] as $k => $v)
{
$tuples[] = '('.$userId.', '.$db->quote('profile.'.$k).', '.$db->quote(json_encode($v)).', '.$order++.')';
}
$db->setQuery('INSERT INTO #__user_profiles VALUES '.implode(', ', $tuples));
if (!$db->query())
{
throw new Exception($db->getErrorMsg());
}
}
catch (JException $e)
{
$this->_subject->setError($e->getMessage());
return false;
}
}
return true;
}
/**
* Remove all user profile information for the given user ID
*
* Method is called after user data is deleted from the database
*
* @param array $user Holds the user data
* @param boolean $success True if user was succesfully stored in the database
* @param string $msg Message
*/
function onUserAfterDelete($user, $success, $msg)
{
if (!$success)
{
return false;
}
$userId = JArrayHelper::getValue($user, 'id', 0, 'int');
if ($userId)
{
try
{
$db = JFactory::getDbo();
$db->setQuery(
'DELETE FROM #__user_profiles WHERE user_id = '.$userId .
" AND profile_key LIKE 'profile.%'"
);
if (!$db->query())
{
throw new Exception($db->getErrorMsg());
}
}
catch (JException $e)
{
$this->_subject->setError($e->getMessage());
return false;
}
}
return true;
}
}
PK ?\) profile/.htaccessnu W+A
Order allow,deny
Deny from all
PK ?\V joomla/index.htmlnu W+A
PK ?\) joomla/.htaccessnu W+A
Order allow,deny
Deny from all
PK ?\j joomla/joomla.phpnu W+A setQuery(
'DELETE FROM '.$db->quoteName('#__session') .
' WHERE '.$db->quoteName('userid').' = '.(int) $user['id']
);
$db->Query();
return true;
}
/**
* Utility method to act on a user after it has been saved.
*
* This method sends a registration email to new users created in the backend.
*
* @param array $user Holds the new user data.
* @param boolean $isnew True if a new user is stored.
* @param boolean $success True if user was succesfully stored in the database.
* @param string $msg Message.
*
* @return void
* @since 1.6
*/
public function onUserAfterSave($user, $isnew, $success, $msg)
{
// Initialise variables.
$app = JFactory::getApplication();
$config = JFactory::getConfig();
$mail_to_user = $this->params->get('mail_to_user', 1);
if ($isnew) {
// TODO: Suck in the frontend registration emails here as well. Job for a rainy day.
if ($app->isAdmin()) {
if ($mail_to_user)
{
$lang = JFactory::getLanguage();
$defaultLocale = $lang->getTag();
/**
* Look for user language. Priority:
* 1. User frontend language
* 2. User backend language
*/
$userParams = new JRegistry($user['params']);
$userLocale = $userParams->get('language', $userParams->get('admin_language', $defaultLocale));
if ($userLocale != $defaultLocale)
{
$lang->setLanguage($userLocale);
}
$lang->load('plg_user_joomla', JPATH_ADMINISTRATOR);
// Compute the mail subject.
$emailSubject = JText::sprintf(
'PLG_USER_JOOMLA_NEW_USER_EMAIL_SUBJECT',
$user['name'],
$config->get('sitename')
);
// Compute the mail body.
$emailBody = JText::sprintf(
'PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY',
$user['name'],
$config->get('sitename'),
JUri::root(),
$user['username'],
$user['password_clear']
);
// Assemble the email data...the sexy way!
$mail = JFactory::getMailer()
->setSender(
array(
$config->get('mailfrom'),
$config->get('fromname')
)
)
->addRecipient($user['email'])
->setSubject($emailSubject)
->setBody($emailBody);
// Set application language back to default if we changed it
if ($userLocale != $defaultLocale)
{
$lang->setLanguage($defaultLocale);
}
if (!$mail->Send()) {
// TODO: Probably should raise a plugin error but this event is not error checked.
JError::raiseWarning(500, JText::_('ERROR_SENDING_EMAIL'));
}
}
}
}
else {
// Existing user - nothing to do...yet.
}
}
/**
* This method should handle any login logic and report back to the subject
*
* @param array $user Holds the user data
* @param array $options Array holding options (remember, autoregister, group)
*
* @return boolean True on success
* @since 1.5
*/
public function onUserLogin($user, $options = array())
{
$instance = $this->_getUser($user, $options);
// If _getUser returned an error, then pass it back.
if ($instance instanceof Exception) {
return false;
}
// If the user is blocked, redirect with an error
if ($instance->get('block') == 1) {
JError::raiseWarning('SOME_ERROR_CODE', JText::_('JERROR_NOLOGIN_BLOCKED'));
return false;
}
// Authorise the user based on the group information
if (!isset($options['group'])) {
$options['group'] = 'USERS';
}
// Chek the user can login.
$result = $instance->authorise($options['action']);
if (!$result) {
JError::raiseWarning(401, JText::_('JERROR_LOGIN_DENIED'));
return false;
}
// Mark the user as logged in
$instance->set('guest', 0);
// Register the needed session variables
$session = JFactory::getSession();
$session->set('user', $instance);
$db = JFactory::getDBO();
// Check to see the the session already exists.
$app = JFactory::getApplication();
$app->checkSession();
// Update the user related fields for the Joomla sessions table.
$db->setQuery(
'UPDATE '.$db->quoteName('#__session') .
' SET '.$db->quoteName('guest').' = '.$db->quote($instance->get('guest')).',' .
' '.$db->quoteName('username').' = '.$db->quote($instance->get('username')).',' .
' '.$db->quoteName('userid').' = '.(int) $instance->get('id') .
' WHERE '.$db->quoteName('session_id').' = '.$db->quote($session->getId())
);
$db->query();
// Hit the user last visit field
$instance->setLastVisit();
return true;
}
/**
* This method should handle any logout logic and report back to the subject
*
* @param array $user Holds the user data.
* @param array $options Array holding options (client, ...).
*
* @return object True on success
* @since 1.5
*/
public function onUserLogout($user, $options = array())
{
$my = JFactory::getUser();
$session = JFactory::getSession();
$app = JFactory::getApplication();
// Make sure we're a valid user first
if ($user['id'] == 0 && !$my->get('tmp_user')) {
return true;
}
// Check to see if we're deleting the current session
if ($my->get('id') == $user['id'] && $options['clientid'] == $app->getClientId()) {
// Hit the user last visit field
$my->setLastVisit();
// Destroy the php session for this user
$session->destroy();
}
// Force logout all users with that userid
$db = JFactory::getDBO();
$db->setQuery(
'DELETE FROM '.$db->quoteName('#__session') .
' WHERE '.$db->quoteName('userid').' = '.(int) $user['id'] .
' AND '.$db->quoteName('client_id').' = '.(int) $options['clientid']
);
$db->query();
return true;
}
/**
* This method will return a user object
*
* If options['autoregister'] is true, if the user doesn't exist yet he will be created
*
* @param array $user Holds the user data.
* @param array $options Array holding options (remember, autoregister, group).
*
* @return object A JUser object
* @since 1.5
*/
protected function _getUser($user, $options = array())
{
$instance = JUser::getInstance();
if ($id = intval(JUserHelper::getUserId($user['username']))) {
$instance->load($id);
return $instance;
}
//TODO : move this out of the plugin
jimport('joomla.application.component.helper');
$config = JComponentHelper::getParams('com_users');
// Default to Registered.
$defaultUserGroup = $config->get('new_usertype', 2);
$acl = JFactory::getACL();
$instance->set('id' , 0);
$instance->set('name' , $user['fullname']);
$instance->set('username' , $user['username']);
$instance->set('password_clear' , $user['password_clear']);
$instance->set('email' , $user['email']); // Result should contain an email (check)
$instance->set('usertype' , 'deprecated');
$instance->set('groups' , array($defaultUserGroup));
//If autoregister is set let's register the user
$autoregister = isset($options['autoregister']) ? $options['autoregister'] : $this->params->get('autoregister', 1);
if ($autoregister) {
if (!$instance->save()) {
return JError::raiseWarning('SOME_ERROR_CODE', $instance->getError());
}
}
else {
// No existing user and autoregister off, this is a temporary user.
$instance->set('tmp_user', true);
}
return $instance;
}
}
PK ?\)Lu joomla/joomla.xmlnu W+A
plg_user_joomlaJoomla! ProjectDecember 2006(C) 2005 - 2009 Open Source Matters. All rights reserved.GNU General Public License version 2 or later; see LICENSE.txtadmin@joomla.orgwww.joomla.org2.5.0PLG_USER_JOOMLA_XML_DESCRIPTIONjoomla.phpindex.htmlen-GB.plg_user_joomla.inien-GB.plg_user_joomla.sys.ini
PK ?\) contactcreator/.htaccessnu W+A
Order allow,deny
Deny from all
PK ?\V contactcreator/index.htmlnu W+A
PK ?\j3= = ! contactcreator/contactcreator.phpnu W+A loadLanguage();
}
function onUserAfterSave($user, $isnew, $success, $msg)
{
if(!$success) {
return false; // if the user wasn't stored we don't resync
}
if(!$isnew) {
return false; // if the user isn't new we don't sync
}
// ensure the user id is really an int
$user_id = (int)$user['id'];
if (empty($user_id)) {
die('invalid userid');
return false; // if the user id appears invalid then bail out just in case
}
$category = $this->params->get('category', 0);
if (empty($category)) {
JError::raiseWarning(41, JText::_('PLG_CONTACTCREATOR_ERR_NO_CATEGORY'));
return false; // bail out if we don't have a category
}
$dbo = JFactory::getDBO();
// grab the contact ID for this user; note $user_id is cleaned above
$dbo->setQuery('SELECT id FROM #__contact_details WHERE user_id = '. $user_id );
$id = $dbo->loadResult();
JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_contact/tables');
$contact = JTable::getInstance('contact', 'ContactTable');
if (!$contact) {
return false;
}
if ($id) {
$contact->load($id);
}
elseif($this->params->get('autopublish', 0)) {
$contact->published = 1;
}
$contact->name = $user['name'];
$contact->user_id = $user_id;
$contact->email_to = $user['email'];
$contact->catid = $category;
$contact->language = '*';
// check for already existing alias
$table = JTable::getInstance('contact', 'ContactTable');
$contact->alias = JApplication::stringURLSafe($contact->name);
while ($table->load(array('alias' => $contact->alias, 'catid' => $contact->catid)))
{
$contact->alias = JString::increment($contact->alias, 'dash');
}
$autowebpage = $this->params->get('autowebpage', '');
if (!empty($autowebpage)) {
// search terms
$search_array = array('[name]', '[username]', '[userid]', '[email]');
// replacement terms, urlencoded
$replace_array = array_map('urlencode', array($user['name'], $user['username'], $user['id'], $user['email']));
// now replace it in together
$contact->webpage = str_replace($search_array, $replace_array, $autowebpage);
}
if ($contact->check()) {
$result = $contact->store();
}
if (!(isset($result)) || !$result) {
JError::raiseError(42, JText::sprintf('PLG_CONTACTCREATOR_ERR_FAILED_UPDATE', $contact->getError()));
}
}
}
PK ?\> ! contactcreator/contactcreator.xmlnu W+A
plg_user_contactcreatorJoomla! ProjectAugust 2009(C) 2005 - 2014 Open Source Matters. All rights reserved.GNU General Public License version 2 or later; see LICENSE.txtadmin@joomla.orgwww.joomla.org2.5.0PLG_CONTACTCREATOR_XML_DESCRIPTIONcontactcreator.phpindex.htmlen-GB.plg_user_contactcreator.inien-GB.plg_user_contactcreator.sys.ini
PK ?\UD4d* d* authentication.phpnu W+A PK ?\) * .htaccessnu W+A PK ?\π5B 5B
^+ helper.phpnu W+A PK ?\P P m user.phpnu W+A PK ?\V
index.htmlnu W+A PK ?\V profile/fields/index.htmlnu W+A PK ?\) l profile/fields/.htaccessnu W+A PK ?\%;|
|
3 profile/fields/tos.phpnu W+A PK ?\) profile/profiles/.htaccessnu W+A PK ?\k k profile/profiles/profile.xmlnu W+A PK ?\V u profile/profiles/index.htmlnu W+A PK ?\V profile/index.htmlnu W+A PK ?\۫(" " @ profile/profile.xmlnu W+A PK ?\6.I I ` profile/profile.phpnu W+A PK ?\) profile/.htaccessnu W+A PK ?\V joomla/index.htmlnu W+A PK ?\) joomla/.htaccessnu W+A PK ?\j joomla/joomla.phpnu W+A PK ?\)Lu < joomla/joomla.xmlnu W+A PK ?\) B contactcreator/.htaccessnu W+A PK ?\V ]C contactcreator/index.htmlnu W+A PK ?\j3= = ! C contactcreator/contactcreator.phpnu W+A PK ?\> ! SP contactcreator/contactcreator.xmlnu W+A PK V