Inheritance: extends AbstractController
Exemplo n.º 1
0
 /**
  * Get response header by key
  *
  * @param string $header
  *
  * @return \Zend\Http\Header\HeaderInterface|false
  */
 protected function getResponseHeader($header)
 {
     /** @var Response $response */
     $response = $this->controller->getResponse();
     $headers = $response->getHeaders();
     $responseHeader = $headers->get($header, false);
     return $responseHeader;
 }
Exemplo n.º 2
0
 protected function preparePluginManager()
 {
     if ($this->controller->getPluginManager() instanceof \PHPUnit_Framework_MockObject_MockObject) {
         return $this->controller->getPluginManager();
     }
     $pluginManager = $this->getMock('Zend\\Mvc\\Controller\\PluginManager');
     $this->controller->setPluginManager($pluginManager);
     return $pluginManager;
 }
 public function setup()
 {
     parent::setup();
     $this->controller = new $this->controllerFQDN();
     $this->request = new Request();
     $this->routeMatch = new RouteMatch(array('router' => array('routes' => array($this->controllerRoute => $this->routes[$this->controllerRoute]))));
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
     $this->controller->setServiceLocator($this->serviceManager);
 }
 public function setEventManager(EventManagerInterface $events)
 {
     parent::setEventManager($events);
     $controller = $this;
     $events->attach('dispatch', function ($e) use($controller) {
         $route = $e->getRouteMatch();
         $params = $route->getParams();
         $request = $controller->getRequest();
         $has_access = false;
         if ($request->getUri()->getPath() === '/employee/signin') {
             $has_access = true;
         } else {
             $has_access = $controller->checkAuthentication('');
         }
         if ($has_access === false) {
             $e->stopPropagation();
         }
     }, 100);
     // execute before executing action logic
     $events->attach('dispatch', function ($e) use($controller) {
         $session = new Container('Auth');
         $controller->layout()->setVariable('page_title', $controller->getTitle());
     }, 0);
     return $this;
 }
Exemplo n.º 5
0
 /**
  * @param \Zend\Mvc\MvcEvent $e
  */
 public function onDispatch(MvcEvent $e)
 {
     $layout = $this->layout();
     $layout->setTemplate('default/layout');
     $layout->bodyCls = '';
     parent::onDispatch($e);
 }
