Forum CMS Made Simple FR

Version complète : Autoriser du contenu en fonction des groupes de FEU
Vous consultez actuellement la version basse qualité d’un document. Voir la version complète avec le bon formatage.
Bonjour,
j'ai fait un petit tag pour indiquer en début de contenu les groupes FEU autorisés à afficher la page.
Si l'utilisateur est logué et qu'il appartient au groupe ou à un des groupes autorisés, il verra le contenu, sinon, il sera redirigé.
C'est le principe de customContent mais en une seule balise pour facilité la saisie par l'utilisateur.
On peut mettre le tag dans le dropdown personnalisable de tinymce.
J'ai appelé le tag 'visible': {visible groupes='admin' redirect='login'} ou bien {visible groupes='admin,clients' redirect='non_autorise'}
Si redirect n'est pas renseigné, prévoir une redirection par défaut à la dernière ligne de code.
Comme l'autorisation peut se faire dans le contenu, la sécurité est mieux assurée.
Code :
//************************************************************************
//use to authorize to see a content with FEU
//parameters:
//groupes: the groups auhorized to see the content (separate with comma)
//redirect: the alias of the page to redirect if not authorized.
// use like this: {visible groupes='grp1,[grp2,...]' redirect='home'}
//you can put this tag at the begining of your content or template, or gabarit.
//************************************************************************
global $gCms;
$gn=array();
$authorized=false;
$feusers = $gCms->modules['FrontEndUsers']['object'];

//* we verify that user is logged in
if($uid = $feusers->LoggedInId()) {

//* we retrieve the groups of the user
$groupes=$feusers->GetMemberGroupsArray($uid);
//* the goupes are registered in an array
    foreach( $groupes as $grp )  {
     $gn[] = $feusers->GetGroupName($grp['groupid']);
        }
//* we retrieve the authorized groups for this page in an array.
$auth=(explode(',',$params['groupes']));

//* we search if there is intersection bettween the two groups
$intersec=array_intersect($auth, $gn);

//* the user is authorized if we find an intersection
if(count($intersec) > 0) $authorized=true;
}
if(!$authorized) {

//* if not authorized, we redirect to the page from redirect parameter.
if(isset($params['redirect'])) {
$id = ContentManager::GetPageIDFromAlias( $params['redirect'] );
    if( $id )
      {
    redirect_to_alias( $id );
    return;
      }
}
//* if no redirect parameter, we redirect to alias of the login page.
    redirect_to_alias( 43 );
}
l'idée est intéressante Smile

merci jissey pour ton partage d'info. Je tenterais de l'utiliser quand l'occasion s'en ferra ressentir Smile

Je t'invites à le partager sur le wiki français et anglais Wink

http://wiki.cmsmadesimple.org/index.php/..._tags_here
http://wiki.cmsmadesimple.org/index.php/...gs_here/fr
Je l'utilise, c'est parfait.
Merci jissey Smile
Merci JLV, c'est un honneur!
puisque c'est ça, j'en ai un autre.
C'est une déclinaison de celui-ci pour menu.
L'utilisateur renseigne dans la zone extra3 les groupes autorisés à voir la page dans le menu.
J'ai appelé ma balise visible_menu, donc, dans le gabarit du menu, il faut mettre {visible_menu groupes=$node->extra3}
Code :
//************************************************************************
//use to authorize a page to appear in the admin menu
//parameters:
// take parameter from the extra3 of the page that containthe groups auhorized to see the content (separate with comma)
//you must put this tag in the gabarit of your menu
//************************************************************************
global $gCms;
$gn=array();
$grps=$params['groupes'];
$autho=false;
print_r($node);
//we assume that there is something in extra3.
if($grps == '') {
$gCms->smarty->assign('autho', false);
return;
}

$feusers = $gCms->modules['FrontEndUsers']['object'];

//* we verify that user is logged in
if($uid = $feusers->LoggedInId()) {

//* if groupes parameter equal *, that mean that no matter the group.
if($grps == '*') {
$gCms->smarty->assign('autho', true);
return;
}

//* we retrieve the groups of the user
$groupes=$feusers->GetMemberGroupsArray($uid);
//* the goupes are registered in an array
    foreach( $groupes as $grp )  {
     $gn[] = $feusers->GetGroupName($grp['groupid']);
        }
//* we retrieve the authorized groups for this page in an array.
$auth=(explode(',',$grps));

//* we search if there is intersection bettween the two groups
$intersec=array_intersect($auth, $gn);

//* the user is authorized if we find an intersection
if(count($intersec) > 0) {
$gCms->smarty->assign('autho', true);
return;
}
}
$gCms->smarty->assign('autho', false);

et le gabarit de mon menu :

Code :
{* administration menu: call to visible_menu tag with extra3 parameter *}
{if $count > 0}
<ul>
{foreach from=$nodelist item=node name="menu"}
{visible_menu groupes=$node->extra3}
{if $autho}
<li><a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if} class="menu_admin">{$node->menutext}</a></li>
{/if}
{/foreach}
<li>{cms_module module=FEUajaxplorer}</li>
</ul>
{/if}
Bess, je n'ai pas trouvé comment les mettre dans les wikis! C'est ballot hein?
Très intéressant tout ça !

Merci jissey pour le partage
@Jissey
Il me semble que tu n'as qu'à te loguer et tu pourras éditer.
il te faut te connecter avec un identifiant : celui du forum anglais

ensuite tu vas sur mes liens : editer le contenu et hop !