Skip to content

Instantly share code, notes, and snippets.

@BinaryKitten
Last active December 21, 2015 01:49
Show Gist options
  • Select an option

  • Save BinaryKitten/6230886 to your computer and use it in GitHub Desktop.

Select an option

Save BinaryKitten/6230886 to your computer and use it in GitHub Desktop.
<?php
namespace Application;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$sharedEvents = $eventManager->getSharedManager();
$sharedEvents->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) {
$controller = $e->getTarget();
$request = $controller->getRequest();
// Skip ACL checks for Console based requests
if (!$request instanceof ConsoleRequest) {
$matchedRoute = $controller->getEvent()->getRouteMatch()->getMatchedRouteName();
$config = $e->getApplication()->getServiceManager()->get('config');
$allowedRoutes = array('zfcuser/login', 'zfcuser/register');
if (in_array($matchedRoute, $allowedRoutes) || $controller->zfcUserAuthentication()->hasIdentity()) {
return; // they're logged in or on the login page, allow
}
// otherwise, redirect to the login page
return $controller->redirect()->toRoute('zfcuser/login');
}
}, 1000
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment