diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-05-01 22:13:17 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2017-06-20 16:03:13 +0200 |
commit | 5a9bc00726ddaf7c8798d4932d0a8b7a38422670 (patch) | |
tree | 487a36da4997b305da9113985785fdf7e97c1811 /src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php | |
parent | fc6d92c63dc5629a9e005628e416e0ecf4daa6ed (diff) | |
download | wallabag-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/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php')
-rw-r--r-- | src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php | 32 |
1 files changed, 23 insertions, 9 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; | |||
6 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder; | 6 | use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfigBuilder; |
7 | use Graby\SiteConfig\ConfigBuilder; | 7 | use Graby\SiteConfig\ConfigBuilder; |
8 | use Psr\Log\LoggerInterface; | 8 | use Psr\Log\LoggerInterface; |
9 | use Wallabag\CoreBundle\Repository\SiteCredentialRepository; | ||
10 | use Wallabag\UserBundle\Entity\User; | ||
9 | 11 | ||
10 | class GrabySiteConfigBuilder implements SiteConfigBuilder | 12 | class 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); |