Exemplo n.º 6
0
use Zend\Barcode\Barcode;
//added by Yesh
class UserController extends AbstractActionController
{
    protected $em;
    protected $authservice;
    public function onDispatch(MvcEvent $e)
    {
        /* Set Default layout for all the actions */
        $this->layout('layout/layout');
        $em = $this->getEntityManager();
        $cities = $em->getRepository('\\Admin\\Entity\\City')->findBy(array('countryId' => 2));
        $categories = $em->getRepository('\\Admin\\Entity\\Categories')->findBy(array('status' => 1));
        $this->layout()->cities = $cities;
        $this->layout()->categories = $categories;
        $user_session = new Container('user');
        $userid = $user_session->userId;
        if (empty($userid)) {
            return $this->redirect()->toRoute('home');
        } else {
            $msg = 'You are already logged in.';
            $status = 1;
            $this->layout()->setVariable('userId', $user_session->userId);
            $this->layout()->setVariable('username', $user_session->userName);
            $username = $user_session->userName;
            $tmp_user = $em->getRepository('\\Admin\\Entity\\Users')->find($user_session->userId);
            $city = $tmp_user->getCity();
            if (!empty($city)) {
 /**
  * check if the admin is login otherwise redirect it to login page
  **/
 public function onDispatch(\Zend\Mvc\MvcEvent $e)
 {
     if (!isset($this->container->admin_id)) {
         return $this->redirect()->toRoute('adminlogin');
     }
     return parent::onDispatch($e);
 }
Exemplo n.º 8
0
 public function onDispatch(\Zend\Mvc\MvcEvent $e)
 {
     $install = setupUtility::checkInstall();
     if ($install == true) {
         return $this->redirect()->toRoute('install');
     }
     //get doctrine service
     $this->serviceLocatorStr = 'doctrine';
     $this->sm = $this->getServiceLocator();
     $this->doctrineService = $this->sm->get($this->serviceLocatorStr);
     //get translate service
     $this->translator = Utility::translate();
     //check login
     $user = Utility::checkLogin();
     if (!is_object($user) && $user == 0) {
         $this->redirect()->toRoute('frontend/child', array('controller' => 'login'));
     }
     //start acl
     //        $acl = new myAcl();
     //        $currentRoute  =  $this->getModuleCurrentRoute($e);
     //        $isOk = $acl->checkRole(UtilityRoleLevel::convertUserTypeToRole($user->userType)['role'],$currentRoute);
     //        if(!$isOk || $isOk == '' || $isOk == null){
     //           return $this->redirect()->toRoute('frontend/child', array('controller' => 'login'));
     //        }
     //end check login
     //end acl
     $this->init();
     return parent::onDispatch($e);
 }
Exemplo n.º 9
0
 public function setEventManager(EventManagerInterface $events)
 {
     parent::setEventManager($events);
     $thisPtr = $this;
     $events->attach('dispatch', function ($e) use($thisPtr) {
         $adminIndex = $thisPtr->getServiceLocator()->get('Navigation')->findOneById(Constants::ADMIN_ID);
         $requirelogin = $thisPtr->getServiceLocator()->get('Navigation')->findAllBy("requireslogin", true);
         $authService = $thisPtr->getServiceLocator()->get('AdminAuthService');
         if ($authService->hasIdentity()) {
             $adminIndex->setVisible(true);
             $adminIndex->setLabel("Logout");
             $adminIndex->setAction("logout");
             foreach ($requirelogin as $rec) {
                 $thisPtr->getServiceLocator()->get('Navigation')->findOneById($rec->get("id"))->setVisible(true);
             }
         } else {
             $adminIndex->setVisible(false);
             $adminIndex->setLabel("Login");
             $adminIndex->setAction("index");
             foreach ($requirelogin as $rec) {
                 $thisPtr->getServiceLocator()->get('Navigation')->findOneById($rec->get("id"))->setVisible(false);
             }
             $controller = strtolower($thisPtr->params()->fromRoute('controller'));
             $action = strtolower($thisPtr->params()->fromRoute('action'));
             $unauthorizedAttempt = array_filter($requirelogin, function ($item) use($controller, $action) {
                 return strtolower($item->get("controller")) == $controller && strtolower($item->get("action")) == $action;
             });
             if (count($unauthorizedAttempt) > 0) {
                 return $thisPtr->redirect()->toUrl("/Index/index");
             }
         }
     }, 100);
     return $this;
 }
 public function onDispatch(\Zend\Mvc\MvcEvent $e)
 {
     parent::onDispatch($e);
     $routeMatch = $e->getRouteMatch();
     $ar = $routeMatch->getParams();
     // $this->accesslLog();
 }
Exemplo n.º 11
0
 /**
  * Register the default events for this controller
  *
  * @return void
  */
 protected function attachDefaultListeners()
 {
     parent::attachDefaultListeners();
     $events = $this->getEventManager();
     $events->attach('dispatch', array($this, 'initJsController'), -10);
     $events->attach('dispatch', array($this->getJsLoader(), 'onMvcDispatch'), -90);
 }
Exemplo n.º 12
0
 /**
  * @param MvcEvent $event
  *
  * @return parent::onDispatch
  */
 public function onDispatch(MvcEvent $event)
 {
     $request = $event->getRequest();
     $remoteAddr = $request->getServer('REMOTE_ADDR');
     // check IP address is allowed
     $application = $event->getApplication();
     $config = $application->getConfig();
     $autoDeployConfig = $config['auto_deploy'];
     $allowedIpAddresses = $autoDeployConfig['ipAddresses'];
     // error if ip is not allowed
     if (!in_array($remoteAddr, $allowedIpAddresses, true)) {
         $baseModel = new \Zend\View\Model\ViewModel();
         $baseModel->setTemplate('layout/output');
         $model = new \Zend\View\Model\ViewModel();
         $model->setTemplate('error/403');
         $baseModel->addChild($model);
         $baseModel->setTerminal(true);
         $event->setViewModel($baseModel);
         $response = $event->getResponse();
         $response->setStatusCode(403);
         $response->sendHeaders();
         $event->setResponse($response);
         exit;
     }
     return parent::onDispatch($event);
 }
Exemplo n.º 13
0
 public function onDispatch(\Zend\Mvc\MvcEvent $event)
 {
     self::$instance = $this;
     if (!isset($_COOKIE['language'])) {
         $headers = $this->getRequest()->getHeaders();
         $defaultLanguage = 'en';
         $supportedLanguages = array('en', 'pl');
         $match = false;
         $this->setLanguage($defaultLanguage);
         setcookie('language', $this->getLanguage(), time() + 60 * 60 * 24 * 365, '/');
     } else {
         $this->setLanguage($_COOKIE['language']);
         setcookie('language', $this->getLanguage(), time() + 60 * 60 * 24 * 365, '/');
     }
     $referer = $this->getRequest()->getHeader('Referer');
     if ($referer) {
         $referer = $referer->uri()->getPath();
     } else {
         $referer = '/';
     }
     $request = $this->getRequest();
     $response = $this->getResponse();
     if ($request->getHeaders()->get('Cookie') !== false && isset($request->getHeaders()->get('Cookie')->previous_link)) {
         $this->setPreviousLink($request->getHeaders()->get('Cookie')->previous_link);
     } else {
         $cookie = new SetCookie('previous_link', $referer, time() + 3600);
         $response->getHeaders()->addHeader($cookie);
         $this->setPreviousLink($referer);
     }
     parent::onDispatch($event);
 }
Exemplo n.º 14
0
 /**
  * Run an action from the specified controller and render it's associated template or view model
  * @param string $expr
  * @param array $attributes
  * @param array $options
  * @return string
  */
 public function __invoke($expr, $attributes, $options)
 {
     $serviceManager = $this->serviceLocator;
     $application = $serviceManager->get('Application');
     //parse the name of the controller, action and template directory that should be used
     $params = explode(':', $expr);
     $controllerName = $params[0];
     $actionName = 'not-found';
     if (isset($params[1])) {
         $actionName = $params[1];
     }
     //instantiate the controller based on the given name
     $controller = $serviceManager->get('ControllerLoader')->get($controllerName);
     //clone the MvcEvent and route and update them with the provided parameters
     $event = $application->getMvcEvent();
     $routeMatch = clone $event->getRouteMatch();
     $event = clone $event;
     $event->setTarget($controller);
     $routeMatch->setParam('action', $actionName);
     foreach ($attributes as $key => $value) {
         $routeMatch->setParam($key, $value);
     }
     $event->setRouteMatch($routeMatch);
     $actionName = $routeMatch->getParam('action');
     //inject the new event into the controller
     if ($controller instanceof InjectApplicationEventInterface) {
         $controller->setEvent($event);
     }
     //test if the action exists in the controller and change it to not-found if missing
     $method = AbstractActionController::getMethodFromAction($actionName);
     if (!method_exists($controller, $method)) {
         $method = 'notFoundAction';
         $actionName = 'not-found';
     }
     //call the method on the controller
     $response = $controller->{$method}();
     //if the result is an instance of the Response class return it
     if ($response instanceof Response) {
         return $response->getBody();
     }
     //if the response is an instance of ViewModel then render that one
     if ($response instanceof ModelInterface) {
         $viewModel = $response;
     } elseif ($response === null || is_array($response) || $response instanceof \ArrayAccess || $response instanceof \Traversable) {
         $viewModel = new ViewModel($response);
     } else {
         return '';
     }
     //inject the view model into the MVC event
     $event->setResult($viewModel);
     //inject template name based on the matched route
     $injectTemplateListener = new InjectTemplateListener();
     $injectTemplateListener->injectTemplate($event);
     $viewModel->terminate();
     $viewModel->setOption('has_parent', true);
     //render the view model
     $view = $serviceManager->get('Zend\\View\\View');
     $output = $view->render($viewModel);
     return $output;
 }
Exemplo n.º 15
0
 /**
  * Se encarga de colgar las funciones predispatch y post dispatch para ser ejecutados
  * antes y despues del controlador principal y poder realizar tareas comunes de 
  * inicializacion y post procesamiento  
  * @see \Zend\Mvc\Controller\AbstractController::attachDefaultListeners()
  */
 protected function attachDefaultListeners()
 {
     parent::attachDefaultListeners();
     $events = $this->getEventManager();
     $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'preDispatch'), 100);
     $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'postDispatch'), -100);
 }
