use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder;
use Graby\SiteConfig\ConfigBuilder;
use Psr\Log\LoggerInterface;
+use Wallabag\CoreBundle\Repository\SiteCredentialRepository;
+use Wallabag\UserBundle\Entity\User;
class GrabySiteConfigBuilder implements SiteConfigBuilder
{
* @var ConfigBuilder
*/
private $grabyConfigBuilder;
+
/**
- * @var array
+ * @var SiteCredentialRepository
*/
- private $credentials;
+ private $credentialRepository;
+
/**
* @var LoggerInterface
*/
private $logger;
+ /**
+ * @var User
+ */
+ private $currentUser;
+
+
/**
* GrabySiteConfigBuilder constructor.
*
- * @param ConfigBuilder $grabyConfigBuilder
- * @param array $credentials
+ * @param ConfigBuilder $grabyConfigBuilder
+ * @param User $currentUser
+ * @param SiteCredentialRepository $credentialRepository
* @param LoggerInterface $logger
*/
- public function __construct(ConfigBuilder $grabyConfigBuilder, array $credentials, LoggerInterface $logger)
+ public function __construct(ConfigBuilder $grabyConfigBuilder, User $currentUser, SiteCredentialRepository $credentialRepository, LoggerInterface $logger)
{
$this->grabyConfigBuilder = $grabyConfigBuilder;
- $this->credentials = $credentials;
+ $this->credentialRepository = $credentialRepository;
+ $this->currentUser = $currentUser;
$this->logger = $logger;
}
$host = substr($host, 4);
}
- if (empty($this->credentials[$host])) {
+ $credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId());
+
+ if (null === $credentials) {
$this->logger->debug('Auth: no credentials available for host.', ['host' => $host]);
return false;
'passwordField' => $config->login_password_field ?: null,
'extraFields' => $this->processExtraFields($config->login_extra_fields),
'notLoggedInXpath' => $config->not_logged_in_xpath ?: null,
- 'username' => $this->credentials[$host]['username'],
- 'password' => $this->credentials[$host]['password'],
+ 'username' => $credentials['username'],
+ 'password' => $credentials['password'],
];
$config = new SiteConfig($parameters);
*/
class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository
{
+ /**
+ * Retrieve one username/password for the given host and userId.
+ *
+ * @param string $host
+ * @param int $userId
+ *
+ * @return null|array
+ */
+ public function findOneByHostAndUser($host, $userId)
+ {
+ return $this->createQueryBuilder('s')
+ ->select('s.username', 's.password')
+ ->where('s.host = :hostname')->setParameter('hostname', $host)
+ ->andWhere('s.user = :userId')->setParameter('userId', $userId)
+ ->setMaxResults(1)
+ ->getQuery()
+ ->getOneOrNullResult();
+ }
}
class: Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder
arguments:
- "@wallabag_core.graby.config_builder"
- - "%sites_credentials%"
+ - "@=service('security.token_storage').getToken().getUser()"
+ - "@wallabag_core.site_credential_repository"
- '@logger'
tags:
- { name: monolog.logger, channel: graby }
arguments:
- WallabagCoreBundle:Tag
+ wallabag_core.site_credential_repository:
+ class: Wallabag\CoreBundle\Repository\SiteCredentialRepository
+ factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
+ arguments:
+ - WallabagCoreBundle:SiteCredential
+
wallabag_core.helper.entries_export:
class: Wallabag\CoreBundle\Helper\EntriesExport
arguments: