Advertisement
Add User Manually via php
- nkatt
- Joomla! Apprentice
- Posts: 5
- Joined: Sat Jul 26, 2008 4:45 am
- Location: Vancouver Island, Canada
Add User Manually via php
Hi there,
I am an experienced php coder, but new to Joomla. I'm considering using Joomla for an upcoming project in which an organization needs a membership database, but also wants to have a login for each member so that they can login and view private pages. My hope is to extend the JUser object to add a bunch of custom fields (using something like the User Meta).
I was then thinking that I would create a custom component with a nice user interface for the organizations administrator to update/add members to the membership database. When they add a new member a user account would automatically be created for that member.
Sorry if this is a simple question, but I basically just want to confirm that this type of approach is possible before I go ahead and accept the project. If I create a component for the membership administration, can I manually create new Joomla users via php?
Thanks in advance,
nkatt
I am an experienced php coder, but new to Joomla. I'm considering using Joomla for an upcoming project in which an organization needs a membership database, but also wants to have a login for each member so that they can login and view private pages. My hope is to extend the JUser object to add a bunch of custom fields (using something like the User Meta).
I was then thinking that I would create a custom component with a nice user interface for the organizations administrator to update/add members to the membership database. When they add a new member a user account would automatically be created for that member.
Sorry if this is a simple question, but I basically just want to confirm that this type of approach is possible before I go ahead and accept the project. If I create a component for the membership administration, can I manually create new Joomla users via php?
Thanks in advance,
nkatt
Advertisement
-
- Joomla! Explorer
- Posts: 331
- Joined: Mon Aug 04, 2008 8:00 am
- Location: India
- Contact:
Re: Add User Manually via php
dear nkatt
1. yes.. you can... a lot of components extend the user... namely virutemart for one...
2. check out this book... which has a chapter on extending the user
Learning Joomla! 1.5 Extension Development: Creating Modules, Components, and Plugins with PHP (Paperback) Packt Pub
3. however you should avoid making changes to the user table.. it will cause problems... instead create a new table jos_user_info
4. instead of rewriting the entire component you can use an existing component and hack into it... the component is called com_user in the component directory.
sumeet
1. yes.. you can... a lot of components extend the user... namely virutemart for one...
2. check out this book... which has a chapter on extending the user
Learning Joomla! 1.5 Extension Development: Creating Modules, Components, and Plugins with PHP (Paperback) Packt Pub
3. however you should avoid making changes to the user table.. it will cause problems... instead create a new table jos_user_info
4. instead of rewriting the entire component you can use an existing component and hack into it... the component is called com_user in the component directory.
sumeet
Sumeet Shroff
PSD to Joomla, Joomla Custom Template Design and Virtuemart Shopping Cart
http://www.prateeksha.com http://www.joomlawebsitedesigners.com
PSD to Joomla, Joomla Custom Template Design and Virtuemart Shopping Cart
http://www.prateeksha.com http://www.joomlawebsitedesigners.com
-
- Joomla! Explorer
- Posts: 331
- Joined: Mon Aug 04, 2008 8:00 am
- Location: India
- Contact:
Re: Add User Manually via php
the book is
Mastering Joomla! 1.5 Extension and Framework Development by James Kennard - Packt Publisher
sumeet
Mod note: Please add signature to your profile and not to each post.
Mastering Joomla! 1.5 Extension and Framework Development by James Kennard - Packt Publisher
sumeet
Mod note: Please add signature to your profile and not to each post.
Sumeet Shroff
PSD to Joomla, Joomla Custom Template Design and Virtuemart Shopping Cart
http://www.prateeksha.com http://www.joomlawebsitedesigners.com
PSD to Joomla, Joomla Custom Template Design and Virtuemart Shopping Cart
http://www.prateeksha.com http://www.joomlawebsitedesigners.com
- nkatt
- Joomla! Apprentice
- Posts: 5
- Joined: Sat Jul 26, 2008 4:45 am
- Location: Vancouver Island, Canada
Re: Add User Manually via php
Great, thanks for the info, I think I'm starting to get a handle on this 

