Permalink
Browse files

adds ability to throw an UnAuthorisedException within controller and …

…have 403 template render
  • Loading branch information...
1 parent 381ff5f commit 45ffff1de17bf07c944c8a00a97ac5b6d3736bd1 @basz basz committed Dec 7, 2012
@@ -0,0 +1,7 @@
+<?php
+
+namespace BjyAuthorize\Exception;
+
+class UnAuthorizedException extends \Exception
+{
+}
@@ -10,6 +10,7 @@
use Zend\Mvc\MvcEvent;
use Zend\Stdlib\ResponseInterface as Response;
use Zend\View\Model\ViewModel;
+use BjyAuthorize\Exception\UnAuthorizedException;
class UnauthorizedStrategy implements ListenerAggregateInterface
{
@@ -71,6 +72,14 @@ public function onDispatchError(MvcEvent $e)
case 'error-unauthorized-route':
$viewVariables['route'] = $e->getParam('route');
break;
+ case Application::ERROR_EXCEPTION:
+ if (!($e->getParam('exception') instanceof UnAuthorizedException)) {
+ return;
+ }
+
+ $viewVariables['reason'] = $e->getParam('exception')->getMessage();
+ $viewVariables['error'] = 'error-unauthorized';
+ break;
default:
/*
* do nothing if there is no error in the event or the error
View
@@ -8,6 +8,8 @@
.
<?php elseif ($error == 'error-unauthorized-route') : ?>
You are not authorized to access <?php echo $route;?>.
+ <?php elseif ($error == 'error-unauthorized') : ?>
+ You are not authorized <?php echo $reason; ?>.
<?php else : ?>
An unknown error occured.
<?php endif;?>

0 comments on commit 45ffff1

Please sign in to comment.