/**
  * {@inheritdoc}
  */
 protected function getSessionId()
 {
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
     return $this->session->getId();
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function isSessionStarted()
 {
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
     return $this->session->isStarted();
 }
 /**
  * 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();
     }
 }
Example #4
0
 public function __construct(Mysql $db, Session $session)
 {
     $this->db = $db;
     $this->session = $session;
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
 }
Example #5
0
 /**
  * Initialize the Controller
  * Sets all attributes and starts the session
  *
  * @param $request
  * @param $em
  * @param $twig
  * @param $formFactory
  */
 public function init($request, $em, $twig, $formFactory)
 {
     $this->request = $request;
     $this->em = $em;
     $this->twig = $twig;
     $this->formFactory = $formFactory;
     $this->session = new Session();
     $this->session->start();
 }
Example #6
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 #7
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 #8
0
 /**
  * Initialize the session.
  *
  * This is something you might want to override in your controller so you can
  * redirect to a page with a message about being logged out after detecting the session has expired.
  *
  * @var int $session_expiration Session Expiration in seconds
  */
 protected function initializeSession($session_expiration = null)
 {
     /**
      * Setup the session with cookie expiration of one week. This will
      * allow the session to persist even if the browser window is closed.
      * The session expiration will still be respected (default 1 hour).
      */
     $this->session = new Session(new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage(['cookie_lifetime' => 604800]));
     $this->config->load('config');
     // Should session cookie be http only? Default true to reduce XSS attack vector.
     $session_cookie_httponly = (bool) $this->config->get('session_cookie_httponly', true);
     ini_set('session.cookie_httponly', $session_cookie_httponly);
     // We need a unique session name for this app. Let's use last 10 characters the file path's sha1 hash.
     try {
         $this->session->setName('TSAPP' . substr(sha1(__FILE__), -10));
         $this->session->start();
         // Default session expiration 1 hour.
         // Can be overridden in method param or by setting session_expiration in config.php
         $session_expiration = !empty($session_expiration) ? $session_expiration : $this->config->get('session_expiration', 3600);
         // Is this session too old?
         if (time() - $this->session->getMetadataBag()->getLastUsed() > $session_expiration) {
             $this->session->invalidate();
         }
     } catch (\LogicException $e) {
         // Session already active, can't change it now!
     }
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function start()
 {
     parent::start();
     if (!$this->has('_token')) {
         $this->put('_token', str_random(40));
     }
 }
function initSession()
{
    $storage = new NativeSessionStorage(['cookie_lifetime' => 3600, 'gc_probability' => 1, 'gc_divisor' => 1, 'gc_maxlifetime' => 10000], new NativeFileSessionHandler());
    $session = new Session($storage, new NamespacedAttributeBag());
    $session->start();
    return $session;
}
 public function indexAction()
 {
     $session = new Session();
     $session->start();
     $user_session = $session->get('username');
     return $this->render('goldtaskAppBundle:Default:index.html.twig');
 }
Example #12
0
 /**
  * @Route("/", name="homepage")
  */
 public function indexAction(Request $request)
 {
     //start session
     $session = new Session(new PhpBridgeSessionStorage());
     $session->start();
     $session->set('date', time());
     //get products from DB
     $products = $this->getDoctrine()->getRepository('AppBundle:Cart')->findAll();
     //get session products
     $sessionProducts = $session->get('products');
     $productArray = null;
     //if post save to db && session
     if ($request->isMethod('post')) {
         $postProduct = [$request->request->get('product')];
         if (!empty($sessionProducts)) {
             $productArray = array_merge($sessionProducts, $postProduct);
         } else {
             $productArray = $postProduct;
         }
         $productArray = array_unique($productArray);
     }
     $session->set('products', $productArray);
     // this helps create cookie for session
     $session->save();
     return $this->render('default/index.html.twig', array('sessionProducts' => $productArray, 'products' => $products));
 }
 /**
  * @param Container $pimple A container instance
  */
 public function register(Container $pimple)
 {
     $pimple[SystemContainer::REQUEST] = function () {
         return Request::createFromGlobals();
     };
     $pimple[SystemContainer::SESSION] = function () {
         if ($this->mockSession) {
             $session = new Session(new MockArraySessionStorage());
         } else {
             $session = new Session();
         }
         $session->setName(sprintf('SID%s', mt_rand(1000, 9999)));
         $session->start();
         return $session;
     };
     $pimple[SystemContainer::TIME_PROVIDER] = function () {
         return new SystemTimeProvider();
     };
     $pimple[SystemContainer::EVENT_DISPATCHER] = function () {
         return new EventDispatcher();
     };
     $pimple[SystemContainer::LOGGER] = function () {
         return new NullLogger();
     };
 }
 function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6')
 {
     $code = $this->generateCode($characters);
     /* font size will be 75% of the image height */
     $font_size = $height * 0.75;
     $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $background_color = imagecolorallocate($image, 255, 255, 255);
     $text_color = imagecolorallocate($image, 20, 40, 100);
     $noise_color = imagecolorallocate($image, 100, 120, 180);
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     /* generate random lines in background */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     /* create textbox and add text */
     $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
     /* output captcha image to browser */
     $session = new Session();
     $session->start();
     $session->set('security_code', $code);
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
 }
 /**
  * Generate token string
  */
 private function generateTokenString()
 {
     if ($this->session->isStarted() === false) {
         $this->session->start();
     }
     return sha1($this->secret . $this->session->getId());
 }
Example #16
0
 public function get()
 {
     $storage = new MockArraySessionStorage();
     $session = new Session($storage);
     $session->start();
     return $session;
 }
Example #17
0
 /**
  * Create new Xerxes Request
  */
 public static function createFromGlobals(ControllerMap $controller_map)
 {
     $registry = Registry::getInstance();
     // reverse proxy
     if ($registry->getConfig("REVERSE_PROXIES", false)) {
         self::$trustProxy = true;
         self::$trustedProxies = explode(',', $registry->getConfig("REVERSE_PROXIES"));
     }
     // request
     $request = parent::createFromGlobals();
     // set cookie path and name
     $basepath = $request->getBasePath();
     $id = strtolower($basepath);
     $id = preg_replace('/\\//', '_', $id);
     $id = 'xerxessession_' . $id;
     $session_options = array('name' => $id, 'cookie_path' => $basepath == '' ? '/' : $basepath);
     $storage = new NativeSessionStorage($session_options);
     // session
     $session = new Session($storage);
     $session->start();
     // register these mo-fo's
     $request->setRegistry($registry);
     $request->setSession($session);
     $request->setControllerMap($controller_map);
     // do our special mapping
     $request->extractQueryParams();
     return $request;
 }
 public function setUp()
 {
     $this->numberOfPayloads = 5;
     $this->tempDirectory = sys_get_temp_dir() . '/orphanage';
     $this->realDirectory = sys_get_temp_dir() . '/storage';
     $this->payloads = array();
     $filesystem = new Filesystem();
     $filesystem->mkdir($this->tempDirectory);
     $filesystem->mkdir($this->realDirectory);
     for ($i = 0; $i < $this->numberOfPayloads; $i++) {
         // create temporary file
         $file = tempnam(sys_get_temp_dir(), 'uploader');
         $pointer = fopen($file, 'w+');
         fwrite($pointer, str_repeat('A', 1024), 1024);
         fclose($pointer);
         $this->payloads[] = new FilesystemFile(new UploadedFile($file, $i . 'grumpycat.jpeg', null, null, null, true));
     }
     // create underlying storage
     $this->storage = new FilesystemStorage($this->realDirectory);
     // is ignored anyways
     $chunkStorage = new FilesystemChunkStorage('/tmp/');
     // create orphanage
     $session = new Session(new MockArraySessionStorage());
     $session->start();
     $config = array('directory' => $this->tempDirectory);
     $this->orphanage = new FilesystemOrphanageStorage($this->storage, $session, $chunkStorage, $config, 'cat');
 }
Example #19
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]);
 }
 public function setUp()
 {
     $this->numberOfPayloads = 5;
     $this->realDirectory = sys_get_temp_dir() . '/storage';
     $this->chunkDirectory = $this->realDirectory . '/' . $this->chunksKey;
     $this->tempDirectory = $this->realDirectory . '/' . $this->orphanageKey;
     $this->payloads = array();
     if (!$this->checkIfTempnameMatchesAfterCreation()) {
         $this->markTestSkipped('Temporary directories do not match');
     }
     $filesystem = new \Symfony\Component\Filesystem\Filesystem();
     $filesystem->mkdir($this->realDirectory);
     $filesystem->mkdir($this->chunkDirectory);
     $filesystem->mkdir($this->tempDirectory);
     $adapter = new Adapter($this->realDirectory, true);
     $filesystem = new GaufretteFilesystem($adapter);
     $this->storage = new GaufretteStorage($filesystem, 100000);
     $chunkStorage = new GaufretteChunkStorage($filesystem, 100000, null, 'chunks');
     // create orphanage
     $session = new Session(new MockArraySessionStorage());
     $session->start();
     $config = array('directory' => 'orphanage');
     $this->orphanage = new GaufretteOrphanageStorage($this->storage, $session, $chunkStorage, $config, 'cat');
     for ($i = 0; $i < $this->numberOfPayloads; $i++) {
         // create temporary file as if it was reassembled by the chunk manager
         $file = tempnam($this->chunkDirectory, 'uploader');
         $pointer = fopen($file, 'w+');
         fwrite($pointer, str_repeat('A', 1024), 1024);
         fclose($pointer);
         //gaufrette needs the key relative to it's root
         $fileKey = str_replace($this->realDirectory, '', $file);
         $this->payloads[] = new GaufretteFile(new File($fileKey, $filesystem), $filesystem);
     }
 }