-
- Joomla! Apprentice
- Posts: 12
- Joined: Fri Oct 26, 2007 2:11 pm
Re: Add User Manually via php
As I often need to bulk add users,prateekshaweb wrote:however you should avoid making changes to the user table.. it will cause problems
I add users by manipulating these 3 tables :
users
core_acl_aro
core_acl_groups_aro_map
It seems to be working fine. However as you mentioned, there might be problems.
What are the potential problems please?
Thanks!

-
- Joomla! Explorer
- Posts: 331
- Joined: Mon Aug 04, 2008 8:00 am
- Location: India
- Contact:
Re: Add User Manually via php
well....
the potential problems i see is that
1. u will have to change the table structure wherever user table is used. frontend and administration...
2. when u upgrade Joomla..... your hacked files will be overwritten.
sumeet
the potential problems i see is that
1. u will have to change the table structure wherever user table is used. frontend and administration...
2. when u upgrade Joomla..... your hacked files will be overwritten.
sumeet
Sumeet Shroff
PSD to Joomla, Joomla Custom Template Design and Virtuemart Shopping Cart
http://www.prateeksha.com http://www.joomlawebsitedesigners.com
PSD to Joomla, Joomla Custom Template Design and Virtuemart Shopping Cart
http://www.prateeksha.com http://www.joomlawebsitedesigners.com
- cbridges
- Joomla! Intern
- Posts: 74
- Joined: Tue Jun 10, 2008 10:57 am
- Location: Dallas, TX (since Feb 09) - Prev London, UK
Re: Add User Manually via php
I have a php file that receives user data via a URL string and I insert name, email, password, username, usertype, gid and registerDate to jos_users. This works perfectly and I can see the inserted data when I use phpadmin.
However, and as you probably know, I cannot login using the inserted details and the user does not appear in the user manager in the Joomla backend.
So, my question is, what do I need to add to 'core_acl_aro' & 'core_acl_groups_aro_map' so that the new user is successfully generated and can login?
Cheers
;
However, and as you probably know, I cannot login using the inserted details and the user does not appear in the user manager in the Joomla backend.
So, my question is, what do I need to add to 'core_acl_aro' & 'core_acl_groups_aro_map' so that the new user is successfully generated and can login?
Cheers
Code: Select all
$insertFields = "INSERT INTO jos_users(name, email, password, username, usertype, gid, registerDate) VALUES('$name','$email', '$password2', '$email', '$usertype', '$gid', '$registerDate')"
k98514700 wrote:As I often need to bulk add users,prateekshaweb wrote:however you should avoid making changes to the user table.. it will cause problems
I add users by manipulating these 3 tables :
users
core_acl_aro
core_acl_groups_aro_map
It seems to be working fine. However as you mentioned, there might be problems.
What are the potential problems please?
Thanks!
Colin Bridges
"Iced Tea with a bucket full of Sugar Please!"
"Iced Tea with a bucket full of Sugar Please!"
-
- Joomla! Apprentice
- Posts: 6
- Joined: Tue Feb 23, 2010 9:37 pm
Re: Add User Manually via php
cbridges! i hv exactlly the same prb! did u solve it??
-
- Joomla! Fledgling
- Posts: 4
- Joined: Mon Jul 20, 2009 10:05 pm
Re: Add User Manually via php
thanks, enough info to solve this problem, to be more explicit..
1. Create the user record transforming the password with php's md5 function.
2. Create the core_acl_aro record using the new user id
3. Create the core_acl_groups_aro_map record using the new id in cor_acl_aro and the value of group_id depending what joomla role is desired ( ie Super admin, registered, etc) .
1. Create the user record transforming the password with php's md5 function.
2. Create the core_acl_aro record using the new user id
3. Create the core_acl_groups_aro_map record using the new id in cor_acl_aro and the value of group_id depending what joomla role is desired ( ie Super admin, registered, etc) .
-
- Joomla! Fledgling
- Posts: 1
- Joined: Fri Aug 13, 2010 11:19 pm
Re: Add User Manually via php
use PHP's md5() function to encrypt the password
Joomla Users Table:
1. jos_users
2. jos_core_acl_aro
3. jos_core_acl_groups_aro_map
Adding new registered user:
1. Insert into jos_users
- fields are : id( = autoincrement field), username, name, email,
password, gid (18)
- these are compulsory fields to fillup.
2. Insert into jos_core_acl_aro
-fields are : aro_id ( = autoincrement field),
section_value( ”users” ), value(=jos_users.id), name=(=jos_users.name)
3. Insert into jos_core_acl_groups_aro_map
-fields are : group_id ( 18 ), aro_id( =jos_core_acl_aro.aro_id)
I hope that's clear enough. '18' is the registered user.
Joomla Users Table:
1. jos_users
2. jos_core_acl_aro
3. jos_core_acl_groups_aro_map
Adding new registered user:
1. Insert into jos_users
- fields are : id( = autoincrement field), username, name, email,
password, gid (18)
- these are compulsory fields to fillup.
2. Insert into jos_core_acl_aro
-fields are : aro_id ( = autoincrement field),
section_value( ”users” ), value(=jos_users.id), name=(=jos_users.name)
3. Insert into jos_core_acl_groups_aro_map
-fields are : group_id ( 18 ), aro_id( =jos_core_acl_aro.aro_id)
I hope that's clear enough. '18' is the registered user.
-
- Joomla! Fledgling
- Posts: 1
- Joined: Mon Apr 30, 2012 6:55 pm
Re: Add User Manually via php
Inserindo um novo usuário no Joomla 2.5:
1º - Inserir dados de usuários na tabela #__users:
INSERT INTO `#__users` (
`id` ,
`name` ,
`username` ,
`email` ,
`password` ,
`usertype` ,
`block` ,
`sendEmail` ,
`registerDate` ,
`lastvisitDate` ,
`activation` ,
`params`
)
VALUES (
NULL , 'TesteInsercao', 'testando', 'testando@teste.com.br', 'a49366b0d33a0ead9e7b9066bce2a72a:5H2CzNy3mxx5qTPIikVibZlbjeggSEsr', 'deprecated', '0', '1', '2012-04-30 15:12:00', '0000-00-00 00:00:00', '0', '{"editor":"jce","timezone":"","language":"pt-BR","admin_style":"","admin_language":"pt-BR","helpsite":""}'
);
2º - Varrer base para capturar o ID deste usuário recem cadastrado:
"SELECT id, username FROM #__users WHERE email = 'testando@teste.com.br'";
(Neste exemplo retornou "44")
3º - Inserir na tabela #__user_usergroup_map
INSERT INTO `#__user_usergroup_map` (`user_id`, `group_id`) VALUES ('45', '19');
//Observando que o parametro de grupo de usuário registrado agora é "1" (antes no 1.5 era 19)
//basta consultar tabela de grupos #__usergroups
Um abraço
1º - Inserir dados de usuários na tabela #__users:
INSERT INTO `#__users` (
`id` ,
`name` ,
`username` ,
`email` ,
`password` ,
`usertype` ,
`block` ,
`sendEmail` ,
`registerDate` ,
`lastvisitDate` ,
`activation` ,
`params`
)
VALUES (
NULL , 'TesteInsercao', 'testando', 'testando@teste.com.br', 'a49366b0d33a0ead9e7b9066bce2a72a:5H2CzNy3mxx5qTPIikVibZlbjeggSEsr', 'deprecated', '0', '1', '2012-04-30 15:12:00', '0000-00-00 00:00:00', '0', '{"editor":"jce","timezone":"","language":"pt-BR","admin_style":"","admin_language":"pt-BR","helpsite":""}'
);
2º - Varrer base para capturar o ID deste usuário recem cadastrado:
"SELECT id, username FROM #__users WHERE email = 'testando@teste.com.br'";
(Neste exemplo retornou "44")
3º - Inserir na tabela #__user_usergroup_map
INSERT INTO `#__user_usergroup_map` (`user_id`, `group_id`) VALUES ('45', '19');
//Observando que o parametro de grupo de usuário registrado agora é "1" (antes no 1.5 era 19)
//basta consultar tabela de grupos #__usergroups
Um abraço

