On registration/edit user data groups file does not change. Only re-edit user profile makes it update.

As i found drupal saves roles data into database after calling hook_user with $op='instert' and $op='update'.

For user/%/edit pages code

    case "after_update": 
      _htpasswdsync_updategroup();
    break;

works well in htpasswdsync_user() function if you add it.

For added users i still need change password to same one and run cron.

Comments

fasdalf@fasdalf.ru’s picture

There is an idea to pass $account object to _htpasswdsync_updategroup function and use it with database valuses.
I'm working on it.

fasdalf@fasdalf.ru’s picture

Status: Active » Needs work
StatusFileSize
new3.51 KB
new24.86 KB
new23.93 KB

Tere is specific patch HTPasswdSync.437904.2.patch for this issue, full path for both this and #437844: PHP error on user/%/delete issues and also modified module.

Works well for me. Bug reports and testers are welcome.

fasdalf@fasdalf.ru’s picture

Modified functions

function _htpasswdsync_updategroup($account=NULL) {
  
  $file = _htpasswdsync_grpfilename();
  $groups = array();
  
  
  // check if user passed to $account
  $acc_name = is_array($account) ? $account['name'] : '';
  $acc_roles = is_array($account) ? $account['roles'] : array();
  // force roles to be integer
  foreach ($acc_roles as $role_rid){
    $role_rid = (int)$role_rid;
  };
  
  foreach (_htpasswdsync_roles() as $rid) {
    // get role name
    $res = db_fetch_object(db_query('SELECT name FROM {role} WHERE rid = %d', $rid));
    $name = $res->name;
    
    //empty group
    $groups[$name] = "";
    
    // add members to the group
    $res = db_query('SELECT name FROM {users} u, {users_roles} ur WHERE ur.rid = %d AND ur.uid = u.uid', $rid);
      while ($r = db_fetch_object($res)) {
        // skip new/changed user
        if ( $acc_name!==$r->name) {
          $groups[$name] .= " ". $r->name;
        };
      }
    if ( in_array((int)$rid, $acc_roles, true) ) {
      $groups[$name] .= " ". $acc_name;
    };

  }

  _htpasswdsync_write_htfile($groups, $file);
 }

Changes in function _htpasswdsync_updategroup():
*account edit form passed as parameter
*removed useless group file loading
*user account used to filter existing values
*unsaved roles appending to HTfile

 function _htpasswdsync_update($account) {
  
  // read current file
  $f = _htpasswdsync_passfilename();
  $passwds = array();
  _htpasswdsync_read_htfile($passwds, $f);
  
  // update with the $account information received
  // password crypted with the standard crypt (not MD5) function
  $user = $account['name'];
  $pass = _htpasswdsync_crypt($account['pass']);
  $passwds[$user] = $pass;
  
  //save file
  _htpasswdsync_write_htfile($passwds, $f);
  
  //update table
  db_query("DELETE FROM {htpasswdsync_passwd} WHERE username = '%s'", $user);
  db_query("INSERT INTO {htpasswdsync_passwd} (username, passwd) VALUES('%s', '%s')", $user, $pass);
  _htpasswdsync_updategroup($account);
}

Changes in function _htpasswdsync_update()
*pass $account to _htpasswdsync_updategroup()

fasdalf@fasdalf.ru’s picture

StatusFileSize
new3.57 KB

Fixed $account->name
module re-upload

stodge’s picture

I tried this latest module ZIP file and got:

warning: Invalid argument supplied for foreach() in /var/www/sites/ldap/sites/all/modules/htpasswdsync/HTPasswdSync.module on line 172.
warning: in_array() [function.in-array]: Wrong datatype for second argument in /var/www/sites/ldap/sites/all/modules/htpasswdsync/HTPasswdSync.module on line 192.
warning: in_array() [function.in-array]: Wrong datatype for second argument in /var/www/sites/ldap/sites/all/modules/htpasswdsync/HTPasswdSync.module on line 192.
warning: in_array() [function.in-array]: Wrong datatype for second argument in /var/www/sites/ldap/sites/all/modules/htpasswdsync/HTPasswdSync.module on line 192.
Anonymous’s picture

With this file I got a blank page. I had to use the file from the last release to get my site working again.

m.fu’s picture

Status: Needs work » Fixed

fixed in latest dev

Status: Fixed » Closed (fixed)

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