public function getServiceLocator()
 {
     if (!$this->serviceLocater) {
         $this->setServiceLocator(\FrontCore\Factories\FrontCoreServiceProviderFactory::getInstance());
     }
     //end if
     return $this->serviceLocator;
 }
 /**
  *
  * {@inheritDoc}
  * @see \Zend\Mvc\Controller\AbstractController::getServiceLocator()
  * @return Zend\ServiceManager\ServiceManager
  */
 public function getServiceLocator()
 {
     if (!$this->serviceManager) {
         $this->serviceManager = \FrontCore\Factories\FrontCoreServiceProviderFactory::getInstance();
     }
     //end function
     return $this->serviceManager;
 }
 /**
  * Static access proxy function
  * @return \FrontProfileSettings\Entities\FrontProfileNativeSettingsProfileEntity
  */
 public static function readProfileSettings()
 {
     $sm = FrontCoreServiceProviderFactory::getInstance();
     $model = $sm->get("FrontProfileSettings\\Models\\NativeProfileSettingsModel");
     return $model->fetchProfileSettings();
 }
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     //preload the Service Manager instance to the Service Manager Factory
     FrontCoreServiceProviderFactory::setInstance($e->getApplication()->getServiceManager());
     /**
      * Register event listeners
      */
     $eventsFrontCore = $e->getApplication()->getServiceManager()->get("FrontCore\\Events\\FrontCoreEvents");
     $eventsFrontCore->registerEvents();
     $eventsSystemForms = $e->getApplication()->getServiceManager()->get("FrontCore\\Events\\FrontCoreSystemFormEvents");
     $eventsSystemForms->registerEvents();
     //append app config to layout
     //load config
     $arr_config = $e->getApplication()->getServiceManager()->get("config");
     $e->getViewModel()->setVariable("app_config", $arr_config);
     $e->getViewModel()->setVariable("cdn_url", $arr_config["cdn_config"]["url"]);
     /**
      * Check if user is logged in
      */
     $sharedEvents = $eventManager->getSharedManager();
     $sharedEvents->attach("*", 'dispatch', function ($e) {
         // fired when an ActionController under the namespace is dispatched.
         $controller = $e->getTarget();
         //first check if user needs to be logged in
         if ($e->getRouteMatch()->getParam("user-bypass-login") === TRUE) {
             return;
         }
         //end if
         $arr_exclude_controllers = array("FrontUserLogin\\Controller\\IndexController");
         //check for cli requests
         if (get_class($controller) == "FrontCLI\\Controller\\IndexController") {
             //check if module is activated
             $objModuleManager = $e->getApplication()->getServiceManager()->get('ModuleManager');
             $arr_modules = $objModuleManager->getLoadedModules();
             if (array_key_exists("FrontCLI", $arr_modules)) {
                 return;
             }
             //end if
         }
         //end if
         if (strtolower(substr(get_class($controller), 0, 5)) == "front" && !in_array(get_class($controller), $arr_exclude_controllers) || strtolower($e->getRouteMatch()->getMatchedRouteName()) == "home") {
             //check if user is logged in
             if (!FrontUserSession::isLoggedIn()) {
                 //redirect to login screen and set message
                 $flashMessenger = new \Zend\Mvc\Controller\Plugin\FlashMessenger();
                 $flashMessenger->addInfoMessage("Please login to continue");
                 //redirect back to login page
                 $target = $e->getTarget();
                 if (strtolower($e->getRouteMatch()->getMatchedRouteName()) == "home") {
                     //home page, access service manager differently from event
                     $serviceLocator = $target->getServiceManager();
                 } else {
                     $serviceLocator = $target->getServiceLocator();
                 }
                 //end if
                 $url = $e->getRouter()->assemble(array("controller" => "FrontUserLogin\\Controller\\IndexController"), array('name' => 'front-user-login'));
                 $response = $e->getResponse();
                 $response->setHeaders($response->getHeaders()->addHeaderLine('Location', $url));
                 $response->setStatusCode(302);
                 $response->sendHeaders();
                 exit;
             }
             //end if
         }
         //end if
     }, 110);
     /**
      * Deal with flash messages that needs to be passed to the layout view
      */
     $eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function ($e) {
         $flashMessenger = new \Zend\Mvc\Controller\Plugin\FlashMessenger();
         if ($flashMessenger->hasMessages()) {
             $e->getViewModel()->setVariable('flashMessages', $flashMessenger->getMessages());
         }
         //end if
         if ($flashMessenger->hasErrorMessages()) {
             $e->getViewModel()->setVariable('flashMessages_errors', $flashMessenger->getErrorMessages());
         }
         //end if
         if ($flashMessenger->hasInfoMessages()) {
             $e->getViewModel()->setVariable('flashMessages_info', $flashMessenger->getInfoMessages());
         }
         //end if
         if ($flashMessenger->hasSuccessMessages()) {
             $e->getViewModel()->setVariable('flashMessages_success', $flashMessenger->getSuccessMessages());
         }
         //end if
     });
     /**
      * Log api calls
      */
     if (isset($_GET["debug_display_errors"]) && $_GET["debug_display_errors"] == 1 || isset($_GET["debug_display_queries"]) && $_GET["debug_display_queries"] == 1) {
         //get shared event manager
         $sem = $e->getApplication()->getEventManager()->getSharedManager();
         $sem->attach("*", "apiCallExecuted", function ($event) use($e) {
             $objApiData = $event->getParam("objApiData");
             $objResponse = $event->getParam("objResponse");
             $objApiData->rawResponse = $objResponse->getBody();
             if (isset($_GET["debug_display_errors"]) && $_GET["debug_display_errors"] == 1) {
                 $url = $objApiData->url;
                 $response = $objApiData->rawResponse;
                 $arr = $e->getViewModel()->getVariable("api_logs");
                 $arr[] = $objApiData;
                 $arr[] = $response;
                 $e->getViewModel()->setVariable("api_logs", $arr);
             }
             //end if
         });
     }
     //end if
     /**
      * Start session
      */
     session_start();
     //load icon packs
     $this->setIconPacks();
 }
 /**
  * Simple check if a user has access to a given resource
  * @TODO create proper zend acl
  * @param string $resource
  * @return boolean
  */
 public static function userHasAccess($resource, ServiceLocatorInterface $serviceLocator = NULL)
 {
     //default routes to be allowed
     switch ($resource) {
         case "home":
         case "front-profile-native-settings":
         case "front-user-login":
         case "front-profile-settings":
         case "front-locations":
             return TRUE;
             break;
     }
     //end switch
     //instantiate the user session
     $objUserSession = new Container("user");
     if (!isset($objUserSession->id) || $objUserSession->id == "") {
         return FALSE;
     }
     //end if
     //check if user acl has been set already, if not temporarily allow access in frontend, api will catch unauthorized requests
     if (count((array) $objUserSession->acl->user_acl_access_allowed < 10)) {
         return TRUE;
     }
     //end if
     //check api resources
     if (in_array($resource, (array) $objUserSession->acl->user_acl_access_allowed)) {
         return TRUE;
     }
     //end if
     //check user navigation array
     if (!is_array($objUserSession->arr_user_acl)) {
         //attempt to construct user acl session data via the navigation factory
         $sm = \FrontCore\Factories\FrontCoreServiceProviderFactory::getInstance();
         $objNavigation = $sm->get("FrontCore\\Navigation\\FrontNavigationFactory");
         $objNavigation->createService($sm);
         //reload user session
         $objUserSession = new Container("user");
     }
     //end if
     if (!is_array($objUserSession->arr_user_acl)) {
         //user acl not set, no point in continuing
         return FALSE;
     }
     //end if
     if (in_array($resource, $objUserSession->arr_user_acl)) {
         return TRUE;
     }
     //end if
     return FALSE;
 }