JUser/bind
From Joomla! Documentation
< API16:JUser
The "API16" 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 bind an associative array of data to a user object
Syntax[edit]
bind(&$array)
Parameter Name | Default Value | Description |
---|---|---|
&$array | $array The associative array to bind to the object |
Returns[edit]
boolean True on success
Defined in[edit]
libraries/joomla/user/user.php
Importing[edit]
jimport( 'joomla.user.user' );
Source Body[edit]
function bind(& $array)
{
jimport('joomla.user.helper');
// Lets 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'];
}
if ($array['password'] != $array['password2']) {
$this->setError(JText::_('PASSWORD DO NOT MATCH.'));
return false;
}
$this->password_clear = JArrayHelper::getValue($array, 'password', '', 'string');
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($array['password'], $salt);
$array['password'] = $crypt.':'.$salt;
// Set the registration timestamp
$this->set('registerDate', JFactory::getDate()->toMySQL());
// 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::_('PASSWORD DO NOT MATCH.'));
return false;
}
$this->password_clear = JArrayHelper::getValue($array, 'password', '', 'string');
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($array['password'], $salt);
$array['password'] = $crypt.':'.$salt;
}
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->bind($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("Unable to bind array to user object");
return false;
}
// Make sure its an integer
$this->id = (int) $this->id;
return true;
}
Examples[edit]
Code Examples[edit]