X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FSiteCredentialRepository.php;h=b2e212a41438cc32d7e3bbab212aed78382b76fd;hb=3afc87426dade0eaeccf69d144a119c6f0c4534f;hp=501b44396e72273b80603e2b2d61e0edd61abd2f;hpb=f92fcb53ca78cc8822962e676b0db117e1a08aa5;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php index 501b4439..b2e212a4 100644 --- a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php +++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php @@ -2,12 +2,46 @@ namespace Wallabag\CoreBundle\Repository; +use Wallabag\CoreBundle\Helper\CryptoProxy; + /** * SiteCredentialRepository. - * - * This class was generated by the Doctrine ORM. Add your own custom - * repository methods below. */ 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; + } }