/**
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @param callable|null $next
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     $this->sessionManager->start();
     Container::setDefaultManager($this->sessionManager);
     $container = new Container('initialized');
     if (isset($container->init)) {
         return $next($request, $response);
     }
     $this->sessionManager->regenerateId(true);
     $container->init = true;
     if ($next) {
         return $next($request, $response);
     }
     return $response;
 }
Пример #2
0
 public function onBootstrap(Event $e)
 {
     $session = new SessionManager();
     if (!$session->sessionExists()) {
         $session->start();
     }
 }
Пример #3
0
 public function sessionStart(MvcEvent $event)
 {
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions(array());
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->start();
     Container::setDefaultManager($sessionManager);
 }
Пример #4
0
 public function initSession($config)
 {
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->start();
     Container::setDefaultManager($sessionManager);
 }
Пример #5
0
 /**
  *  @return void
  */
 private function init()
 {
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($this->config);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->start();
     Container::setDefaultManager($sessionManager);
 }
Пример #6
0
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $session = new SessionManager();
     $session->start();
     $eventManager->attach('dispatch', array($this, 'secureSession'));
 }
Пример #7
0
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $sess = new SessionManager();
     $sess->start();
     Container::setDefaultManager($sess);
 }
Пример #8
0
 public function onBootstrap(MvcEvent $e)
 {
     /* @var $sm \Zend\ServiceManager\ServiceManager */
     $sm = $e->getApplication()->getServiceManager();
     $config = $sm->get('Config');
     // bootstrap session
     $tableGateway = new TableGateway($config['app']['session.tableName'], $sm->get('dbAdapter'));
     $saveHandler = new DbTableGateway($tableGateway, new DbTableGatewayOptions());
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config['session']);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->setSaveHandler($saveHandler);
     $sessionManager->start();
     Container::setDefaultManager($sessionManager);
     // translate
     $sm->get('translator');
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     // bootstrap locale
     //     	$headers = $app->getRequest()->getHeaders();
     //     	Locale::setDefault($config['locale']['default']);
     //     	if($headers->has('Accept-Language')) {
     //     		$locales = $headers->get('Accept-Language')->getPrioritized();
     //     		// Loop through all locales, highest priority first
     //     		foreach($locales as $locale) {
     //     			if(!!($match = Locale::lookup($config['locale']['supported'], $locale->typeString))) {
     //     				// The locale is one of our supported list
     //     				Locale::setDefault($match);
     //     				break;
     //     			}
     //     		}
     //     		if(!$match) {
     //     			// Nothing from the supported list is a match
     //     			Locale::setDefault($config['locale']['default']);
     //     		}
     //     	}
     // switch layout
     $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
         $controller = $e->getTarget();
         $controllerClass = get_class($controller);
         $moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
         $config = $e->getApplication()->getServiceManager()->get('config');
         $routeMatch = $e->getRouteMatch();
         $actionName = strtolower($routeMatch->getParam('action', 'not-found'));
         // get the action name
         if (isset($config['module_layouts'][$moduleNamespace][$actionName])) {
             $controller->layout($config['module_layouts'][$moduleNamespace][$actionName]);
         } elseif (isset($config['module_layouts'][$moduleNamespace]['default'])) {
             $controller->layout($config['module_layouts'][$moduleNamespace]['default']);
         }
     }, 100);
 }
Пример #9
0
 public function onBootstrap(MvcEvent $e)
 {
     $app = $e->getApplication();
     $sm = $app->getServiceManager();
     $request = $app->getRequest();
     $response = $app->getResponse();
     $appConfig = $sm->get('Configuration');
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($appConfig['session']);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->start();
     $responseHeaders = $response->getHeaders();
     $requestHeaders = $request->getHeaders();
     $this->checkCloudFlareHttpHeader();
     $requestUriPath = $request->getUri()->getPath();
     $requestExtension = pathinfo($requestUriPath, PATHINFO_EXTENSION);
     if (!in_array($requestExtension, ['js', 'css'])) {
         $eventManager = $app->getEventManager();
         $moduleRouteListener = new ModuleRouteListener();
         $moduleRouteListener->attach($eventManager);
         $sharedManager = $eventManager->getSharedManager();
         $sharedManager->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) use($sm) {
             $controller = $e->getTarget();
             $controller->getEventManager()->attachAggregate($sm->get('Visitor'));
         }, 2);
         $client = new RemoteAddress();
         $queryParams = $request->getQuery();
         $setPartnerId = (isset($queryParams['gid']) and is_numeric($queryParams['gid'])) ? ['gid' => (int) $queryParams['gid'], 'url' => $request->getUri()] : FALSE;
         $setLang = (isset($queryParams['lang']) and is_string($queryParams['lang'])) ? ['lang' => $queryParams['lang'], 'url' => $request->getUri()] : FALSE;
         $setCurrency = (isset($queryParams['cur']) and is_string($queryParams['cur'])) ? ['cur' => $queryParams['cur'], 'url' => $request->getUri()] : FALSE;
         if ($requestHeaders->has('Accept-Language')) {
             $browserLang = $requestHeaders->get('Accept-Language')->getPrioritized();
         } else {
             $browserLang = FALSE;
         }
         if ($requestHeaders->has('User-Agent')) {
             $userAgent = $requestHeaders->get('User-Agent')->getFieldValue();
         } else {
             $userAgent = FALSE;
         }
         if ($requestHeaders->has('Referer')) {
             $referer = $requestHeaders->get('Referer');
         } else {
             $referer = FALSE;
         }
         $eventManager->trigger('detectVisitor', $this, array('setLang' => $setLang, 'setCurrency' => $setCurrency, 'browserLang' => $browserLang, 'userAgent' => $userAgent, 'referer' => $referer, 'request' => $request, 'clientIp' => $client->getIpAddress(), 'clientProxy' => $client->getUseProxy(), 'setPartnerId' => $setPartnerId, 'sessionManager' => $sessionManager, 'response' => $response, 'responseHeaders' => $responseHeaders, 'requestHeaders' => $requestHeaders, 'serviceLocator' => $sm));
         $eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_ROUTE, array($this, 'onPreDispatch'));
     }
     $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
     GlobalAdapterFeature::setStaticAdapter($dbAdapter);
 }
Пример #10
0
 public function initSession($config, \Zend\ServiceManager\ServiceManager $sm)
 {
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->getValidatorChain()->attach('session.validate', array(new HttpUserAgent(), 'isValid'));
     $sessionManager->getValidatorChain()->attach('session.validate', array(new RemoteAddr(), 'isValid'));
     $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
     $tableGateway = new TableGateway(new TableIdentifier('sessions', 'users'), $dbAdapter);
     $saveHandler = new DbTableGateway($tableGateway, new DbTableGatewayOptions());
     $sessionManager->setSaveHandler($saveHandler);
     $sessionManager->start();
     Container::setDefaultManager($sessionManager);
 }
 public function __invoke()
 {
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($this->config['options']);
     $sessionManager = new SessionManager($sessionConfig);
     if (class_exists(\Redis::class)) {
         $saveHandler = new Redis($this->config['redis']['host'], $this->config['redis']['port'], $this->config['redis']['password']);
         $sessionManager->setSaveHandler($saveHandler);
         $sessionManager->start();
     } else {
         trigger_error('Redis extension is not found. ' . \Staticus\Auth\AuthSessionMiddleware::class . ' will not work.', E_USER_NOTICE);
     }
     return $sessionManager;
 }
