All pastes #941323 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-03-13 17:00 UTC
rendered paste body
<?php

class EDM_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
		$webUser = WebUser::getInstance();
		$acl = EDM_Acl::getInstance();
		$request = $this->getRequest();

		try {

			if (!$acl->hasRole($webUser->acl_role_id)) {
        	    throw new Zend_Exception('Sorry, the requested user role "'.$webUser->acl_role_id.'" does not exist');									
        	}
        	if (!$acl->has($request->getControllerName())) {
        	    throw new Zend_Exception('Sorry, the requested controller "'.$request->getControllerName().'" does not exist as an ACL resource');
        	}
			if (!$acl->isAllowed($webUser->acl_role_id, $request->getControllerName(), $request->getActionName())) {
        	    throw new Zend_Exception('Sorry, the page you requested does not exist or you do not have access');
        	}

		} catch (Zend_Exception $e) {
			
			Zend_Layout::getMvcInstance()->getView()->error = $e;
			$request->setControllerName('error');
			$request->setActionName('error');
			$request->setDispatched(false);
			
		}
    }
}