/** * 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; }
/** * Get filtered user properties from user provider * * @static * @access public * @param UserProviderInterface $user * @return array */ public static function getProperties(UserProviderInterface $user) { $properties = array('username' => $user->getUsername(), 'name' => $user->getName(), 'email' => $user->getEmail(), 'role' => $user->getRole(), $user->getExternalIdColumn() => $user->getExternalId()); $properties = array_merge($properties, $user->getExtraAttributes()); return array_filter($properties, array(__NAMESPACE__ . '\\UserProperty', 'isNotEmptyValue')); }