-
- Joomla! Exemplar
- Posts: 8808
- Joined: Sat Oct 01, 2011 7:06 pm
Re: Add User Manually via php
The code above will not work because of different user_id's (44 & 45). Combining 2 and 3 will resolve problem with different id's (44 & 45).This will insert the user as Registered and not as Super user(19) as done above.
Code: Select all
INSERT INTO `#__user_usergroup_map` (`user_id`, `group_id`)
VALUES ((SELECT id FROM #__users WHERE email = 'testando@teste.com.br'), (SELECT id FROM #__usergroups WHERE title = 'Registered'));
Issue with migrating? Include logs/joomla_update.php in your report!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!
-
- Joomla! Apprentice
- Posts: 11
- Joined: Mon Mar 09, 2009 11:43 pm
Add User Manually via php VIA API THE RIGHT WAY
If you care about using the native api when creating a user then you can use this script.
I took it directly from com_users. For some reason the password comparison (does pass = passver) was in the com_users controller but the rest of the save function in the model. Here is what I put together...
call it like this in your view:
$data is a variable that contains all the info:
The function goes in your model:
I took it directly from com_users. For some reason the password comparison (does pass = passver) was in the com_users controller but the rest of the save function in the model. Here is what I put together...
call it like this in your view:
Code: Select all
$model = &$this->getModel();
$status = $model->makeAccount($data);
Code: Select all
$data = array('name' => 'ety' ,'username' => 'testing' ,'password' => '','password2' => '','email' => 'rty@dtydfg.gyy' ,'registerDate' => '','lastvisitDate' => '','lastResetTime' => '','resetCount' => 0 ,'sendEmail' => 0 ,'block' => 1 ,'id' => 0 ,'groups' => array( 0 => 2 ) ,'params' => array( 'admin_style' => '','admin_language' => '','language' => '','editor' => '','helpsite' => '','timezone' => '') ) ;
Code: Select all
public function makeAccount($data)
{
if (isset($data['password']) && isset($data['password2']))
{
// Check the passwords match.
if ($data['password'] != $data['password2'])
{
$this->setError(JText::_('JLIB_USER_ERROR_PASSWORD_NOT_MATCH'));
return false;
}
unset($data['password2']);
}
// Initialise variables;
$pk = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('user.id');
$user = JUser::getInstance($pk);
$my = JFactory::getUser();
if ($data['block'] && $pk == $my->id && !$my->block)
{
$this->setError(JText::_('COM_USERS_USERS_ERROR_CANNOT_BLOCK_SELF'));
return false;
}
// Make sure that we are not removing ourself from Super Admin group
$iAmSuperAdmin = $my->authorise('core.admin');
if ($iAmSuperAdmin && $my->get('id') == $pk)
{
// Check that at least one of our new groups is Super Admin
$stillSuperAdmin = false;
$myNewGroups = $data['groups'];
foreach ($myNewGroups as $group)
{
$stillSuperAdmin = ($stillSuperAdmin) ? ($stillSuperAdmin) : JAccess::checkGroup($group, 'core.admin');
}
if (!$stillSuperAdmin)
{
$this->setError(JText::_('COM_USERS_USERS_ERROR_CANNOT_DEMOTE_SELF'));
return false;
}
}
// Bind the data.
if (!$user->bind($data))
{
$this->setError($user->getError());
return false;
}
// Store the data.
if (!$user->save())
{
$this->setError($user->getError());
return false;
}
$this->setState('user.id', $user->id);
return true;
}
Advertisement