wallabag/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php

48 lines
1.2 KiB
PHP
Raw Normal View History

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;
}
/**
* Retrieve one username/password for the given host and userId.
*
* @param string $host
* @param int $userId
*
2019-02-11 10:50:24 +00:00
* @return array|null
*/
public function findOneByHostAndUser($host, $userId)
{
2017-06-11 21:05:19 +00:00
$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();
2017-06-11 21:05:19 +00:00
if (null === $res) {
return;
}
// 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;
}
2016-12-04 12:51:58 +00:00
}