discriminate if a user is logged in and belongs to specific group

Permalink 1 user found helpful
I'm trying to "serve" parts of the content (both in my various templates and in elements such as header_required.php) differently, depending on various conditions (if the user is logged in AND if s/he belongs to a specific group) -- is that possible?

I couldn't work my way to this in the API doc, so I thought I would just... ask :)

 
TouchTecServers replied on at Permalink Reply
Hmm it would be interesting if permissions could be set at a block level, not just at page level maybe?

Although, you could create various copies of the pages, with different blocks on.

Creating user groups is the best way to do what you want to do surely?
frz replied on at Permalink Reply
frz
turn on advanced permissions and look again.
Lucy replied on at Permalink Reply
Right, perhaps I should have been a tad more specific.

Advanced permissions only apply to user-editable sections of the pages and blocks, right?

That just won't cut it for me.

I'm very much into optimization, trying to stick as best as I can to Yahoo's best practices as laid out here:http://developer.yahoo.com/performance/rules.html...

I'm creating fairly sophisticated and graphic intensive web designs, so reducing HTTP requests is one of my pet peeves.

I've conceived my own CSS framework, I'm making an intensive use of CSS sprites, minifying and aggregating CSS and JS libraries, and getting pretty sweet results when checking my page with the Yslow Firefox extension.

However, trouble starts when I "port" my lean and clean xHTML/CSS to C5 - the overhead added by the whole editing machinery simply ruins all my optimization efforts: header_required.php injects a fair amount of external CSS and JS files, multiplying HTTP requests accordingly.

So I figured that C5's inline editing interface, being required only for users in specific member groups (and definitely not for the majority of unregistered visitors), could simply be loaded on a user groupe basis.

I'm therefore looking to implement something along those lines, within the header_required.php:

IF user is logged in AND user group is (admin, editor, whatever) >> load and execute C5's various .css, .js - the whole shebang.

ELSE let me load just my own tidy css+js and generate lean and clean <head> section without any of C5's overhead for the vast majority of users, who only want to browse the pages.

Does that make sense ?
ScottC replied on at Permalink Reply
ScottC
you can modify header required to do whatever you want.

Code guess, probably wrong:
edit: if you can get userInfo, then you want to look into canAdminCollection so you don't have a hardcoded group like Administrators below
$u = new User(); //gets current user object
$g = Group::getByName("Administrators"); 
if($u->inGroup($g) && $c->isEditMode())
{ 
js css includes
}


Instead try this?
definitely more terse
this might work as well....again haven't tested.
$u = new User();
$ui = UserInfo::getByID($u->uID);
if($ui->canAddblock()){
//use the html helper to add javascript to the page
//also try $ui->canAdminCollection() not sure one is better than the other?
}


I wrote a short tutorial on modifying that specific file. I am hoping that the user has a cached copy of jquery & swfobj from google, otherwise THEIR CDNs take over.

I agree maybe jquery shouldn't be loaded unless a block or the editing interface requires it...again easily from blocks.

I am sure Andrew would be happy to look at a leaner header_required and would give you credit where due.

But yeah you are right, lean is always better. For what it is worth, I'd rather them work on the filemanager instead of dedicating resources to this.
frz replied on at Permalink Reply
frz
Yeah you should be able to not load the JS for the editing bar if the user isn't gonna see the editing bar. that's certainly a fair request. If scott's code doesnt do it, nag again and I'll get andy to give you a corrected snippit..
ScottC replied on at Permalink Reply
ScottC
But i feel like the other code shouldn't limit only administrators to editing or Editors, that would suck for advanced permissions.

We want to know if they belong to a group that can do work on a page besides read it.
joycebeck replied on at Permalink Reply
This is SO close to what I need. The template that was designed for me uses Mootools which wipes out the top menu when I'm logged in. If I disable Mootools, then when I log-in, I use the CMS top bar. But I want it enabled for visitors who are not logged in. So, all I want to do is check if the visitor is logged in or not. It doesn't matter what group they're in. The following code works, but I want to eliminate checking for the group. Can you help me out with the proper condition to check for in the "if" statement? Thanks.
<?php  
$u = new User(); //gets current user object
$g = Group::getByName("Administrators"); 
if($u->inGroup($g)) { // if a user in the Administrator group is logged in, disable Mootools ?>
<!-- <script type="text/javascript" src="mootools.js"></script> -->
<?php } else { ?>
<script type="text/javascript" src="mootools.js"></script>
<?php } ?>
ScottC replied on at Permalink Reply
ScottC
nt
joycebeck replied on at Permalink Reply
Thanks, that did the trick.

<?php  
$u = new User(); //gets current user object
if($u->isLoggedIn()) { // if a user is logged in, disable Mootools ?>
<!-- <script type="text/javascript" src="mootools.js"></script> -->
<?php } else { ?>
<script type="text/javascript" src="mootools.js"></script>
<?php } ?>