2016-12-04 12:51:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wallabag\CoreBundle\Repository;
|
|
|
|
|
2017-06-11 21:05:19 +00:00
|
|
|
use Wallabag\CoreBundle\Helper\CryptoProxy;
|
|
|
|
|
2016-12-04 12:51:58 +00:00
|
|
|
/**
|
|
|
|
* SiteCredentialRepository.
|
|
|
|
*/
|
|
|
|
class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository
|
|
|
|
{
|
2017-06-11 21:05:19 +00:00
|
|
|
private $cryptoProxy;
|
|
|
|
|
|
|
|
public function setCrypto(CryptoProxy $cryptoProxy)
|
|
|
|
{
|
|
|
|
$this->cryptoProxy = $cryptoProxy;
|
|
|
|
}
|
|
|
|
|
2017-05-01 20:13:17 +00:00
|
|
|
/**
|
|
|
|
* Retrieve one username/password for the given host and userId.
|
|
|
|
*
|
|
|
|
* @param string $host
|
|
|
|
* @param int $userId
|
|
|
|
*
|
|
|
|
* @return null|array
|
|
|
|
*/
|
|
|
|
public function findOneByHostAndUser($host, $userId)
|
|
|
|
{
|
2017-06-11 21:05:19 +00:00
|
|
|
$res = $this->createQueryBuilder('s')
|
2017-05-01 20:13:17 +00:00
|
|
|
->select('s.username', 's.password')
|
|
|
|
->where('s.host = :hostname')->setParameter('hostname', $host)
|
|
|
|
->andWhere('s.user = :userId')->setParameter('userId', $userId)
|
|
|
|
->setMaxResults(1)
|
|
|
|
->getQuery()
|
|
|
|
->getOneOrNullResult();
|
2017-06-11 21:05:19 +00:00
|
|
|
|
|
|
|
if (null === $res) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-14 13:02:34 +00:00
|
|
|
// decrypt user & password before returning them
|
|
|
|
$res['username'] = $this->cryptoProxy->decrypt($res['username']);
|
2017-06-11 21:05:19 +00:00
|
|
|
$res['password'] = $this->cryptoProxy->decrypt($res['password']);
|
|
|
|
|
|
|
|
return $res;
|
2017-05-01 20:13:17 +00:00
|
|
|
}
|
2016-12-04 12:51:58 +00:00
|
|
|
}
|