/**
  * Starts the session if it does not exist.
  *
  * @return void
  */
 protected function startSession()
 {
     // Check that the session hasn't already been started
     if ($this->session->isStarted()) {
         $this->session->start();
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function getSessionId()
 {
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
     return $this->session->getId();
 }
Example #3
0
 /**
  * {@inheritDoc}
  */
 public function isSessionStarted()
 {
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
     return $this->session->isStarted();
 }
 /**
  * Moves flash messages from the session to a cookie inside a Response Kernel listener.
  *
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if ($event->getRequestType() !== HttpKernel::MASTER_REQUEST) {
         return;
     }
     // Flash messages are stored in the session. If there is none, there
     // can't be any flash messages in it. $session->getFlashBag() would
     // create a session, we need to avoid that.
     if (!$this->session->isStarted()) {
         return;
     }
     $flashBag = $this->session->getFlashBag();
     $flashes = $flashBag->all();
     if (empty($flashes)) {
         return;
     }
     $response = $event->getResponse();
     $cookies = $response->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
     if (isset($cookies[$this->options['host']][$this->options['path']][$this->options['name']])) {
         $rawCookie = $cookies[$this->options['host']][$this->options['path']][$this->options['name']]->getValue();
         $flashes = array_merge($flashes, json_decode($rawCookie));
     }
     $cookie = new Cookie($this->options['name'], json_encode($flashes), 0, $this->options['path'], $this->options['host'], $this->options['secure'], false);
     $response->headers->setCookie($cookie);
 }
Example #5
0
 public function __construct(Mysql $db, Session $session)
 {
     $this->db = $db;
     $this->session = $session;
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
 }
Example #6
0
 /**
  * Session constructor.
  *
  * @param string|null $namespace
  */
 public function __construct($namespace = null)
 {
     @session_start();
     $this->session = new SymfonySession(new PhpBridgeSessionStorage());
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
     $this->setSessionValues($namespace);
 }
Example #7
0
 public function __construct(Mysql $db, Session $session, LoginService $login)
 {
     $this->db = $db;
     $this->session = $session;
     $this->login = $login;
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
 }
Example #8
0
 /**
  * @Route("/", name="homepage")
  */
 public function indexAction(Request $request)
 {
     $session = new Session();
     if ($session->isStarted() == true) {
         $session->start();
     }
     $products = $this->getDoctrine()->getRepository('AppBundle:Product')->findAll();
     $prodId = $request->request->get('prod', 'noone');
     $inBasket[] = "Empty Basket, please select a product";
     if ($prodId != 'noone') {
         $product = $this->getDoctrine()->getRepository('AppBundle:Product')->find($prodId);
         $session->set($product->getId(), $product->getName());
         $log = new Log();
         $log->setProdName($product->getName());
         $log->setDate(new \DateTime());
         $em = $this->getDoctrine()->getManager();
         $em->persist($log);
         $em->flush();
         echo "Dev : Log saved to database. Product name - " . $product->getName() . " Current time - " . $log->getDate()->format('H:i:s \\O\\n Y-m-d');
         $inBasket = $session->all();
     } else {
         if ($session->count() != 0) {
             $inBasket = $session->all();
             echo "Please select a Product before submitting !!!";
         }
     }
     return $this->render('default/index.html.twig', ['products' => $products, 'basketProds' => $inBasket]);
 }
 /**
  * Generate token string
  */
 private function generateTokenString()
 {
     if ($this->session->isStarted() === false) {
         $this->session->start();
     }
     return sha1($this->secret . $this->session->getId());
 }
Example #10
0
 public function getSession($request)
 {
     if (($session = $request->getSession()) === NULL) {
         $session = new Session();
     }
     if (!$session->isStarted()) {
         $session->start();
     }
     return $session;
 }
Example #11
0
 /**
  * Register the service provider.
  *
  * @return object
  */
 public function register()
 {
     $this->app->singleton('session', function () {
         $storage = new NativeSessionStorage($this->getOptions(), $this->getHandler(), new MetadataBag());
         $session = new SfSession($storage, new AttributeBag('_group_attributes'), new FlashBag());
         if (!$session->isStarted()) {
             $session->start();
         }
         return new SessionService($session);
     });
 }
Example #12
0
 /**
  * @param $type
  * @param null $header
  * @param null $title
  * @param null $message
  * @param null $buttonMessage
  * @return bool
  */
 private function addMessage($type, $header = null, $title = null, $message = null, $buttonMessage = null)
 {
     if (!$this->flashBag && $this->session->isStarted()) {
         $this->flashBag = $this->session->getFlashBag();
     }
     if ($this->flashBag) {
         $this->flashBag->add($type, new FlashMessage($header, $title, $message, $buttonMessage));
         return true;
     }
     return false;
 }
Example #13
0
 /**
  * Apply the Session Strategy
  *
  * @return void
  */
 protected function applySessionStrategy()
 {
     if (!$this->session->isStarted()) {
         return $this->session->start();
     }
     switch ($this->strategy) {
         case self::STRATEGY_MIGRATE:
             $this->session->migrate();
             break;
         case self::STRATEGY_INVALIDATES:
             $this->session->invalidate();
             break;
         default:
             throw new \RuntimeException('Session strategy should be "migrate" or "invalidate"');
     }
 }
 /**
  * @Route("/", name="homepage")
  */
 public function indexAction(Request $request)
 {
     $session = $request->getSession();
     if ($session == null) {
         $session = new Session();
     }
     if (!$session->isStarted()) {
         $session->start();
     }
     //new sessionID if session existed already.
     $session->migrate();
     if ($session->has('originalSessionID')) {
         $session->remove('originalSessionID');
     }
     return $this->render('default/index.html.twig');
 }
 public function getLoginUrls()
 {
     $socialNetworks = $this->socialNetworkRepository->findBy(array('enabled' => true, 'loginEnabled' => true));
     try {
         $session = new Session();
         if (!$session->isStarted()) {
             $session->start();
         }
     } catch (\Exception $e) {
     }
     $urls = array();
     $provider_prefix = "socialhub_provider_";
     foreach ($socialNetworks as $socialNetwork) {
         $socialProvider = $this->container->get($provider_prefix . $socialNetwork->getType());
         $loginUrl = $socialProvider->getLoginUrl();
         $urls[] = array('name' => $socialNetwork->getName(), 'type' => $socialNetwork->getType(), 'label' => "label." . $socialNetwork->getType(), 'url' => $loginUrl);
     }
     return $urls;
 }
 /**
  * @Route("/lucky/number")
  */
 public function numberAction()
 {
     //session
     $session = new Session();
     if (!$session->isStarted()) {
         //$session->start();
     }
     // set and get session attributes
     $session->set('name', 'Drak');
     $session->get('name');
     // set flash messages
     $session->getFlashBag()->add('notice', 'Profile updated');
     // retrieve messages
     $_session_test = '';
     foreach ($session->getFlashBag()->get('notice', array()) as $message) {
         $_session_test .= '<div class="flash-notice">' . $message . '</div>';
     }
     //session.end
     $number = rand(0, 100);
     return new Response('<html><body>Lucky number: ' . $number . $_session_test . '</body></html>');
 }
Example #17
0
 /**
  * Clear Session
  */
 private function clearSession(Session $session)
 {
     if ($session->isStarted()) {
         $session->clear();
     }
 }
Example #18
0
 /**
  * \brief This is where the magic for
  * Authentication happens.
  */
 function PostInitialize()
 {
     global $SysConf;
     /* if Site Minder enabled core-auth will be disabled*/
     if (siteminder_check() != -1) {
         return 0;
     }
     if (!$this->session->isStarted()) {
         $this->session->setName('Login');
         $this->session->start();
     }
     if (array_key_exists('selectMemberGroup', $_POST)) {
         $selectedGroupId = intval($_POST['selectMemberGroup']);
         $this->userDao->setDefaultGroupMembership(intval($_SESSION[Auth::USER_ID]), $selectedGroupId);
         $_SESSION[Auth::GROUP_ID] = $selectedGroupId;
         $this->session->set(Auth::GROUP_ID, $selectedGroupId);
         $SysConf['auth'][Auth::GROUP_ID] = $selectedGroupId;
     }
     if (array_key_exists(Auth::USER_ID, $_SESSION)) {
         $SysConf['auth'][Auth::USER_ID] = $_SESSION[Auth::USER_ID];
     }
     if (array_key_exists(Auth::GROUP_ID, $_SESSION)) {
         $SysConf['auth'][Auth::GROUP_ID] = $_SESSION[Auth::GROUP_ID];
     }
     $Now = time();
     if (!empty($_SESSION['time'])) {
         /* Logins older than 60 secs/min * 480 min = 8 hr are auto-logout */
         if (@$_SESSION['time'] + 60 * 480 < $Now) {
             $this->updateSession("");
         }
     }
     $_SESSION['time'] = $Now;
     if (empty($_SESSION['ip'])) {
         $_SESSION['ip'] = $this->getIP();
     } else {
         if (@$_SESSION['checkip'] == 1 && @$_SESSION['ip'] != $this->getIP()) {
             /* Sessions are not transferable. */
             $this->updateSession("");
             $_SESSION['ip'] = $this->getIP();
         }
     }
     if (@$_SESSION[Auth::USER_NAME]) {
         /* Recheck the user in case he is suddenly blocked or changed. */
         if (empty($_SESSION['time_check'])) {
             $_SESSION['time_check'] = time() + 480 * 60;
         }
         if (time() >= @$_SESSION['time_check']) {
             $row = $this->userDao->getUserAndDefaultGroupByUserName(@$_SESSION[Auth::USER_NAME]);
             /* Check for instant logouts */
             if (empty($row['user_pass'])) {
                 $row = "";
             }
             $this->updateSession($row);
         }
     } else {
         $this->updateSession("");
     }
     /* Disable all plugins with >= level access */
     plugin_disable($_SESSION[Auth::USER_LEVEL]);
     $this->State = PLUGIN_STATE_READY;
 }
Example #19
0
 /**
  * {@inheritdoc}
  */
 public function processResponse(Request $request, Response $response)
 {
     if ($this->session->isStarted()) {
         $this->session->save();
     }
 }
 private function getSessionID($request)
 {
     $session = $request->getSession();
     $logger = $this->get('logger');
     if (!$session instanceof Session) {
         $logger->info('Session Not Found');
         $session = new Session();
         $session->start();
     } else {
         if (!$session->isStarted()) {
             $logger->info('Session Started');
             $session->start();
         }
         $logger->info('Session Found = ' . $session->getId());
     }
     $logger->info('Session ID = ' . $session->getId());
     return $session->getId();
 }