How can I create a new Joomla user account from within a script?

Viewed 51384

We're creating an XML API for Joomla that allows partner sites to create new accounts for their users on our website.

We've created a standalone PHP script that processes and validates the API request, but now we need to actually create the new accounts. We were originally thinking about just doing a CURL call to submit the signup form, but we realized that there is an issue with the user token. Is there another clean way to create a user account without going into the guts of Joomla? If we do have to do some surgery, what is the best way to approach it?

12 Answers

You should use Joomla internal classes, like JUser, since there a lot of internal logic such as password salting. Create a custom script that uses the values from the API request and saves the users in the database using methods from Joomla User Classes.

Two ways to add joomla users using your custom code is a wonderful tutorial. The approach works. I've used this approach in some projects.

If you have to access Joomla Framework outside Joomla, check this resource instead.

there is one module called "login module" you can use that module and display it in one of the menu.. in which u will get one link like "new user?" or "create an account" just click on it you will get one registration page with validation..this is just 3-step process to use registration page...it may be helpful to get result faster!!..thanx

Valid for Joomla 3.9.xx If you are working with a separate 3rd party MySQL DB (other that the current DB that Joomla is running in), then you can use the following SQl. Its a bit crude but will get the job of "creating users" done.

INSERT INTO `datph_users` (`id`, `name`, `username`, `email`, `password`, `block`, `sendEmail`, `registerDate`, `lastvisitDate`, `activation`, `params`, `lastResetTime`, `resetCount`, `otpKey`, `otep`, `requireReset`)  VALUES (NULL, 'New Super User', 'newsuperuser', 'newsuperuser@mailinator.com', MD5('newsuperuser'), '0', '1', '2019-09-03 11:59:51', '2020-09-15 15:01:28', '0', '{\"update_cache_list\":1,\"admin_style\":\"\",\"admin_language\":\"\",\"language\":\"\",\"editor\":\"\",\"helpsite\":\"\",\"timezone\":\"\"}', '0000-00-00 00:00:00', '0', '', '', '1');
INSERT INTO `datph_user_usergroup_map` (`user_id`, `group_id`) VALUES (LAST_INSERT_ID(), '8');
  • These are the bare basic necessary details required to have a "user" in Joomla. Remember to update the respective field values accordingly
  • This query will make the CMS ask the user to update the password on first login so its safe in terms of salt and stuff
  • The User Group is set to Super Administrator , you can set to what ever you wish to register the user to.
Related