[Solved]Can I add a new user through PHP code?

14 years 1 month ago #126895 by djc
I am designing a system where a client buys my product, then gets access to members side of the site through CB login. Is there a standard way to create the user through a PHP script when the product is purchased.
I did find this script on the CBSubs forum, but can't make it work, perhaps it only works in CBSubs.
function registerUser( $fname, $lname, $email, $username, $password, $plan_id ) {
global $_CB_framework, $_CB_database;

$row = new moscomprofilerUser( $_CB_database );
$row->usertype = $_CB_framework->getCfg( 'new_usertype' );
$row->gid = $_CB_framework->acl->get_group_id( $row->usertype, 'ARO' );
$row->confirmed = 1;
$row->approved = 1;
$row->block = 0;
$row->sendEmail = 0;
$row->registerDate = date( 'Y-m-d H:i:s', $_CB_framework->now() );
$row->name = $fname . ' ' . $lname;
$row->first_name = $fname;
$row->last_name = $lname;
$row->username = $username;
$row->email = $email;
$row->password = cbHashPassword( $password );

if ( ! $row->store() ) {
trigger_error( 'Add User SQL error: ' . $row->getError(), E_USER_ERROR );
}
}

Thanks for any input!
Dom

Post edited by: djc, at: 2010/03/16 21:33

Post edited by: djc, at: 2010/03/16 22:35

Post edited by: djc, at: 2010/03/17 16:34

Please Log in to join the conversation.

14 years 1 month ago #126951 by krileon
Replied by krileon on topic Re:Can I add a new user through PHP code?
That indeed will create a user, but you need to load the CB API first before you can use the CB API. See tutorials in my signature for how to load the CB API.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

14 years 1 month ago #127016 by djc
Thank you for your help. I got the code from your tutorials on loading the CB API. However, I must be missing something because there seems to be a problem creating the moscomprofilerUser structure as the code never continues from there.

Any other suggestions?
Dom

Please Log in to join the conversation.

14 years 1 month ago #127018 by djc
Wait....I think I got it...I forgot to cbimport(cb.html)

THANKS.

Please Log in to join the conversation.

14 years 1 month ago #127023 by djc
I thought it was solved, but I am still missing something.
The user is created, but without a first name or last name when I go into CB user management.
Also, even though I sent confirmed & approved to 1, the user comes back not confirmed and pending approval in the CB user management.

What other steps am I missing?

Thank you,
Dom

Please Log in to join the conversation.

14 years 1 month ago #127092 by krileon
Replied by krileon on topic Re:Can I add a new user through PHP code?
Don't know what to tell you, that's the API; it's up to you to determine its usage and debug your code. We don't debug 3PD (3rd party development), sorry. Check that you're not just using the example straight as is; all code provided via forum is generally an EXAMPLE which means you need to edit it to meet your needs. Such as $fname, it actually needs to be defined.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.222 seconds

Facebook Twitter LinkedIn