Programmatically register a user

Permalink 1 user found helpful
I want to programmatically register new users. I set up paypal subscriptions and IPN processing. Paypal sends me back automatically created usernames and passwords. I want to register these and assign them to a premium users group. This way users who buy a subscription will instantly have access to premium content. I'm new to php and web development so I'm not sure where to start.

Thanks.

 
Remo replied on at Permalink Best Answer Reply
Remo
that's easy. Here's a sample:

$userData['uName'] = 'username';
$userData['uEmail'] = 'mailaddress';
$userData['uPassword'] = 'password';
$userData['uPasswordConfirm'] = 'password';
$ui = UserInfo::register($userData);
// assign the new user to a group
$g = Group::getByName('Administrators');
$u = $ui->getUserObject();
$u->enterGroup($g);
jakem replied on at Permalink Reply
Thanks! I figured it was as simple as sending a form. So I can just stick that in the php file that handles the IPN message? Does it automatically know what UserInfo is or do I need to import that somehow?
Remo replied on at Permalink Reply
Remo
Well, I have no clue how you call your PHP script but in general (with concrete5): Never call a PHP script directly! Put it in the tools directory and call it like /index.php/tools/your_tool
jakem replied on at Permalink Reply
That works perfectly. Is there a way to specify the groups the user should belong to?
$userData['uGroups'] = ['registered','premium'] // ?
Remo replied on at Permalink Reply
Remo
I've updated the post above so we have everything in one post
gmurillo replied on at Permalink Reply
Hi Remo,
Sorry to take this post to my own question.
My problem is that's code don't works outside concrete5, or well I don't know to use it.
In my case, I have a php program to add a new user to another system, and I need to add this same user to the concrete5 system to have in both the same user, and when the user do login in my concrete5 site, he can to use my app's in the other system, that I have to include in my concrete5 with a addon iframe type.
I don't know if I can explain my case clearly?
Thanks for patient!
johandalabacka replied on at Permalink Reply
johandalabacka