Skip to content

Instantly share code, notes, and snippets.

@danilo04
Created August 7, 2012 06:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilo04/3282425 to your computer and use it in GitHub Desktop.
Save danilo04/3282425 to your computer and use it in GitHub Desktop.
<?php
/**
* $Id$
* @license
*
* @package usuarios
* @subpackage components
* @author Danilo Domínguez P.
* @copyright UTP
*/
App::import('Core', 'Inflector');
class PermissionComponent extends Object {
var $components = array('Auth', 'Session');
var $Privilege;
var $Controller;
function initialize(&$controller, $settings = array()) {
$this->Privilege = ClassRegistry::init('Privilege');
$this->Controller = $controller;
}
function startup(&$controller) {
$this->Privilege = ClassRegistry::init('Privilege');
$this->Controller = $controller;
}
/**
*
* Verifica si el usuario tiene permiso para la ver la página
* actual
*/
function verifyPrivilege() {
switch ($this->Controller->action) {
case 'login':
case 'logout':
break;
default:
// get minimum level
$groups = explode(",", $this->Controller->Auth->user('roles_id'));
if (empty($groups)) {
$groups = array(ANONYMOUS_GROUP); //debes definir ANONYMOUS_GROUP con el valor del grupo
}
$valid = $this->Privilege->find('first', array(
'conditions' => array(
'and' => array(
'controller' => Inflector::underscore($this->Controller->name),
'action' => $this->Controller->action,
'rol_id' => $groups,
)
),
'fields' => array('Privilege.id'),
'limit' => 1,
'recursive' => -1
));
// check if they have access
if (empty($valid['Privilege'])) return false;
return true;
}
}
}
@oidacra
Copy link

oidacra commented Aug 8, 2012

Perfect., let me check if work ... tonigth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment