Hi,

The current approach of directly making an entry in the users_roles table does not work since the user_save function deletes the users_roles table entry before restoring it from the original user options array.

The correct thing to do would be to add the required role to that array (it is passed in the hook) and let user_save do the database entry.

So the current code

function registration_role_user ($op, &$edit, &$user, $category=null)
{
  if ($op == "insert" && $rid = variable_get('registration_role_roles', ''))
  {
    // below does not seem safe!  or necessary for insert. Commented out
    // clear first
    // db_query( 'DELETE FROM {users_roles} WHERE uid = %d', $user->uid );
      db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $user->uid, $rid);
  }
}

should change to

function registration_role_user ($op, &$edit, &$user, $category=null)
{
  if ($op == "insert" && $rid = variable_get('registration_role_roles', ''))
  {
    // below does not seem safe!  or necessary for insert. Commented out
    // clear first
    // db_query( 'DELETE FROM {users_roles} WHERE uid = %d', $user->uid );
      $edit['roles'][$rid] = array();
  }
}      

regards,
Abhaya

CommentFileSizeAuthor
#1 320087_registration_role.patch456 byteschristefano

Comments

christefano’s picture

Priority: Normal » Critical
Status: Active » Needs review
StatusFileSize
new456 bytes

Here's a patch. Let's get this in.

mlncn’s picture

Status: Needs review » Fixed

This has been committed to the Drupal 5 dev branch. I haven't tested it myself, if someone has tested this patch or can test the D5 dev from CVS, I'll make a new release.

Sorry for the slow response here.

benjamin, Agaric Design Collective

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.