API16:JUser/bind
From Joomla! Documentation
Description
Method to bind an associative array of data to a user object
Syntax
bind(&$array)
| Parameter Name | Default Value | Description |
|---|---|---|
| &$array | $array The associative array to bind to the object |
Returns
boolean True on success
Defined in
libraries/joomla/user/user.php
Importing
jimport( 'joomla.user.user' );
Source Body
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
Code Examples