Example #21
0
 public function loginProcessAction()
 {
     $userId = $this->get("request")->request->get("user_id");
     $em = $this->getDoctrine()->getManager();
     $session = new Session();
     $session->clear();
     $session->start();
     if (strpos($userId, "teacher") != 0) {
         $userId = str_replace("_teacher_", "", $userId);
         $teacher = $em->getRepository("sociaLecompsSuperBundle:Teacher")->find($userId);
         $session->set("user_id", $teacher->getId());
         $session->set("name", $teacher->getName());
         $session->set("last_name", $teacher->getLastName());
         $session->set("privilege", "teacher");
         return $this->redirect($this->generateUrl("socia_lecomps_teacher_homepage"));
     } else {
         $userId = str_replace("_student_", "", $userId);
         $student = $em->getRepository("sociaLecompsSuperBundle:Student")->find($userId);
         $session->set("user_id", $student->getId());
         $session->set("name", $student->getName());
         $session->set("last_name", $student->getLastName());
         $session->set("privilege", "student");
         return $this->redirect($this->generateUrl("socia_lecomps_student_homepage"));
     }
 }
 public function testImplicitGrant()
 {
     // Start session manually.
     $session = new Session(new MockFileSessionStorage());
     $session->start();
     // Query authorization endpoint with response_type = token.
     $parameters = array('response_type' => 'token', 'client_id' => 'http://democlient1.com/', 'redirect_uri' => 'http://democlient1.com/redirect_uri', 'scope' => 'demoscope1', 'state' => $session->getId());
     $server = array('PHP_AUTH_USER' => 'demousername1', 'PHP_AUTH_PW' => 'demopassword1');
     $client = $this->createClient();
     $crawler = $client->request('GET', '/api/oauth2/authorize', $parameters, array(), $server);
     $this->assertTrue($client->getResponse()->isRedirect());
     // Check basic auth response that can simply compare.
     $authResponse = Request::create($client->getResponse()->headers->get('Location'), 'GET');
     $this->assertEquals('http://democlient1.com/redirect_uri', $authResponse->getSchemeAndHttpHost() . $authResponse->getBaseUrl() . $authResponse->getPathInfo());
     // Check basic token response that can simply compare.
     $tokenResponse = $authResponse->query->all();
     $this->assertEquals('bearer', $tokenResponse['token_type']);
     $this->assertEquals('demoscope1', $tokenResponse['scope']);
     $this->assertEquals($session->getId(), $tokenResponse['state']);
     // Query debug endpoint with access_token.
     $parameters = array();
     $server = array('HTTP_Authorization' => implode(' ', array('Bearer', $tokenResponse['access_token'])));
     $client = $this->createClient();
     $crawler = $client->request('GET', '/api/oauth2/debug', $parameters, array(), $server);
     $debugResponse = json_decode($client->getResponse()->getContent(), true);
     $this->assertEquals('demousername1', $debugResponse['username']);
 }
