aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-05-01 22:13:17 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-06-20 16:03:13 +0200
commit5a9bc00726ddaf7c8798d4932d0a8b7a38422670 (patch)
tree487a36da4997b305da9113985785fdf7e97c1811 /src/Wallabag
parentfc6d92c63dc5629a9e005628e416e0ecf4daa6ed (diff)
downloadwallabag-5a9bc00726ddaf7c8798d4932d0a8b7a38422670.tar.gz
wallabag-5a9bc00726ddaf7c8798d4932d0a8b7a38422670.tar.zst
wallabag-5a9bc00726ddaf7c8798d4932d0a8b7a38422670.zip
Retrieve username/password from database
Inject the current user & the repo to retrieve username/password from the database
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php32
-rw-r--r--src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php18
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml9
3 files changed, 49 insertions, 10 deletions
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
index 1c56fa9f..94615687 100644
--- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
+++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php
@@ -6,6 +6,8 @@ use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig;
6use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder; 6use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder;
7use Graby\SiteConfig\ConfigBuilder; 7use Graby\SiteConfig\ConfigBuilder;
8use Psr\Log\LoggerInterface; 8use Psr\Log\LoggerInterface;
9use Wallabag\CoreBundle\Repository\SiteCredentialRepository;
10use Wallabag\UserBundle\Entity\User;
9 11
10class GrabySiteConfigBuilder implements SiteConfigBuilder 12class GrabySiteConfigBuilder implements SiteConfigBuilder
11{ 13{
@@ -13,26 +15,36 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
13 * @var ConfigBuilder 15 * @var ConfigBuilder
14 */ 16 */
15 private $grabyConfigBuilder; 17 private $grabyConfigBuilder;
18
16 /** 19 /**
17 * @var array 20 * @var SiteCredentialRepository
18 */ 21 */
19 private $credentials; 22 private $credentialRepository;
23
20 /** 24 /**
21 * @var LoggerInterface 25 * @var LoggerInterface
22 */ 26 */
23 private $logger; 27 private $logger;
24 28
25 /** 29 /**
30 * @var User
31 */
32 private $currentUser;
33
34
35 /**
26 * GrabySiteConfigBuilder constructor. 36 * GrabySiteConfigBuilder constructor.
27 * 37 *
28 * @param ConfigBuilder $grabyConfigBuilder 38 * @param ConfigBuilder $grabyConfigBuilder
29 * @param array $credentials 39 * @param User $currentUser
40 * @param SiteCredentialRepository $credentialRepository
30 * @param LoggerInterface $logger 41 * @param LoggerInterface $logger
31 */ 42 */
32 public function __construct(ConfigBuilder $grabyConfigBuilder, array $credentials, LoggerInterface $logger) 43 public function __construct(ConfigBuilder $grabyConfigBuilder, User $currentUser, SiteCredentialRepository $credentialRepository, LoggerInterface $logger)
33 { 44 {
34 $this->grabyConfigBuilder = $grabyConfigBuilder; 45 $this->grabyConfigBuilder = $grabyConfigBuilder;
35 $this->credentials = $credentials; 46 $this->credentialRepository = $credentialRepository;
47 $this->currentUser = $currentUser;
36 $this->logger = $logger; 48 $this->logger = $logger;
37 } 49 }
38 50
@@ -47,7 +59,9 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
47 $host = substr($host, 4); 59 $host = substr($host, 4);
48 } 60 }
49 61
50 if (empty($this->credentials[$host])) { 62 $credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId());
63
64 if (null === $credentials) {
51 $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]); 65 $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]);
52 66
53 return false; 67 return false;
@@ -62,8 +76,8 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
62 'passwordField' => $config->login_password_field ?: null, 76 'passwordField' => $config->login_password_field ?: null,
63 'extraFields' => $this->processExtraFields($config->login_extra_fields), 77 'extraFields' => $this->processExtraFields($config->login_extra_fields),
64 'notLoggedInXpath' => $config->not_logged_in_xpath ?: null, 78 'notLoggedInXpath' => $config->not_logged_in_xpath ?: null,
65 'username' => $this->credentials[$host]['username'], 79 'username' => $credentials['username'],
66 'password' => $this->credentials[$host]['password'], 80 'password' => $credentials['password'],
67 ]; 81 ];
68 82
69 $config = new SiteConfig($parameters); 83 $config = new SiteConfig($parameters);
diff --git a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
index 88aee6d5..316ecc75 100644
--- a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
@@ -7,4 +7,22 @@ namespace Wallabag\CoreBundle\Repository;
7 */ 7 */
8class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository 8class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository
9{ 9{
10 /**
11 * Retrieve one username/password for the given host and userId.
12 *
13 * @param string $host
14 * @param int $userId
15 *
16 * @return null|array
17 */
18 public function findOneByHostAndUser($host, $userId)
19 {
20 return $this->createQueryBuilder('s')
21 ->select('s.username', 's.password')
22 ->where('s.host = :hostname')->setParameter('hostname', $host)
23 ->andWhere('s.user = :userId')->setParameter('userId', $userId)
24 ->setMaxResults(1)
25 ->getQuery()
26 ->getOneOrNullResult();
27 }
10} 28}
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index 4be79547..a59152d3 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -63,7 +63,8 @@ services:
63 class: Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder 63 class: Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder
64 arguments: 64 arguments:
65 - "@wallabag_core.graby.config_builder" 65 - "@wallabag_core.graby.config_builder"
66 - "%sites_credentials%" 66 - "@=service('security.token_storage').getToken().getUser()"
67 - "@wallabag_core.site_credential_repository"
67 - '@logger' 68 - '@logger'
68 tags: 69 tags:
69 - { name: monolog.logger, channel: graby } 70 - { name: monolog.logger, channel: graby }
@@ -120,6 +121,12 @@ services:
120 arguments: 121 arguments:
121 - WallabagCoreBundle:Tag 122 - WallabagCoreBundle:Tag
122 123
124 wallabag_core.site_credential_repository:
125 class: Wallabag\CoreBundle\Repository\SiteCredentialRepository
126 factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
127 arguments:
128 - WallabagCoreBundle:SiteCredential
129
123 wallabag_core.helper.entries_export: 130 wallabag_core.helper.entries_export:
124 class: Wallabag\CoreBundle\Helper\EntriesExport 131 class: Wallabag\CoreBundle\Helper\EntriesExport
125 arguments: 132 arguments: