Build edit block with user permission

Permalink
Hi,

I've built a couple of sites with c5 (v5.6) and it's really easy and now I am trying to create some new blocks for special functions. I've got the general idea but I can't work out how to access information about the current visitor to the site.

As an example I want to build a new block based on the file download block which allows a download if the visitor is logged in and belongs to a specified group but shows a "You must be registered" message if not logged in. The logic being something like:
if (current user logged) and (current user in user group X)
  show download link
else
  print " You must be logged in as a member of group X to download this file"
endif


I think I could achieve something like this using Advanced Permissions but I'd prefer to stick with Standard Permissions if possible and deal with special cases through code.

Can anyone point me in the right direction to get the user info I need?
Thanks

briggers
 
hutman replied on at Permalink Reply
hutman
To get the currently logged in user you can do this

$u = new User();
$g = Group::getByName('Group Name');
if($u->isLoggedIn() && $u->inGroup($g)){
//Show the download stuff
} else {
//User is not logged in
}
briggers replied on at Permalink Reply
briggers
Thanks hutman,

I couldn't find the methods in the user object. Now I'm on my way.