Пример #12
0
 public function init($sid = '')
 {
     try {
         if ($sid != '') {
             parent::setId($sid);
         }
         parent::start();
         $this->default = $this->container('Manager');
         if (!$this->default->timestamp) {
             $this->default->timestamp = time();
         }
     } catch (EMException $e) {
         throw $e;
     }
 }
 /**
  * Metodo para validar acceso al portal
  * @return \Zend\View\Model\ViewModel
  */
 public function ingresoAction()
 {
     if ($this->getRequest()->isPost()) {
         $auth = new AuthenticationService();
         $validate = $this->getRequest()->getPost();
         $authAdapter = new AuthAdapter($this->adapter(), 'usuario', 'usuario_correo', 'usuario_password');
         $authAdapter->setIdentity($validate['correo']);
         $authAdapter->setCredential(md5($validate['password']));
         $resultado = $auth->authenticate($authAdapter);
         switch ($resultado->getCode()) {
             case Result::FAILURE_IDENTITY_NOT_FOUND:
                 $this->message = "Usuario y/o contraseña incorrectos";
                 $this->flashMessenger()->addMessage($this->message);
                 return $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . '/login');
             case Result::FAILURE_CREDENTIAL_INVALID:
                 $this->message = "Usuario y/o contraseña incorrectos";
                 $this->flashMessenger()->addMessage($this->message);
                 return $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . '/login');
             case Result::SUCCESS:
                 $this->flashMessenger()->clearMessages();
                 $store = $auth->getStorage();
                 $store->write($authAdapter->getResultRowObject(null, 'usuario_password'));
                 $sessionConfig = new StandardConfig();
                 $sessionConfig->setRememberMeSeconds(20)->setCookieLifetime(30)->setCookieSecure(true)->setGcMaxlifetime(60)->setGcDivisor(60);
                 $sesionMa = new SessionManager($sessionConfig);
                 $sesionMa->rememberMe(30);
                 $container = new Container('cbol');
                 $container->setExpirationSeconds(1800);
                 $sesionMa->start();
                 $container->idSession = $auth->getIdentity()->perfil_id;
                 $permisos = $this->getPermisos($auth->getIdentity()->usuario_id);
                 $container->permisosUser = $permisos;
                 $indexProfile = \Login\IndexAllProfile::listIndexAllProfiles($auth->getIdentity()->perfil_id);
                 if ($indexProfile == 'vias') {
                     $container->reportesVias = $this->getReportesViales();
                 }
                 if ($indexProfile == 'admin') {
                     $container->sugerencias = $this->getSugerenciasAction();
                 }
                 $container->setDefaultManager($sesionMa);
                 return $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . "/{$indexProfile}");
             default:
                 echo 'Mensaje por defecto';
                 break;
         }
     }
 }
Пример #14
0
 public function onBootstrap(MvcEvent $e)
 {
     $evm = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($evm);
     /** @var ServiceManager $sm */
     $sm = $e->getApplication()->getServiceManager();
     $evm->attachAggregate($sm->get('App\\ExceptionLoggerListener'));
     $config = $e->getApplication()->getServiceManager()->get('config');
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config['session']);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->start();
     SessionContainer::setDefaultManager($sessionManager);
     $evm->attach(MvcEvent::EVENT_DISPATCH, function (MvcEvent $e) {
         $this->initEnv($e);
     }, 100);
 }
Пример #15
0
 public function initSession($config)
 {
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->getValidatorChain()->attach('session.validate', array(new HttpUserAgent(), 'isValid'));
     /*
               $sessionManager->getValidatorChain()
               ->attach(
                 'session.validate',
                   array(new RemoteAddr(), 'isValid')
               );*/
     $sessionManager->start();
     /**
      * Optional: If you later want to use namespaces, you can already store the 
      * Manager in the shared (static) Container (=namespace) field
      */
     Container::setDefaultManager($sessionManager);
 }
Пример #16
0
 /**
  * Run for every request to the system.
  *
  * This function does a lot. It register all kinds of event.
  * Logs critical error. Select correct layouts, just to
  * name a few points....
  *
  * @param MvcEvent $e
  */
 public function onBootstrap(MvcEvent $e)
 {
     $logger = $e->getApplication()->getServiceManager()->get('Logger');
     //CONFIG
     //	get config values from the application
     //	config files.
     $config = $e->getApplication()->getServiceManager()->get('Configuration');
     //SESSION
     //	config and start session
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config['session']);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->start();
     //SHUT DOWN
     //	register shutdown function that will log a critical message
     //
     register_shutdown_function(function () use($logger) {
         if ($e = error_get_last()) {
             $logger->critical("register_shutdown_function: " . $e['message'] . " in " . $e['file'] . ' line ' . $e['line']);
             echo "Smá vandræði";
         }
     });
     //EVENT MANAGER
     //	get event manager and attache event handlers to it. These
     //	event are something required for the MVC to work. And
     //	error events in the MVC application; ie. if something
     //	goes wrong in Dispatch or Rendering, these events will be called,
     //	they will  log a critical message
     $eventManager = $e->getApplication()->getEventManager();
     /** @var  $eventManager \Zend\EventManager\Event */
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $eventManager->attach($e->getApplication()->getServiceManager()->get('Stjornvisi\\Event\\SystemExceptionListener'));
     $eventManager->attach($e->getApplication()->getServiceManager()->get('Stjornvisi\\Event\\PersistenceLoginListener'));
     $eventManager->attach($e->getApplication()->getServiceManager()->get('Stjornvisi\\Event\\LayoutSelectListener'));
     $eventManager->getSharedManager()->attach(__NAMESPACE__, 'notify', $e->getApplication()->getServiceManager()->get('Stjornvisi\\Event\\NotifyListener'));
 }
Пример #17
0
 public function bootstrapSession(MvcEvent $e)
 {
     $serviceManager = $e->getApplication()->getServiceManager();
     $sessionConfig = new SessionConfig();
     $config = $serviceManager->get('Config');
     $sessionConfig->setOptions($config['session']);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->start();
     Container::setDefaultManager($sessionManager);
     //prevent session fixation by generating new session id every 5 min
     $session = new Container();
     //uses the "Default" namespace
     if (!isset($session->generated) || $session->generated < time() - 300) {
         $sessionManager->regenerateId();
         $session->generated = time();
     }
 }
Пример #18
0
 public function initSession($config)
 {
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->getValidatorChain()->attach('session.validate', array(new RemoteAddr(), 'isValid'));
     $sessionManager->getValidatorChain()->attach('session.validate', array(new HttpUserAgent(), 'isValid'));
     $sessionManager->start();
     Container::setDefaultManager($sessionManager);
 }
Пример #19
0
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $request = $e->getApplication()->getServiceManager()->get('Request');
     $moduleRouteListener->attach($eventManager);
     $adapter = $e->getApplication()->getServiceManager()->get('Zend\\Db\\Adapter\\Adapter');
     $config = $e->getApplication()->getServiceManager()->get('Configuration');
     $locale = null;
     $eventManager->attach(new UserRegisterListener($adapter));
     $eventManager->attach(new LogListener());
     // Add ACL information to the Navigation view helper
     $authorize = $e->getApplication()->getServiceManager()->get('BjyAuthorize\\Service\\Authorize');
     $acl = $authorize->getAcl();
     $role = $authorize->getIdentity();
     \Zend\View\Helper\Navigation::setDefaultAcl($acl);
     \Zend\View\Helper\Navigation::setDefaultRole($role);
     // translating system
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config['session']);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->start();
     $session = new Container('base');
     // Get the visitor language selection
     $translator = $e->getApplication()->getServiceManager()->get('translator');
     // get the locale from the cookie
     $headCookie = $request->getHeaders()->get('Cookie');
     if (!empty($headCookie) && array_key_exists('locale', get_object_vars($headCookie))) {
         $locale = $headCookie->locale;
     }
     if (empty($locale)) {
         // if there is not set any cookie
         $locale = $session->offsetGet('locale');
         // Get the locale from the session
         if (empty($locale)) {
             // if there is not any session set yet
             $headers = $request->getHeaders();
             if ($headers->has('Accept-Language')) {
                 $locales = $headers->get('Accept-Language')->getPrioritized();
                 $first = array_shift($locales);
                 $locale = $first->getLanguage();
                 if (!empty($locale) && 2 == strlen($locale)) {
                     $locale .= "_" . strtoupper($locale);
                 }
             }
             if (empty($locale)) {
                 // if the browser has no locale set, we have to get the default INTL global locale setting
                 $locale = \Locale::getPrimaryLanguage(\Locale::getDefault());
                 // Gets the default locale value from the INTL global 'default_locale'
             }
         }
     } else {
         #\Zend\Debug\debug::dump("Cookie set with locale: $locale");
     }
     $translator->setLocale(\Locale::acceptFromHttp($locale));
     $translator->setLocale($locale)->setFallbackLocale('en_US');
     \Zend\Validator\AbstractValidator::setDefaultTranslator($translator);
     \Zend\Validator\AbstractValidator::setDefaultTranslatorTextDomain();
 }