Exemplo n.º 16
0
 /**
  * @param \Zend\Mvc\MvcEvent $e
  * @return mixed
  */
 public function onDispatch(MvcEvent $e, $validate = true)
 {
     if ($validate && !$this->getServiceLocator()->get('ServiceLocator')->hasIdentity()) {
         $this->redirect()->toRoute(self::ROUTE_DEFAULT);
     }
     return parent::onDispatch($e);
 }
Exemplo n.º 17
0
 public function onDispatch(\Zend\Mvc\MvcEvent $e)
 {
     //$logged_block = array('index');
     //if(!$this->identity() && !in_array($e->getRouteMatch()->getParam("action"), $logged_block)) return $this->redirect()->toRoute('home');
     die("Em Manutenção.");
     return parent::onDispatch($e);
 }
 /**
  * @param string $message
  * @param string $router
  * @param array $params
  * @return \Zend\Mvc\Controller\AbstractController::redirect()->toRouter()
  */
 public function redirect($message, $router, array $params = array())
 {
     if ($message) {
         $this->flashMessenger()->addMessage($message);
     }
     return parent::redirect()->toRoute($router, $params);
 }
Exemplo n.º 19
0
 /**
  * {@inheritdoc}
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return mixed|ResponseInterface
  * @throws \RuntimeException
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response = null)
 {
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException('You can use this controller only from a console!');
     }
     return parent::dispatch($request, $response);
 }
 /**
  * {@inheritdoc}
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response = null)
 {
     if (!$request instanceof ConsoleRequest) {
         throw new InvalidArgumentException(sprintf('%s can only dispatch requests in a console environment', get_called_class()));
     }
     return parent::dispatch($request, $response);
 }
Exemplo n.º 21
0
 public function onDispatch(MvcEvent $e)
 {
     $logged_block = array('view', 'all');
     if (!$this->identity() && !in_array($e->getRouteMatch()->getParam("action"), $logged_block)) {
         return $this->redirect()->toRoute('home');
     }
     return parent::onDispatch($e);
 }
Exemplo n.º 22
0
 public function onDispatch(\Zend\Mvc\MvcEvent $e)
 {
     $this->user = new Container('user');
     if (!$this->user->boolLogged) {
         return $this->redirect()->toRoute('admin', array('controller' => 'login'));
     }
     return parent::onDispatch($e);
 }
 /**
  * Executa a requisicao
  *
  * @param \Zend\Mvc\MvcEvent $e
  *
  * @return mixed
  */
 public function onDispatch(\Zend\Mvc\MvcEvent $e)
 {
     $actionResponse = parent::onDispatch($e);
     $this->layout()->setVariable('breadcrumb', $this->getBreadcrumbOutput());
     $this->layout()->setVariable('title', $this->montarTitle($this->getTitle()));
     $this->layout()->setVariable('pageDescription', $this->getPageDescription());
     return $actionResponse;
 }
