]>
Commit | Line | Data |
---|---|---|
f92fcb53 JB |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\Repository; | |
4 | ||
906424c1 JB |
5 | use Wallabag\CoreBundle\Helper\CryptoProxy; |
6 | ||
f92fcb53 JB |
7 | /** |
8 | * SiteCredentialRepository. | |
f92fcb53 JB |
9 | */ |
10 | class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository | |
11 | { | |
906424c1 JB |
12 | private $cryptoProxy; |
13 | ||
14 | public function setCrypto(CryptoProxy $cryptoProxy) | |
15 | { | |
16 | $this->cryptoProxy = $cryptoProxy; | |
17 | } | |
18 | ||
5a9bc007 JB |
19 | /** |
20 | * Retrieve one username/password for the given host and userId. | |
21 | * | |
f4549633 JB |
22 | * @param array $hosts An array of host to look for |
23 | * @param int $userId | |
5a9bc007 | 24 | * |
0182cdae | 25 | * @return array|null |
5a9bc007 | 26 | */ |
f4549633 | 27 | public function findOneByHostsAndUser($hosts, $userId) |
5a9bc007 | 28 | { |
906424c1 | 29 | $res = $this->createQueryBuilder('s') |
5a9bc007 | 30 | ->select('s.username', 's.password') |
f4549633 | 31 | ->where('s.host IN (:hosts)')->setParameter('hosts', $hosts) |
5a9bc007 JB |
32 | ->andWhere('s.user = :userId')->setParameter('userId', $userId) |
33 | ->setMaxResults(1) | |
34 | ->getQuery() | |
35 | ->getOneOrNullResult(); | |
906424c1 JB |
36 | |
37 | if (null === $res) { | |
38 | return; | |
39 | } | |
40 | ||
bead8b42 TC |
41 | // decrypt user & password before returning them |
42 | $res['username'] = $this->cryptoProxy->decrypt($res['username']); | |
906424c1 JB |
43 | $res['password'] = $this->cryptoProxy->decrypt($res['password']); |
44 | ||
45 | return $res; | |
5a9bc007 | 46 | } |
f92fcb53 | 47 | } |