X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FGuzzleSiteAuthenticator%2FGrabySiteConfigBuilder.php;h=b0be21763c4db127bfd6e08ccfc26c832f5de365;hb=a9753ef99018a0b92e6af1f9a6e98fa3c7e92792;hp=90e00c62d9aaeff353e5f356ec6fcc4703e9d5db;hpb=2a1ceb67b4400f46f4d3067e887ff54aa906f0a2;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php index 90e00c62..b0be2176 100644 --- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php +++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php @@ -34,11 +34,6 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder /** * GrabySiteConfigBuilder constructor. - * - * @param ConfigBuilder $grabyConfigBuilder - * @param TokenStorage $token - * @param SiteCredentialRepository $credentialRepository - * @param LoggerInterface $logger */ public function __construct(ConfigBuilder $grabyConfigBuilder, TokenStorage $token, SiteCredentialRepository $credentialRepository, LoggerInterface $logger) { @@ -62,11 +57,24 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder $host = substr($host, 4); } - $credentials = null; - if ($this->currentUser) { - $credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId()); + if (!$this->currentUser) { + $this->logger->debug('Auth: no current user defined.'); + + return false; } + $hosts = [$host]; + // will try to see for a host without the first subdomain (fr.example.org & .example.org) + $split = explode('.', $host); + + if (\count($split) > 1) { + // remove first subdomain + array_shift($split); + $hosts[] = '.' . implode('.', $split); + } + + $credentials = $this->credentialRepository->findOneByHostsAndUser($hosts, $this->currentUser->getId()); + if (null === $credentials) { $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]);