The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Wed Sep 17, 2008 6:14 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Jul 26, 2008 4:45 am
Posts: 5
Location: Vancouver Island, Canada
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


Top
 Profile  
 
PostPosted: Fri Sep 19, 2008 4:05 am 
Joomla! Explorer
Joomla! Explorer

Joined: Mon Aug 04, 2008 8:00 am
Posts: 293
Location: India
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

_________________
Sumeet Shroff
PSD to Joomla, Joomla Custom Template Design and Virtuemart Shopping Cart
http://www.prateeksha.com http://www.prateekshawebdesign.com


Top
 Profile  
 
PostPosted: Fri Sep 19, 2008 4:08 am 
Joomla! Explorer
Joomla! Explorer

Joined: Mon Aug 04, 2008 8:00 am
Posts: 293
Location: India
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.

_________________
Sumeet Shroff
PSD to Joomla, Joomla Custom Template Design and Virtuemart Shopping Cart
http://www.prateeksha.com http://www.prateekshawebdesign.com


Top
 Profile  
 
PostPosted: Wed Sep 24, 2008 12:12 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Jul 26, 2008 4:45 am
Posts: 5
Location: Vancouver Island, Canada
Great, thanks for the info, I think I'm starting to get a handle on this :)


Top
 Profile  
 
PostPosted: Fri Jan 02, 2009 1:29 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Oct 26, 2007 2:11 pm
Posts: 12
prateekshaweb wrote:
however you should avoid making changes to the user table.. it will cause problems


As I often need to bulk add users,
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! :p


Top
 Profile  
 
PostPosted: Fri Jan 02, 2009 2:54 am 
Joomla! Explorer
Joomla! Explorer

Joined: Mon Aug 04, 2008 8:00 am
Posts: 293
Location: India
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

_________________
Sumeet Shroff
PSD to Joomla, Joomla Custom Template Design and Virtuemart Shopping Cart
http://www.prateeksha.com http://www.prateekshawebdesign.com


Top
 Profile  
 
PostPosted: Mon Apr 19, 2010 11:12 am 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Tue Jun 10, 2008 10:57 am
Posts: 74
Location: Dallas, TX (since Feb 09) - Prev London, UK
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

Code:
$insertFields = "INSERT INTO jos_users(name, email, password, username, usertype, gid, registerDate) VALUES('$name','$email', '$password2', '$email', '$usertype', '$gid', '$registerDate')"
;

k98514700 wrote:
prateekshaweb wrote:
however you should avoid making changes to the user table.. it will cause problems


As I often need to bulk add users,
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! :p

_________________
Colin Bridges
"Iced Tea with a bucket full of Sugar Please!"


Top
 Profile  
 
PostPosted: Wed May 26, 2010 10:11 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Feb 23, 2010 9:37 pm
Posts: 6
cbridges! i hv exactlly the same prb! did u solve it??


Top
 Profile  
 
PostPosted: Wed Aug 04, 2010 9:08 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Mon Jul 20, 2009 10:05 pm
Posts: 4
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) .


Top
 Profile  
 
PostPosted: Fri Aug 13, 2010 11:22 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Aug 13, 2010 11:19 pm
Posts: 1
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.


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 7:01 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Mon Apr 30, 2012 6:55 pm
Posts: 1
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 :)


Top
 Profile  
 
PostPosted: Tue May 01, 2012 9:59 am 
Joomla! Ace
Joomla! Ace

Joined: Sat Oct 01, 2011 7:06 pm
Posts: 1260
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).
Code:
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'));
This will insert the user as Registered and not as Super user(19) as done above.


Top
 Profile  
 
PostPosted: Fri Jul 06, 2012 6:34 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Mar 09, 2009 11:43 pm
Posts: 11
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:
Code:
$model = &$this->getModel();
$status = $model->makeAccount($data);

$data is a variable that contains all the info:
Code:
$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' => '') ) ;

The function goes in your model:
Code:
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;
   }


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 



Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group