Пример #20
0
 public function _init(Dispatcher $dispatcher)
 {
     // 引入Composer,Yaf扩展的配置项yaf.use_spl_autoload务必设置为1
     if (file_exists(ROOT_PATH . '/vendor/autoload.php')) {
         $loader = (include ROOT_PATH . '/vendor/autoload.php');
         //$loader->add("",ROOT_PATH.'/library');
         //$loader->addPsr4("Zend\\",ROOT_PATH.'/library/Zend');
         Registry::set('loader', $loader);
     }
     // 禁止自动渲染
     $dispatcher->autoRender(FALSE);
     // 保存配置
     $this->_config = Application::app()->getConfig();
     Registry::set('config', $this->_config);
     // 报错设置
     if ($this->_config->global->showError) {
         error_reporting(-1);
         ini_set('display_errors', 'On');
     }
     // 加解密
     if (!empty($this->_config->global->key)) {
         Registry::set('enc', function () {
             $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
             $blockCipher->setKey($this->_config->global->key);
             return $blockCipher;
         });
     }
     // 命令行方式,跳过SESSION
     if (!defined("RUN_IN_CLI")) {
         // 保存路径
         $sessionConfig = $this->_config->session->toArray();
         if (isset($sessionConfig['save_path'])) {
             @mkdir($sessionConfig['save_path'], 0777, true);
         }
         // 配置
         $config = new SessionConfig();
         $config->setOptions($sessionConfig);
         // 会话管理器
         $manager = new SessionManager($config);
         // 开启会话
         $manager->start();
         // 验证会话
         $manager->getValidatorChain()->attach('session.validate', array(new HttpUserAgent(), 'isValid'));
         if (!$manager->isValid()) {
             $manager->destroy();
             throw new \Exception("会话验证失败");
         }
         // 会话Token
         $default = new Zend\Session\Container();
         if (empty($default->offsetGet('securityToken'))) {
             $default->offsetSet('securityToken', md5(uniqid(rand(), true)));
         }
         // 保存实例
         Registry::set('session', $default);
         Registry::set('sm', $manager);
     }
     // 数据库
     Registry::set('db', function () {
         $mysqlMasterConfig = $this->_config->mysql->master->toArray();
         $adapter = new Adapter($mysqlMasterConfig);
         $connect = $adapter->getDriver()->getConnection();
         for ($i = 0; $i < 5; $i++) {
             if ($connect->isConnected()) {
                 break;
             }
             $connect->connect();
         }
         return $adapter;
     });
     // 邮件
     Registry::set('mail', function () {
         $options = new SmtpOptions($this->_config->smtp->toArray());
         $mail = new SmtpTransport();
         $mail->setOptions($options);
         return $mail;
     });
     // 日志
     Registry::set('logger', function () {
         $logger = new Zend\Log\Logger();
         $writer = new Zend\Log\Writer\Stream($this->_config->log->path . '/' . date("Ymd") . ".log");
         $logger->addWriter($writer);
         return $logger;
     });
 }
