initial commit
This commit is contained in:
commit
e869a1cab4
107 changed files with 9029 additions and 0 deletions
47
app/plugins/AclPlugin.php
Normal file
47
app/plugins/AclPlugin.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
use Phalcon\Acl;
|
||||
use Phalcon\Events\Event;
|
||||
use Phalcon\Mvc\Dispatcher;
|
||||
|
||||
class AclPlugin extends Phalcon\Mvc\User\Plugin
|
||||
{
|
||||
public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
|
||||
{
|
||||
// We only have two roles for now, authenticated users and guests.
|
||||
if ($this->auth->hasIdentity()) {
|
||||
$role = \Acl\Acl::ROLE_USER;
|
||||
} else {
|
||||
$role = \Acl\Acl::ROLE_GUEST;
|
||||
}
|
||||
|
||||
// Support annotations for actions to define custom resources.
|
||||
$controllerClass = $dispatcher->getControllerClass();
|
||||
$activeMethod = $dispatcher->getActiveMethod();
|
||||
|
||||
$annotation = $this->annotations->getMethod($controllerClass, $activeMethod);
|
||||
|
||||
// ACL annotation found. use that.
|
||||
if ($annotation->has('Acl')) {
|
||||
$resource = $annotation->get('Acl')->getArgument('resource');
|
||||
}
|
||||
// Otherwise, default to controller name.
|
||||
else {
|
||||
$resource = $dispatcher->getControllerName();
|
||||
}
|
||||
|
||||
// Now, check and redirect user to login page if
|
||||
// this role does not have access to this resource.
|
||||
if ($this->acl->isAllowed($role, $resource, 'Read') == Acl::DENY) {
|
||||
|
||||
// Forward to login page.
|
||||
$dispatcher->forward(array(
|
||||
'controller' => 'auth',
|
||||
'action' => 'index',
|
||||
));
|
||||
|
||||
// Return false to stop the dispatch loop.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in a new issue