ZF-Commons / zfc-rbac

Role-based access control module to provide additional features on top of Zend\Permissions\Rbac
BSD 3-Clause "New" or "Revised" License
181 stars 111 forks source link

redirect Strategy Reuse #231

Closed mohamedsharaf closed 10 years ago

mohamedsharaf commented 10 years ago

if (!$this->isGranted('foo')) { $app = $this->getServiceLocator()->get('Application'); $em = $app->getEventManager(); $mvcEvent = $app->getMvcEvent(); $mvcEvent->setError(Rbac::ERROR_CONTROLLER_UNAUTHORIZED) ->setParam('identity', $this->identity()); $em->trigger('dispatch.error', $mvcEvent); $response = $mvcEvent->getResult(); return $response; }

i know i can through throw new \ZfcRbac\Exception\UnauthorizedException('Not authorized!'); but i need if user not logged in to be redirected to login page if logged in with no permission isGranted('permission') then he get the Not authorized message like this

if (!$this->isGranted('foo')) { //handle redirect strategy
}

i know this can be made manually but i need to reuse the exist redirect strategy if this possibly can be done

related https://github.com/ZF-Commons/zfc-rbac/issues/230 https://github.com/ZF-Commons/zfc-rbac/issues/70

jmleroux commented 10 years ago

:put_litter_in_its_place: