Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

Create a user through CB api from external script on joomla folder

  • Hertak
  • Hertak
  • OFFLINE
  • Posts: 386
  • Thanks: 84
  • Karma: 29
10 years 11 months ago - 10 years 11 months ago #237619 by Hertak
Hi the user nikomed
Make a post on Spanish forum here i'm helping with the language i interpretate the post and try to help. I think that i translate are the important part more data are on original post. Now i send the link of this post to nikomed and if i can help tell me.
nikomed said

I follow the tutorial here But i can't make it work.
Don't have any error or something.
Down i paste the modified code

Code:
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; } else{ echo $user->getError(); }
The api seems work because the part
Code:
$_CB_database->setQuery( "SELECT username FROM #__users WHERE username = '$checkusername'"); $usern = $_CB_database->loadResult(); if ($usern) { return "El usuario ya está dado de alta." ; }
works returning the user status. The constant that cause problem is "JLIB_DATABASE_ERROR_PLEASE_ENTER_YOUR_NAME"
What are wrong or how can i test and make it work. Thanks

Last edit: 10 years 11 months ago by Hertak.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48473
  • Thanks: 8281
  • Karma: 1443
10 years 11 months ago #237644 by krileon
The error Joomla is throwing tells you exactly that's wrong. A user is being stored without a name. You must store a user with Name, Username, Email, and Password. There is no exception to this. You can randomly generate Name, Username, and Password as needed, but they must still be added to the user object when creating a user through 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 or Create an account to join the conversation.

  • nikomed
  • nikomed
  • OFFLINE
  • Posts: 92
  • Thanks: 2
  • Karma: 0
10 years 11 months ago #237654 by nikomed
I know.
I have checked all the fields, but the error is the same.

Look my code, I tried to manually enter strings:
Code:
/* Load Joomla */ define('_JEXEC', 1); /* JPATH_BASE and JPATH_CB is defined more up, but is correct */ require( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require( JPATH_BASE .DS. 'libraries' .DS. 'import.php'); $mainframe = \JFactory::getApplication('site'); require_once (JPATH_BASE.DS.'includes'.DS.'framework.php'); include_once( JPATH_CB . '/components/com_comprofiler/plugin.foundation.php' ); cbimport( 'cb.plugins' ); cbimport( 'cb.html' ); cbimport( 'cb.database' ); cbimport( 'language.front' ); cbimport( 'cb.snoopy' ); cbimport( 'cb.imgtoolbox' ); global $_CB_framework, $mainframe, $_PLUGINS, $_CB_database, $ueConfig; // check user $_CB_database->setQuery( "SELECT username FROM #__users WHERE username = '$checkusername'"); $usern = $_CB_database->loadResult(); if ($usern) { return "El usuario ya está dado de alta en la provincia." ; } // API CB register user $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 = 'usuname'; $user->firstname = 'usufirst'; $user->lastname = 'usulast'; $user->username = 'usuuser'; $user->email = 'prueba@prueba.es'; $user->password = 'asdfasdf' ; $user->registeripaddr = '0.0.0.0'; 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; } 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; } else{ echo $user->getError(); }

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48473
  • Thanks: 8281
  • Karma: 1443
10 years 11 months ago #237698 by krileon
Enable debug mode and maximum error reporting then retry. See if there are any fatal errors and if there are then follow the callstack if one is shown to see what's causing the issue. Aside from that I don't know what to tell you as that's a Joomla error. Username and Email must be unique, perhaps the one you're supplying is taken already.


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 or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum