Groups?

Permalink
What I am trying to do seems simple enough, but I am apparently missing something. I am wanting to redirect users based on their group membership after login to a sub-page. I have the sub-pages set up and permission(ed) correctly, so I just want to drop a quick line into the /elements/header_required.php file that looks at the signed in user and then their memberships. The code I have returns the groups, but not the custom group that I created. For example:

$u = new User();
$loggedIn = $u->checkLogin();
if($loggedIn) {
$groups = $u->getUserGroups();
if(count($groups) > 0) {
for($i = 0; $i < count($groups); $i++) {
echo $groups[$i] . "<br>";
}
}
}

This returns (in this users's case) "Guest" and "Registered Users", but not "Client", which is the custom group that I created and this user belongs to. Is there something that I have to do in order to get C5 to recognize a user's custom group membership? If I can only return C5 default groups (i.e. Administrator, etc.) from this method, that seems very limited, but I am sure that I am just missing something.

Thanks in advance.

mlesher
 
JohntheFish replied on at Permalink Reply
JohntheFish
If you have $75, you could always try:
http://www.concrete5.org/marketplace/addons/login-attribute-redirec...

Your code appears about right for listing groups, so maybe double check the user you are testing is in the group.

On the overall logic, do you always want to send them to the redirected page? or just immediately after they log in?
mlesher replied on at Permalink Reply
mlesher
Thanks JohntheFish. I can definitely confirm that the user belongs to the Group. I have tried this on several Users (all assigned to the same Group) and I have tried several new Groups. The only ones returned by C5 are "Guest", "Registered User" and/or "Administrator"
JohntheFish replied on at Permalink Reply
JohntheFish
You could try attacking it from the other direction. I use the below code in several situations. I think there is an equivalent get by name method.
$g = Group::getByID($gID);
if ($u->inGroup($g)){
 // in group
}
Shotster replied on at Permalink Reply
Shotster
Your approach should work fine, but hooking into the on_user_login event might be more elegant. I haven't done it myself, but it seems like it should work.

http://www.concrete5.org/documentation/developers/system/events...

-Steve
mlesher replied on at Permalink Reply
mlesher
Thanks Shotster. My intent was to use the event handler after I determined what group that the user belonged to, which I agree is a more elegant approach than using header or a redirect per se. The issue still is, however, that apparently I cannot determine the custom Group status of a User...