wallabag/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
2017-06-20 16:03:35 +02:00

47 lines
1.1 KiB
PHP

<?php
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 null|array
*/
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 password before returning it
$res['password'] = $this->cryptoProxy->decrypt($res['password']);
return $res;
}
}