API15:JUser/bind
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
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 $now =& JFactory::getDate(); $this->set( 'registerDate', $now->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(); $gid = array_key_exists('gid', $array ) ? $array['gid'] : $this->get('gid'); $query = 'SELECT name' . ' FROM #__core_acl_aro_groups' . ' WHERE id = ' . (int) $gid ; $db->setQuery( $query ); $this->set( 'usertype', $db->loadResult()); if ( array_key_exists('params', $array) ) { $params = ''; $this->_params->bind($array['params']); if ( is_array($array['params']) ) { $params = $this->_params->toString(); } 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; }
[Edit See Also] SeeAlso:JUser/bind
Examples
<CodeExamplesForm />