Пример #21
0
 public function onBootstrap(EventInterface $e)
 {
     $serviceManager = $e->getApplication()->getServiceManager();
     $config = $e->getApplication()->getServiceManager()->get('config');
     $translator = $serviceManager->get('translator');
     // Gestion de la locale
     if (PHP_SAPI !== 'cli') {
         //translator
         // Gestion locale pour le back
         if ($serviceManager->get('router')->match($serviceManager->get('request')) && strpos($serviceManager->get('router')->match($serviceManager->get('request'))->getMatchedRouteName(), 'admin') !== false) {
             if ($e->getRequest()->getCookie() && $e->getRequest()->getCookie()->offsetExists('pg_locale_back')) {
                 $locale = $e->getRequest()->getCookie()->offsetGet('pg_locale_back');
             }
         }
         if (empty($locale)) {
             if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                 $locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
             } else {
                 $locale = 'fr_FR';
             }
         }
         $translator->setLocale($locale);
         // plugins
         $translate = $serviceManager->get('viewhelpermanager')->get('translate');
         $translate->getTranslator()->setLocale($locale);
         $options = $serviceManager->get('playgroundcore_module_options');
         $options->setLocale($locale);
     }
     // positionnement de la langue pour les traductions de date avec strftime
     setlocale(LC_TIME, "fr_FR", 'fr_FR.utf8', 'fra');
     AbstractValidator::setDefaultTranslator($translator, 'playgroundcore');
     /*
      * Entity translation based on Doctrine Gedmo library
      */
     $doctrine = $serviceManager->get('doctrine.entitymanager.orm_default');
     $evm = $doctrine->getEventManager();
     $translatableListener = new \Gedmo\Translatable\TranslatableListener();
     // TODO : Set the Default locale to be taken from config
     $translatableListener->setDefaultLocale('fr_FR');
     // If no translation is found, fallback to entity data
     $translatableListener->setTranslationFallback(true);
     // set Locale
     if (!empty($locale)) {
         $translatableListener->setTranslatableLocale($locale);
     }
     $evm->addEventSubscriber($translatableListener);
     /**
      * Adding a Filter to slugify a string (make it URL compliiant)
      */
     $filterChain = new \Zend\Filter\FilterChain();
     $filterChain->getPluginManager()->setInvokableClass('slugify', 'PlaygroundCore\\Filter\\Slugify');
     $filterChain->attach(new Filter\Slugify());
     // Start the session container
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config['session']);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->start();
     /**
      * Optional: If you later want to use namespaces, you can already store the
      * Manager in the shared (static) Container (=namespace) field
      */
     \Zend\Session\Container::setDefaultManager($sessionManager);
     // Google Analytics : When the render event is triggered, we invoke the view helper to
     // render the javascript code.
     $e->getApplication()->getEventManager()->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function (\Zend\Mvc\MvcEvent $e) use($serviceManager) {
         $view = $serviceManager->get('ViewHelperManager');
         $plugin = $view->get('googleAnalytics');
         $plugin();
         $pluginOG = $view->get('facebookOpengraph');
         $pluginOG();
     });
     if (PHP_SAPI !== 'cli') {
         $session = new Container('facebook');
         $fb = $e->getRequest()->getPost()->get('signed_request');
         if ($fb) {
             list($encoded_sig, $payload) = explode('.', $fb, 2);
             $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
             $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
             $session->offsetSet('signed_request', $data);
             // This fix exists only for safari on Windows : we need to redirect the user to the page outside of iframe
             // for the cookie to be accepted. Core just adds a 'redir_fb_page_id' var to alert controllers
             // that they need to send the user back to FB...
             if (!count($_COOKIE) > 0 && strpos($_SERVER['HTTP_USER_AGENT'], 'Safari')) {
                 echo '<script type="text/javascript">' . 'window.top.location.href = window.location.href+"?redir_fb_page_id=' . $data["page"]["id"] . '";' . '</script>';
             }
             // This fix exists only for IE6+, when this app is embedded into an iFrame : The P3P policy has to be set.
             $response = $e->getResponse();
             if ($response instanceof \Zend\Http\Response && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') || strpos($_SERVER['HTTP_USER_AGENT'], 'rv:11.'))) {
                 $response->getHeaders()->addHeaderLine('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
             }
         }
     }
 }
 /**
  * @runInSeparateProcess
  */
 public function testPreserveRequestAccessTimeAfterStart()
 {
     $manager = new SessionManager(null, $this->storage);
     $this->assertGreaterThan(0, $this->storage->getRequestAccessTime());
     $manager->start();
     $this->assertGreaterThan(0, $this->storage->getRequestAccessTime());
 }
