X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FSiteCredentialRepository.php;h=b2e212a41438cc32d7e3bbab212aed78382b76fd;hb=3afc87426dade0eaeccf69d144a119c6f0c4534f;hp=88aee6d583da41fa777e6987365c7e176937aea5;hpb=fc6d92c63dc5629a9e005628e416e0ecf4daa6ed;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php index 88aee6d5..b2e212a4 100644 --- a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php +++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php @@ -2,9 +2,46 @@ namespace Wallabag\CoreBundle\Repository; +use Wallabag\CoreBundle\Helper\CryptoProxy; + /** * SiteCredentialRepository. */ class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository { + private $cryptoProxy; + + public function setCrypto(CryptoProxy $cryptoProxy) + { + $this->cryptoProxy = $cryptoProxy; + } + + /** + * Retrieve one username/password for the given host and userId. + * + * @param string $host + * @param int $userId + * + * @return array|null + */ + public function findOneByHostAndUser($host, $userId) + { + $res = $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(); + + if (null === $res) { + return; + } + + // decrypt user & password before returning them + $res['username'] = $this->cryptoProxy->decrypt($res['username']); + $res['password'] = $this->cryptoProxy->decrypt($res['password']); + + return $res; + } }