If you care about using the native api when creating a user then you can use this script.
I took it directly from com_users. For some reason the password comparison (does pass = passver) was in the com_users controller but the rest of the save function in the model. Here is what I put together...
call it like this in your view:
Code:
$model = &$this->getModel();
$status = $model->makeAccount($data);
$data is a variable that contains all the info:
Code:
$data = array('name' => 'ety' ,'username' => 'testing' ,'password' => '','password2' => '','email' => 'rty@dtydfg.gyy' ,'registerDate' => '','lastvisitDate' => '','lastResetTime' => '','resetCount' => 0 ,'sendEmail' => 0 ,'block' => 1 ,'id' => 0 ,'groups' => array( 0 => 2 ) ,'params' => array( 'admin_style' => '','admin_language' => '','language' => '','editor' => '','helpsite' => '','timezone' => '') ) ;
The function goes in your model:
Code:
public function makeAccount($data)
{
if (isset($data['password']) && isset($data['password2']))
{
// Check the passwords match.
if ($data['password'] != $data['password2'])
{
$this->setError(JText::_('JLIB_USER_ERROR_PASSWORD_NOT_MATCH'));
return false;
}
unset($data['password2']);
}
// Initialise variables;
$pk = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('user.id');
$user = JUser::getInstance($pk);
$my = JFactory::getUser();
if ($data['block'] && $pk == $my->id && !$my->block)
{
$this->setError(JText::_('COM_USERS_USERS_ERROR_CANNOT_BLOCK_SELF'));
return false;
}
// Make sure that we are not removing ourself from Super Admin group
$iAmSuperAdmin = $my->authorise('core.admin');
if ($iAmSuperAdmin && $my->get('id') == $pk)
{
// Check that at least one of our new groups is Super Admin
$stillSuperAdmin = false;
$myNewGroups = $data['groups'];
foreach ($myNewGroups as $group)
{
$stillSuperAdmin = ($stillSuperAdmin) ? ($stillSuperAdmin) : JAccess::checkGroup($group, 'core.admin');
}
if (!$stillSuperAdmin)
{
$this->setError(JText::_('COM_USERS_USERS_ERROR_CANNOT_DEMOTE_SELF'));
return false;
}
}
// Bind the data.
if (!$user->bind($data))
{
$this->setError($user->getError());
return false;
}
// Store the data.
if (!$user->save())
{
$this->setError($user->getError());
return false;
}
$this->setState('user.id', $user->id);
return true;
}