Пример #23
0
 /**
  * If configured aggregate the impact from the report in the session and return the updated value.
  * @param IDS_Report $report
  * @return int
  */
 protected function aggregateImpactInSession(IDS_Report $report)
 {
     if ($this->config['aggregate_in_session']) {
         $sessionManager = new SessionManager();
         $sessionManager->start();
         $session = $sessionManager->getStorage();
         if (!isset($session->ZeSecurityIDS)) {
             $session->ZeSecurityIDS = array('impact' => 0);
         }
         $impact = $session->ZeSecurityIDS['impact'];
         $impact += $report->getImpact();
         $session->ZeSecurityIDS['impact'] = $impact;
     } else {
         $impact = $report->getImpact();
     }
     return $impact;
 }
Пример #24
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $sm Service manager
  *
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $sm)
 {
     // Build configuration:
     $sessionConfig = new \Zend\Session\Config\SessionConfig();
     $sessionConfig->setOptions($this->getOptions($sm));
     // Build session manager and attach handler:
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->setSaveHandler($this->getHandler($sm));
     // Start up the session:
     $sessionManager->start();
     // Check if we need to immediately stop it based on the settings object
     // (which may have been informed by a controller that sessions should not
     // be written as part of the current process):
     $settings = $sm->get('VuFind\\Session\\Settings');
     if ($settings->setSessionManager($sessionManager)->isWriteDisabled()) {
         $sessionManager->getSaveHandler()->disableWrites();
     } else {
         // If the session is not disabled, we should set up the normal
         // shutdown function:
         $this->registerShutdownFunction($sessionManager);
     }
     return $sessionManager;
 }
Пример #25
0
 /**
  * return a session storage instance
  * @return \Zend\Session\Storage\StorageInterface
  */
 protected function getSession()
 {
     $sessionManager = new SessionManager();
     $sessionManager->start();
     return $sessionManager->getStorage();
 }
Пример #26
0
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $adapter = $e->getApplication()->getServiceManager()->get('Zend\\Db\\Adapter\\Adapter');
     $sm = $e->getApplication()->getServiceManager();
     $config = $e->getApplication()->getServiceManager()->get('Configuration');
     $settings = $e->getApplication()->getServiceManager()->get('SettingsService');
     $eventManager->attach(new UserRegisterListener($adapter));
     $eventManager->attach(new LogListener());
     // Add ACL information to the Navigation view helper
     $authorize = $e->getApplication()->getServiceManager()->get('BjyAuthorize\\Service\\Authorize');
     $acl = $authorize->getAcl();
     $role = $authorize->getIdentity();
     \Zend\View\Helper\Navigation::setDefaultAcl($acl);
     \Zend\View\Helper\Navigation::setDefaultRole($role);
     // translating system
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config['session']);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->start();
     $session = new Container('base');
     // Get the visitor language selection
     $translator = $e->getApplication()->getServiceManager()->get('translator');
     $locale = $session->offsetGet('locale');
     // Get the locale
     if (empty($locale)) {
         $locale = \Locale::getPrimaryLanguage(\Locale::getDefault());
         // Get the locale
     }
     if (!empty($locale) && 2 == strlen($locale)) {
         $locale .= "_" . strtoupper($locale);
     }
     $translator->setLocale($locale)->setFallbackLocale('en_US');
     $isCompress = $settings->getValueByParameter('Base', 'iscompressed');
     if ($isCompress) {
         $eventManager->getSharedManager()->attach('Zend\\Mvc\\Application', 'finish', array($this, 'compressHtml'), 1002);
     }
 }