diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2017-10-23 11:09:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-23 11:09:17 +0200 |
commit | 1953a872932a63792293b4aec087880265ba89f7 (patch) | |
tree | fd16599e737fcdaf193c933ef3ec4a4ee248b117 /src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php | |
parent | d83d25dadec2c38460a32d96f5d2903426fec9d3 (diff) | |
parent | 702f2d67d60ca963492b90dad74cb5f8dcc84e51 (diff) | |
download | wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.gz wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.zst wallabag-1953a872932a63792293b4aec087880265ba89f7.zip |
Merge pull request #3011 from wallabag/2.3
wallabag 2.3.0
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php new file mode 100644 index 00000000..36906761 --- /dev/null +++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php | |||
@@ -0,0 +1,47 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Repository; | ||
4 | |||
5 | use Wallabag\CoreBundle\Helper\CryptoProxy; | ||
6 | |||
7 | /** | ||
8 | * SiteCredentialRepository. | ||
9 | */ | ||
10 | class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository | ||
11 | { | ||
12 | private $cryptoProxy; | ||
13 | |||
14 | public function setCrypto(CryptoProxy $cryptoProxy) | ||
15 | { | ||
16 | $this->cryptoProxy = $cryptoProxy; | ||
17 | } | ||
18 | |||
19 | /** | ||
20 | * Retrieve one username/password for the given host and userId. | ||
21 | * | ||
22 | * @param string $host | ||
23 | * @param int $userId | ||
24 | * | ||
25 | * @return null|array | ||
26 | */ | ||
27 | public function findOneByHostAndUser($host, $userId) | ||
28 | { | ||
29 | $res = $this->createQueryBuilder('s') | ||
30 | ->select('s.username', 's.password') | ||
31 | ->where('s.host = :hostname')->setParameter('hostname', $host) | ||
32 | ->andWhere('s.user = :userId')->setParameter('userId', $userId) | ||
33 | ->setMaxResults(1) | ||
34 | ->getQuery() | ||
35 | ->getOneOrNullResult(); | ||
36 | |||
37 | if (null === $res) { | ||
38 | return; | ||
39 | } | ||
40 | |||
41 | // decrypt user & password before returning them | ||
42 | $res['username'] = $this->cryptoProxy->decrypt($res['username']); | ||
43 | $res['password'] = $this->cryptoProxy->decrypt($res['password']); | ||
44 | |||
45 | return $res; | ||
46 | } | ||
47 | } | ||