How to Create a New Joomla User Account from Within a Script

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

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.

How to create Joomla 3.0 Account using PHP File

I'm not sure about the variables you mention, I answered a similiar question that included the PHP to create an account at Joomla ACL integration.

programmatic joomla user creation conflict with login display

I finally resolved the issue. All I had to do was make sure that once the new user was created I set the $user variable back to the active user data by using JFactory::getUser(). I was really over thinking it. It was only displaying the just created user because after creating the user in our joomla table I had not thought to set it back.

creating new user for joomla in phpmyadmin

You can adjust the values in phpmyadmin with the following query. Please adjust table prefix from jos_ to whatever yours is.

INSERT INTO `jos_users`   (`name`, `username`, `password`, `params`, `registerDate`, `lastvisitDate`, `lastResetTime`)VALUES ('Administrator2', 'admin2',    'd2064d358136996bd22421584a7cb33e:trd7TvKHx6dMeoMmBVxYmg0vuXEA4199', '', NOW(), NOW(), NOW());
INSERT INTO `jos_user_usergroup_map` (`user_id`,`group_id`)VALUES (LAST_INSERT_ID(),'8'); <br/>

How to log into joomla through an external script?

<?php
//http://domain.com/script/script.php?username=username&passwd=password

define( '_JEXEC', 1 );
define('JPATH_BASE', '../' );
define( 'DS', DIRECTORY_SEPARATOR );
require_once('../configuration.php');
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );

/* Create the Application */
$mainframe =& JFactory::getApplication('site');
jimport('joomla.plugin.helper');

$credentials = array();
$credentials['username'] = JRequest::getVar('username', '', 'method', 'username');
$credentials['password'] = JRequest::getVar('passwd', '', 'method', 'passwd');

//perform the login action
$error = $mainframe->login($credentials);
$user = JFactory::getUser();
//now you are logged in

$mainframe->logout();
//now you are logged out

Joomla User creation hooks

Yes, this is possible. You're going to write an user plugin based on user events for plugin system. From your question I believe you want onAfterStoreUser or onBeforeStoreUser event hooks. Check these provided links for official documentation with examples.



Related Topics



Leave a reply



Submit