Code:
<?php
function registerUser( $fullName, $email, $username, $password, $approve = 0, $confirm = 0, $usergroups = array() ) {
global $_CB_framework, $_PLUGINS, $ueConfig, $mainframe ;
if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) ) {
echo 'CB not installed'; return;
}
include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );
cbimport( 'cb.html' );
$approval = ( $approve == 2 ? $ueConfig['reg_admin_approval'] : $approve );
$confirmation = ( $confirm == 2 ? $ueConfig['reg_confirmation'] : $confirm );
$user = new \CB\Database\Table\UserTable();
$user->set( 'username', $username );
$user->set( 'email', $email );
$user->set( 'name', $fullName );
$user->set( 'gids', array( (int) $_CB_framework->getCfg( 'new_usertype' ) ) );
$user->set( 'sendEmail', 0 );
$user->set( 'registerDate', $_CB_framework->getUTCDate() );
$user->set( 'password', $user->hashAndSaltPassword( $password ) );
$user->set( 'registeripaddr', cbGetIPlist() );
if ( $approval == 0 ) {
$user->set( 'approved', 1 );
} else {
$user->set( 'approved', 0 );
}
if ( $confirmation == 0 ) {
$user->set( 'confirmed', 1 );
} else {
$user->set( 'confirmed', 0 );
}
if ( ( $user->get( 'confirmed' ) == 1 ) && ( $user->get( 'approved' ) == 1 ) ) {
$user->set( 'block', 0 );
} else {
$user->set( 'block', 1 );
}
$_PLUGINS->trigger( 'onBeforeUserRegistration', array( &$user, &$user ) );
if ( $user->store() ) {
if ( $user->get( 'confirmed' ) == 0 ) {
$user->store();
}
$messagesToUser = activateUser( $user, 1, 'UserRegistration' );
$_PLUGINS->trigger( 'onAfterUserRegistration', array( &$user, &$user, true ) );
if ( $user->get( 'block' ) == 1 ) {
return false;
} else {
return true;
}
}
return false;
}
/* Fields from form
$form->data['mobil']
$form->data['adresse']
$form->data['post']
date_format( date_create_from_format( 'd-m-Y', $form->data['foedsel'] ), 'Y-m-d' )
$form->data['email']
$form->data['loginname']
$form->data['name']
$form->data['password']
*/
echo 'Navn: '.$form->data['name'].' Email: '.$form->data['email'].' login: '.$form->data['loginname'].' Password: '.$form->data['password'].'<br >';
registerUser( $form->data['name'], $form->data['email'], $form->data['loginname'], $form->data['password'], 0 , 0, 9 );
?>
The only modification is the 'name' variable, as I don't ask for firstname / lastname, but only full name.
the echo statement is there for debugging, and the fields are shown correctly with their content.