Browse files

Add role editor and enable redirect to login or access denied page

  • Loading branch information...
1 parent bd6ecaa commit 9966221164aa4c3b30f2464cf4ee58f84d0c5bae @jtouza committed Feb 13, 2012
Showing with 31 additions and 12 deletions.
  1. +18 −8 Controller/Plugin/Auth.php
  2. +13 −4 Resource/Auth.php
View
26 Controller/Plugin/Auth.php
@@ -48,11 +48,12 @@ public function preDispatch(Zend_Controller_Request_Abstract $request)
* Default access
* @var bool
*/
- $isAllowed = true;
+ $isAllowed = true;
+ $identity = Zend_Auth::getInstance()->getIdentity();
if(Zend_Auth::getInstance()->hasIdentity())
{
- $role = Zend_Auth::getInstance()->getIdentity()->role;
+ $role = $identity->role;
} else {
//Zend_Auth::getInstance()->getStorage()->write(array('role'=>'guest'));
@@ -87,22 +88,31 @@ public function preDispatch(Zend_Controller_Request_Abstract $request)
Zend_Debug::dump($privilege, 'privilege');
*/
-
if(!$isAllowed){
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
- //$redirector->gotoSimple('login', 'auth');
- //$redirector->setExit();
- $redirector
+ if(!$identity){
+ $redirector
->setCode(303)
->gotoRoute(array(
'module' => 'admin',
'controller' => 'auth',
'action' => 'login',
- 'locale' => 'en',
'url' => base64_encode(Zend_Controller_Front::getInstance()->getRequest()->getRequestUri())
- ));
+ ),'admin', true);
+ }
+
+
+
+ $redirector
+ ->setCode(303)
+ ->gotoRoute(array(
+ 'module' => 'admin',
+ 'controller' => 'auth',
+ 'action' => 'access-denied',
+ 'url' => base64_encode(Zend_Controller_Front::getInstance()->getRequest()->getRequestUri())
+ ),'admin', true);
}
}
}
View
17 Resource/Auth.php 100644 → 100755
@@ -78,20 +78,29 @@ public function init()
// Roles
$acl->addRole(new Zend_Acl_Role('guest'))
+ ->addRole(new Zend_Acl_Role('editor'))
->addRole(new Zend_Acl_Role('admin'));
// Resources
$acl->add(new Zend_Acl_Resource('public'));
$acl->add(new Zend_Acl_Resource('private'));
+ $acl->add(new Zend_Acl_Resource('config'));
- //guest
+ // Guest
$acl->deny('guest', 'private');
$acl->allow('guest', 'public');
- //admin
- $acl->allow('admin', 'private');
- $acl->allow('admin', 'public');
+
+ // Admin
+ $acl->allow('admin', 'private');
+ $acl->allow('admin', 'public');
+ $acl->allow('admin', 'config');
+
+ // Editor
+ $acl->allow('editor', 'private');
+ $acl->allow('editor', 'public');
+ $acl->deny('editor', 'config');
Zend_Registry::set('Zend_Acl', $acl);

0 comments on commit 9966221

Please sign in to comment.