Sep 07, 2008 | 07:14 PM  
Welcome

Don't have an account yet? You can create one, it is free, just click here

as a registered user you have some advantages like free downloads, comments and posting on our forums, depending upon this site's configuration and options.

 • •  Control Panel - Register - Login  • • 
Current Stable MDPro Lite 1.0821 Download
  Forum FAQForum FAQ   SearchSearch  UsergroupsUsergroups  PreferencesPreferences  Options forumOptions forum  Watched TopicsWatched Topics  Watched ForumsWatched Forums
Latest forum posts Latest forum posts  Log in to check your private messages Log in to check your private messages    Log inLog in 
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
WebDude
MD user level 1
MD user level 1


Joined: Apr 18, 2006
Posts: 11

Member
Post  Posted: May 17, 2006 - 04:18 AM Reply with quote Back to top
Post subject: User / Group Functions

Is there a function in MDUsers which allows you simply to determine if a user is a member of a particular group (given the name or ID)? I've looked through includes/security.php and found the pnSecAuthAction() function, but I don't think it really gives me what I'm looking for. I'm about ready to write my own function, but I'd much rather use an existing function.
View user's profile
PeteBest
MD user level 5
MD user level 5


Joined: Oct 06, 2003
Posts: 4845

bannato
Post  Posted: May 17, 2006 - 05:39 AM Reply with quote Back to top

We need more details needed about what exactly you're trying to do. All auth checks are passed through pnSecAuthAction, if that's not what you're looking for you need to supply more details. What do you expect to be returned? The usergroup as plain text given an input user? The Group ID of that user?

If this is a question in particular referring to MDUsers, it should either be in the mailing list or the MDLite Beta discussion forum. I suspect this is actually a general API question and not anything to do with MDUsers at all. The current API documentation is available HERE

_________________
Retired from official MAXdev duties
View user's profile
WebDude
MD user level 1
MD user level 1


Joined: Apr 18, 2006
Posts: 11

bannato
Post  Posted: May 17, 2006 - 06:44 AM Reply with quote Back to top

I'm modifying MDUsers to include Active Directory authentication. I'm trying to set it up so that if a user is a member of a particular group, it'll use AD for authentication. So all I need t o do is to have it tell me if the user is a member of that particular group.
View user's profile
PeteBest
MD user level 5
MD user level 5


Joined: Oct 06, 2003
Posts: 4845

bannato
Post  Posted: May 17, 2006 - 09:30 AM Reply with quote Back to top

Discussion about modifying MDLite specific modules belongs in the dev list. Serg (creator of MDUsers) doesn't frequent these forums, so there is little point in posting this to the forum. Here's a copy of a function from PostNuke that does what you want, adapt is as needed.

Code:
function pnGetUsersGroups($uid) {

list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();

$grouptable = $pntable['group_membership'];
$groupcolumn = &$pntable['group_membership_column'];

$sql = "SELECT * FROM $grouptable WHERE $groupcolumn[uid] = " . pnVarPrepForStore($uid);

$result = $dbconn->Execute($sql);

$resarray = array();

while(list($groupid, $userid) = $result->fields) {
$result->MoveNext();
$resarray[] = array('groupid' => $groupid, 'userid' => $userid);
  }
}

_________________
Retired from official MAXdev duties
View user's profile
PeteBest
MD user level 5
MD user level 5


Joined: Oct 06, 2003
Posts: 4845

bannato
Post  Posted: May 17, 2006 - 10:25 AM Reply with quote Back to top

Another alternative is to edit the pnUserGetVars function, like:

Code:
function pnUserGetVars($uid)
{
    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();
    $vars = array();
    // TODO: review this code for performance.
    $propertiestable = $pntable['user_property'];
    $userstable = $pntable['users'];
    $datatable = $pntable['user_data'];
    $grouptable = $pntable['group_membership'];
    $userscolumn = &$pntable['users_column'];
    $datacolumn = &$pntable['user_data_column'];
    $propcolumn = &$pntable['user_property_column'];
    $groupcolumn = &$pntable['group_membership_column'];

    $query = "SELECT $propcolumn[prop_label] as label, $datacolumn[uda_value] as value
              FROM $datatable, $propertiestable, $grouptable
              WHERE $datacolumn[uda_uid] = '" . pnVarPrepForStore($uid) . "' "
     . "AND $datacolumn[uda_propid] = $propcolumn[prop_id]"
     . " AND $groupcolumn[uid] = '" . pnVarPrepForStore($uid) . "'";

    $result = $dbconn->Execute($query);

    while (!$result->EOF) {
        $uservars = $result->GetRowAssoc(false);
        $vars[$uservars['label']] = $uservars['value'];
        $result->MoveNext();
    }

    $result->Close();

    $query = "SELECT *
              FROM $userstable
              WHERE $userscolumn[uid] = " . pnVarPrepForStore($uid);
    $result = $dbconn->Execute($query);

    if ($result->EOF) {
        return false;
    }

    $corevars = $result->GetRowAssoc(false);
    $result->Close();

    $query = "SELECT $groupcolumn[gid]
                     FROM $grouptable
                     WHERE $groupcolumn[uid] = " . pnVarPrepForStore($uid);
    $result = $dbconn->Execute($query);
   
    if ($result->EOF) {
        return false;
    }
   
    $group = $result->GetRowAssoc(false);
    $result->Close();

    $vars = array_merge ($vars, $corevars, $group);
   
    // Aliasing if required
    if (empty($vars['uid'])) {
        $vars['uid'] = $vars['pn_uid'];
        $vars['email'] = $vars['pn_email'];
        $vars['gid'] = $vars['pn_gid'];
        $vars['femail'] = $vars['pn_femail'];
        $vars['name'] = $vars['pn_name'];
        $vars['theme'] = $vars['pn_theme'];
        $vars['timezone_offset'] = $vars['pn_timezone_offset'];
        $vars['uname'] = $vars['pn_uname'];
        $vars['ublock'] = $vars['pn_ublock'];
        $vars['ublockon'] = $vars['pn_ublockon'];
        $vars['user_avatar'] = $vars['pn_user_avatar'];
        $vars['user_icq'] = $vars['pn_user_icq'];
        $vars['user_aim'] = $vars['pn_user_aim'];
        $vars['user_yim'] = $vars['pn_user_yim'];
        $vars['user_msnm'] = $vars['pn_user_msnm'];
        $vars['user_from'] = $vars['pn_user_from'];
        $vars['user_occ'] = $vars['pn_user_occ'];
        $vars['user_intrest'] = $vars['pn_user_intrest'];
        $vars['user_sig'] = $vars['pn_user_sig'];
        $vars['bio'] = $vars['pn_bio'];
        $vars['url'] = $vars['pn_url'];
        $vars['storynum'] = $vars['pn_storynum'];
        $vars['umode'] = $vars['pn_umode'];
        $vars['uorder'] = $vars['pn_uorder'];
        $vars['thold'] = $vars['pn_thold'];
        $vars['noscore'] = $vars['pn_noscore'];
        $vars['commentmax'] = $vars['pn_commentmax'];
    }
    return($vars);
}


So then you can use something like:

Code:
if (pnUserLoggedIn()) {
$gid = pnUserGetVar('gid');
if (isset($gid)) {
echo "You belong to usergroup $gid";
}
}


Probably a better option IMO

_________________
Retired from official MAXdev duties
View user's profile
Display posts from previous:     
Jump to:  
All times are GMT + 13 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by MDForum 2.0.8© 2003-2007 MAXdev Team
Credits