fixing up acl plugin

This commit is contained in:
naomiaro 2011-01-25 00:04:40 -05:00
parent 51f77dba50
commit 057b1a08a6
1 changed files with 44 additions and 20 deletions

View File

@ -109,13 +109,36 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
**/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if (Zend_Auth::getInstance()->hasIdentity()){
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$this->setRoleName($userInfo->type);
$controller = strtolower($request->getControllerName());
if (!Zend_Auth::getInstance()->hasIdentity()){
if ($controller !== 'login') {
if ($request->isXmlHttpRequest()) {
$url = 'http://'.$request->getHttpHost().'/login';
$json = Zend_Json::encode(array('auth' => false, 'url' => $url));
// Prepare response
$this->getResponse()
->setHttpResponseCode(401)
->setBody($json)
->sendResponse();
//redirectAndExit() cleans up, sends the headers and stops the script
Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->redirectAndExit();
}
else {
$this->_roleName = "guest";
$r = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$r->gotoSimpleAndExit('index', 'login', $request->getModuleName());
}
}
}
else {
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$this->setRoleName($userInfo->type);
Zend_View_Helper_Navigation_HelperAbstract::setDefaultRole($this->_roleName);
@ -125,7 +148,7 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
$resourceName .= strtolower($request->getModuleName()) . ':';
}
$resourceName .= strtolower($request->getControllerName());
$resourceName .= $controller;
/** Check if the controller/action can be accessed by the current user */
if (!$this->getAcl()->isAllowed($this->_roleName, $resourceName, $request->getActionName())) {
@ -133,6 +156,7 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
$this->denyAccess();
}
}
}
/**
* Deny Access Function