示例#1
0
 /**
  * Tries to read the username from the cookie.
  *
  * @param  UserProviderInterface $provider
  * @return UserInterface
  * @throws AuthException
  */
 public function autoLogin(UserProviderInterface $provider)
 {
     try {
         if (null === ($cookie = $this->cookie->get($this->name))) {
             throw new AuthException('No remember me cookie found.');
         }
         $cookieParts = $this->decodeCookie($cookie);
         if (count($cookieParts) !== 3) {
             throw new AuthException('The cookie is invalid.');
         }
         list($username, $expires, $hash) = $cookieParts;
         if ($expires < time()) {
             throw new AuthException('The cookie has expired.');
         }
         if (false === ($username = base64_decode($username, true))) {
             throw new AuthException(sprintf('"%s" contains a character from outside the base64 alphabet.', $username));
         }
         if (!($user = $provider->findByUsername($username))) {
             throw new AuthException(sprintf('No user found for "%s".', $username));
         }
         if (true !== $this->compareHashes($hash, $this->generateCookieHash($username, $expires, $user->getPassword()))) {
             throw new AuthException('The cookie\'s hash is invalid.');
         }
     } catch (AuthException $e) {
         $this->remove();
         throw $e;
     }
     return $user;
 }
 public function testHasGet()
 {
     $this->cookieJar->set('testCookie', 'testValue');
     $this->assertTrue($this->cookieJar->has('testCookie'));
     $this->assertEquals('testValue', $this->cookieJar->get('testCookie')->getValue());
 }
示例#3
0
 public function testSet()
 {
     $this->cookie = $this->cookieJar->set('aCookie', $this->cookieJar->get('testCookie'));
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Cookie', $this->cookie);
     $this->assertEquals('testValue', $this->cookie->getValue());
 }