Last active
December 21, 2015 01:49
-
-
Save BinaryKitten/6230886 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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