On the site I run and am implementing Dokuwiki, we need three classes of users:
There are actually a few other groups, but I (as webmaster) manage them more manually since they change about once in three years for a half dozen people.
We have one user who determines who is allowed into the “members only” group and that person has been using a web form to add and remove permissions for many users frequently as memberships are added and lapse.
I have built a webbased form that returned a list of users “in” the members group with a button to remove them. Another list of members not in the members group has a button to add the user. At the top of the form there is a script that:
While I was fighting with some ugly code to do a ton of check and recheck and recheck again as the password file was re-written, I looked at the code in inc/auth.php and saw how it performed a similar operation to change passwords. I immediated rewrote my functions into a single, simpler function that still accomplishes all my goals. Hopefully, someone else will have a use for this or, perhaps it can be imported into the Wiki engine itself.
Nov 18/2005
function SetUserGroup($userid, $group_name, $grp_state) {
//echo "\t\t<p>DEBUG SetUserGroup($userid, $group_name, $grp_state)</p>\n";
//Load the entire file
$pro = file('conf/users.auth.php');
// Get the current data for the user ID
$lines = preg_grep("/^$userid:/", $pro);
//echo "\t\t<p>DEBUG count(\$lines)=".count($lines)."</p>\n";
$match_pattern = "/^($userid):([^:]*):([^:]*):([^:]*):([^\n\r$]*)[\n\r$]+/";
$key = key($lines);
//echo "\t\t<p>DEBUG \$lines[\$key]=$lines[key]</p>\n";
$matched = preg_match($match_pattern, $lines[$key], $matches);
if($matched) {
// Remove the old user data from the file contents
$prodel = preg_grep("/^$userid:/", $pro, PREG_GREP_INVERT);
// Make the output into a single string
$prodeljoin = join("",$prodel);
//generate the list of groups the user belongs to
foreach(explode(",", $matches[5]) as $grp) {
// Use the group name as a key to ensure a group never exists twice
$grp_list[$grp] = 1;
}
$grp_list[$group_name] = $grp_state;
$grp_string = "";
foreach($grp_list as $grp=>$active) {
if ($active) {
$grp_string .= $grp . ",";
}
}
// remove trailing commas
$grp_string = rtrim($grp_string,",");
// Build e new user line
$pronew = $matches[1] .':'. //user
$matches[2] .':'. //pwd
$matches[3] .':'. //name
$matches[4] .':'. //email
$grp_string; //groupe
//echo "\t\t<p>DEBUG \$pronew=\"$pronew\"</p>\n";
$prosav = $prodeljoin . $pronew ."\n";
return (io_saveFile("conf/users.auth.php", $prosav));
} else {
echo "\t\t<p class=\"error\">User was not found</p>\n";
return false;
}
}
Hi Kite, The auth system has been revised. The updated auth interface provides methods for managing groups and group memberships. The usermanager handles most of the common user management functions. However there is (currently) no specific group membership only handling. If you would like to take a look at both of the above and suggest extensions to the user manager for group membership handling that would be great
— Christopher Smith 2005-11-19 13:56