Displaying content in single page or block based on group/access level
Permalink
I’m currently working on a single_page but could be a block as well and was wondering if there is a way to obtain the logged in users access or group to use in a conditional statement? For example, I have a page to add/mod/delete data but I want the delete option to only be display if the logged in user has permission via a group or defined permission.
The API reference is always a valuable resource. Look at it here (Permissions class):
http://docs.concrete5addons.com/...
Thanks David[MIRV]!
http://docs.concrete5addons.com/...
Thanks David[MIRV]!
Old post (I know, but) same problem.
I was writing this exact same code and having trouble. The code I have is:
I dumped the caches on both ff and IE as well as C5. In this code the admin was logged on, who is both a superuser and assigned to the Vics Group. Same problem with other non-super users but members of Vics Group - no recognition of the group. Why the three different groups? I thought maybe the cache/cookies, but problem persists. I've double and single quoted around the name just for fun. I can't find the inGroup function to see if the array of users is causing the problem. I have created a new user with no history and the var_dump comes out just the same.
Any thoughts?
I was writing this exact same code and having trouble. The code I have is:
The var_dump outputs:
Sorry, no Vics group found for you... object(User)#214 (6) { ["uID"]=> string(1) "1" ["uName"]=> string(5) "admin" ["uGroups"]=> array(3) { [2]=> string(16) "Registered Users" [5]=> string(12) "Vics" [1]=> string(5) "Guest" } ["superUser"]=> bool(true) ["uTimezone"]=> string(19) "America/Los_Angeles" ["error"]=> string(0) "" }
I dumped the caches on both ff and IE as well as C5. In this code the admin was logged on, who is both a superuser and assigned to the Vics Group. Same problem with other non-super users but members of Vics Group - no recognition of the group. Why the three different groups? I thought maybe the cache/cookies, but problem persists. I've double and single quoted around the name just for fun. I can't find the inGroup function to see if the array of users is causing the problem. I have created a new user with no history and the var_dump comes out just the same.
Any thoughts?
grab the current user object
$u = new User(); //construct fills a user object
//grab the user's groups
if($u->inGroup('yourGroup')){
//display whatever
}
that'll get you started, just read every model class definition and methods and you'll get a good idea of the class method definitions and be able to "wing" more code using common concrete5 terminology. Most classes have getByID and getByHandle/getByName available.