Example #23
0
 /**
  * {@inheritDoc}
  *
  * This method restores persisted services.
  */
 public function start()
 {
     $started = parent::start();
     if ($started) {
         $this->restorePersistedServices();
     }
     return $started;
 }
Example #24
0
 /**
  * Get a session object.
  *
  * @return  Session
  *
  * @since   1.0
  */
 public function getSession()
 {
     if (is_null($this->newSession)) {
         $this->newSession = new Session();
         $this->newSession->start();
     }
     return $this->newSession;
 }
 /**
  * @Route("/codecaisse",name="codecaisse")
  * @Template()
  * 
  */
 public function CodecaisseAction(Request $request)
 {
     /*         * Creer une session* */
     $session = new Session();
     $session->start();
     $session->set('Codecaisse', $request->get('codecaisse'));
     return $this->redirect($this->generateUrl("index"));
 }
Example #26
0
 public function start()
 {
     $request = Request::createFromGlobals();
     $response = new Response();
     $session = new Session();
     $session->start();
     return $this->handle($request, $response, $session);
 }
Example #27
0
 /**
  * Init session
  *
  * @return Session
  */
 public static function create(ServiceContainer $app)
 {
     $options = $app->config['session'];
     $storage = new NativeSessionStorage($options, new NativeFileSessionHandler());
     $session = new Session($storage);
     $session->start();
     return $session;
 }
 public function testNothingIsPersisted()
 {
     session_id('nullsessionstorage');
     $storage = $this->getStorage();
     $session = new Session($storage);
     $session->start();
     $this->assertEquals('nullsessionstorage', $session->getId());
     $this->assertNull($session->get('something'));
 }
Example #29
0
 /**
  * Runner constructor.
  */
 public function __construct()
 {
     static::$request = Request::createFromGlobals();
     if (!static::$request->hasPreviousSession()) {
         $session = new Session();
         $session->start();
         static::$request->setSession($session);
     }
 }
 /**
  * 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());
         $session->start();
         return new SessionService($session);
     });
 }