Difference between revisions of "JUser/bind"
From Joomla! Documentation
< API15:JUser
m (removing red link to edit, no existant pages) |
|||
Line 3: | Line 3: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Syntax=== | ===Syntax=== | ||
Line 139: | Line 139: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Examples=== | ===Examples=== | ||
Line 154: | Line 154: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | [[Category:Archived pages API15]] |
Revision as of 13:57, 12 May 2013
The "API15" 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
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
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
$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;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
<CodeExamplesForm />