/** * {@inheritdoc} */ public function onExecuteAction(ExecuteActionEvent $event, $eventConfig) { $request = $event->getRequest(); try { $userId = $request->getSession()->get('user.id'); $user = $this->cast('Mapper\\User', $userId); $redirectUrl = null; if ($request->getController() == 'Resource') { return; } else { if (!$user->getLocation() && ($request->getController() != 'Authenticate' || $request->getMethod() != 'setLocation')) { $redirectUrl = '/login/location'; } else { if ($user->getLocation() && $request->getController() == 'Authenticate' && $request->getMethod() == 'setLocation') { $redirectUrl = '/'; } else { return; } } } $response = new Response(); $response->redirect($redirectUrl); $event->setResponse($response); } catch (ValueNotFoundException $e) { return; } catch (UserNotFoundExceptio $e) { $request->getSession()->clear(); $response = new Response(); $response->redirect('/login'); $event->setResponse($response); } }
/** * Check authenticate. * * @param \Arbor\Event\ExecuteActionEvent $event * @param array $config * @param array $eventConfig * @throws \Arbor\Exception\ValueNotFoundException * @throws \Arbor\Exception\PermissionDeniedException * @since 0.1.0 */ private function execute(ExecuteActionEvent $event, $config, $eventConfig) { $request = $event->getRequest(); $session = $request->getSession(); $maxTime = isset($eventConfig['maxTime']) ? $eventConfig['maxTime'] : 0; try { $session->get('user.id'); if ($maxTime > 0) { if ($session->get('session.epoch') < time()) { //deprecated session $session->clear(); throw new ValueNotFoundException('session.epoch'); } $session->set('session.epoch', time() + $maxTime); } if (isset($config['session-redirect'])) { $response = $this->createResponseRedirect($config['session-redirect'], $request); $event->setResponse($response); } } catch (ValueNotFoundException $e) { if (isset($config['incognito']) && $config['incognito'] == 'true') { //IGNORED } else { if (isset($config['redirect'])) { $response = $this->createResponseRedirect($config['redirect'], $request); $event->setResponse($response); } else { throw new PermissionDeniedException(); } } } }