Hi,
I'm trying to find a way for a user to create several accounts at the same time. In the future this will be subscription-based, I just don't have CB Subs yet but this is the final objective.
I thought I could use this
www.joomlapolis.com/support/tutorials/120-api-usage/18362-registering-a-user-through-cb-api
to trigger additional registrations. The idea is that the person checks a box saying this is a family registration (I want to make family packs), which then reveals a series of hidden fields where you can input additional e-mail addresses. Then I was thinking of having an auto action to create the new accounts based on whether or not those additional fields are filled.
Here's what my auto action looks like so far.
Type: code (PHP eval).
Trigger: onBeforeUserRegistration
ACL: everyone
Condition: [cb_family1] not empty
Code:
Code:
function registerUser( $fname='', $lname='', $email='[cb_family1]', $username='', $password='', $approve = 0, $confirm = 0 ) {
global $_CB_framework, $_CB_database, $ueConfig, $_PLUGINS;
$approval = ( $approve == 2 ? $ueConfig['reg_admin_approval'] : $approve );
$confirmation = ( $confirm == 2 ? $ueConfig['reg_confirmation'] : $confirm );
$usertype = $_CB_framework->getCfg( 'new_usertype' );
$user = new moscomprofilerUser( $_CB_database );
$user->usertype = ( $usertype ? $usertype : 'Registered' );
$user->gid = $_CB_framework->acl->get_group_id( $user->usertype, 'ARO' );
$user->gids = array( $user->gid );
$user->sendEmail = 0;
$user->registerDate = date( 'Y-m-d H:i:s', $_CB_framework->now() );
$user->name = $fname . ' ' . $lname;
$user->firstname = $fname;
$user->lastname = $lname;
$user->username = $username;
$user->email = $email;
$user->password = $user->hashAndSaltPassword( $password );
$user->registeripaddr = cbGetIPlist();
if ( $approval == 0 ) {
$user->approved = 1;
} else {
$user->approved = 0;
}
if ( $confirmation == 0 ) {
$user->confirmed = 1;
} else {
$user->confirmed = 0;
}
if ( ( $user->confirmed == 1 ) && ( $user->approved == 1 ) ) {
$user->block = 0;
} else {
$user->block = 1;
}
$_PLUGINS->trigger( 'onBeforeUserRegistration', array( &$user, &$user ) );
if ( $user->store() ) {
if ( ( $user->confirmed == 0 ) && ( $confirmation != 0 ) ) {
$user->_setActivationCode();
if ( ! $user->store() ) {
return false;
}
}
$_PLUGINS->trigger( 'onAfterUserRegistration', array( &$user, &$user, true ) );
return true;
}
return false;
}
Debugging is one but didn't give me anything so I'm suspecting maybe I did a mistake in my condition? What do you think?
The main account is created just fine, but not the additional one.
Thanks.
Seb.