Exemplo n.º 24
0
 public function onDispatch(\Zend\Mvc\MvcEvent $e)
 {
     $this->authService = new AuthenticationService();
     if (!$this->authService->hasIdentity()) {
         $this->redirect()->toRoute("auth");
     }
     return parent::onDispatch($e);
 }
 public function attachDefaultListeners()
 {
     parent::attachDefaultListeners();
     $events = $this->getEventManager();
     /* This must run before onDispatch, because we could alter the action param */
     $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'checkPostRequest'), 10);
     return $this;
 }
Exemplo n.º 26
0
 public function onDispatch(\Zend\Mvc\MvcEvent $e)
 {
     $sessionUser = new container('user');
     if (!$sessionUser->connected) {
         $this->redirect()->toRoute('home');
     }
     return parent::onDispatch($e);
 }
 protected function attachDefaultListeners()
 {
     parent::attachDefaultListeners();
     /**
      * @todo Think of how we can automatically redirect to allow page if user hasn't installed
      */
     $this->events->attach('dispatch', array($this, 'preDispatch'), 100);
 }
Exemplo n.º 28
0
 /**
  * (non-PHPdoc)
  * @see \Zend\Mvc\Controller\AbstractActionController::onDispatch()
  */
 public function onDispatch(MvcEvent $event)
 {
     $request = $event->getRequest();
     if (!$request instanceof HttpRequest || !$request->isXmlHttpRequest()) {
         //throw new \RuntimeException('This controller must only be called with ajax requests.');
     }
     return parent::onDispatch($event);
 }
Exemplo n.º 29
0
 public function onDispatch(MvcEvent $e)
 {
     $this->authService->auth();
     $this->user = $this->authService->getUser();
     $this->layout()->user = $this->user;
     $this->layout()->userMessages = $this->authService->getUnreadMessages();
     parent::onDispatch($e);
 }
Exemplo n.º 30
0
 /**
  * Seta variáveis para o layout
  */
 public function onDispatch(\Zend\Mvc\MvcEvent $e)
 {
     /**
      * Chamada do parent no inicio do método para primeiro setar
      * os valores das variáveis antes de renderizar a tela
      */
     parent::onDispatch($e);
 }