fixing up acl plugin
This commit is contained in:
parent
51f77dba50
commit
057b1a08a6
|
@ -109,13 +109,36 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
|
||||||
**/
|
**/
|
||||||
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
||||||
{
|
{
|
||||||
if (Zend_Auth::getInstance()->hasIdentity()){
|
$controller = strtolower($request->getControllerName());
|
||||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
|
||||||
$this->setRoleName($userInfo->type);
|
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 {
|
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);
|
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->getModuleName()) . ':';
|
||||||
}
|
}
|
||||||
|
|
||||||
$resourceName .= strtolower($request->getControllerName());
|
$resourceName .= $controller;
|
||||||
|
|
||||||
/** Check if the controller/action can be accessed by the current user */
|
/** Check if the controller/action can be accessed by the current user */
|
||||||
if (!$this->getAcl()->isAllowed($this->_roleName, $resourceName, $request->getActionName())) {
|
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();
|
$this->denyAccess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deny Access Function
|
* Deny Access Function
|
||||||
|
|
Loading…
Reference in New Issue