Ejemplo n.º 1
0
 public function testGetResponseValue()
 {
     Cookies::reset();
     Cookies::set($name = 'hello', $value = 'world');
     $cookie = Cookies::get($name);
     $cookie->useEncryption(false);
     $this->assertEquals($name, $cookie->getName());
     $this->assertEquals($value, $cookie->getResponseValue());
     $cookie->useEncryption(true);
     $this->assertNotEquals($value, $encrypted = $cookie->getResponseValue());
     /* @var \Phalcon\Crypt $crypt */
     $crypt = $this->di->getShared('crypt');
     $this->assertEquals($value, $crypt->decryptBase64($encrypted));
     Cookies::reset();
 }
Ejemplo n.º 2
0
 protected function realTestSessionCRUD($driver)
 {
     Config::set('session.default', $driver);
     Session::register($this->di);
     $suffix = " ({$driver})";
     Session::flush();
     // Start session
     $this->assertFalse(isset($_SESSION), '$_SESSION should not exist before session start' . $suffix);
     $this->assertTrue(Session::start(), 'Failed to start session' . $suffix);
     $this->assertFalse(Session::start(), 'Should not start duplicated sessions' . $suffix);
     // Get session id
     $this->assertNotEmpty($sid = Session::getId(), 'Session id not generated');
     // Session detection
     $this->assertTrue(isset($_SESSION), '$_SESSION should exist after session start' . $suffix);
     $this->assertFalse(isset($_SESSION[$key = 'test_key']), 'Session value should not exist before set' . $suffix);
     // Set session value
     Session::set($key, $value = 'Test value');
     $this->assertTrue(isset($_SESSION[$key]), 'Session value should exist after set' . $suffix);
     $this->assertEquals($value, $_SESSION[$key], 'Bad session set result' . $suffix);
     // Update session value
     Session::set($key, $value = 'Test value 2');
     $this->assertEquals($value, $_SESSION[$key], 'Bad session update result' . $suffix);
     // Delete session value
     Session::remove($key);
     $this->assertFalse(isset($_SESSION[$key]), 'Session value should be deleted' . $suffix);
     // Load existing session
     Session::set($key, $value);
     Session::end();
     $this->assertEquals($sid, Cookies::get('phwoolcon')->getValue(), 'Session cookie not set properly' . $suffix);
     $this->assertFalse(isset($_SESSION), '$_SESSION should be ended' . $suffix);
     $this->assertTrue(Session::start(), 'Failed to restart session' . $suffix);
     $this->assertEquals($value, $_SESSION[$key], 'Bad session load result' . $suffix);
     Session::end();
     Config::set('session.default', 'native');
     Session::register($this->di);
 }
Ejemplo n.º 3
0
 public function setCookie()
 {
     $now = time();
     if ($lazyRenew = $this->_options['cookie_lazy_renew_interval']) {
         if ($this->cookieRenewedAt + $lazyRenew > $now) {
             return $this;
         }
         $this->set('_cookie_renewed_at', $this->cookieRenewedAt = $now);
     }
     Cookies::set($cookieName = $this->getName(), $this->getId(), $now + $this->_options['lifetime'], $this->_options['cookies']['path'], $this->_options['cookies']['secure'], $this->_options['cookies']['domain'], $this->_options['cookies']['http_only']);
     Cookies::get($cookieName)->useEncryption(false);
     return $this;
 }
Ejemplo n.º 4
0
 public function logout()
 {
     if ($this->getUser() && method_exists($this->user, 'removeRememberToken')) {
         $this->user->removeRememberToken();
     }
     Cookies::set($cookieName = $this->options['remember_login']['cookie_key'], '', null, null, null, null, true);
     Cookies::get($cookieName)->useEncryption(false);
     $this->user = null;
     Session::clear();
     return $this;
 }
Ejemplo n.º 5
0
 public function reset()
 {
     if (!$this->multiLocale) {
         return;
     }
     $this->request or $this->request = static::$di->getShared('request');
     if ($locale = $this->request->get('_locale')) {
         $this->_setLocale($locale);
         return;
     }
     if (($cookie = Cookies::get('locale')) && ($locale = $cookie->useEncryption(false)->getValue())) {
         $this->_setLocale($locale);
         $cookie->setHttpOnly(false)->delete();
         return;
     }
     if ($locale = Session::get('current_locale')) {
         $this->loadLocale($this->currentLocale = $locale);
         return;
     }
     // @codeCoverageIgnoreStart
     if ($this->detectClientLocale) {
         $this->_setLocale($this->request->getBestLanguage());
         return;
     }
     // @codeCoverageIgnoreEnd
     $this->loadLocale($this->currentLocale = $this->defaultLocale);
 }