mirror of
https://github.com/wallabag/wallabag.git
synced 2024-06-01 07:58:05 +00:00
f45496336f
Instead of fetching one domain, we use the same method as in site config (to retrieve the matching file) and handle api.example.org, example.org, .org (yes the last one isn’t useful). If one of these match, we got it and use it.
48 lines
1.2 KiB
PHP
48 lines
1.2 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 array $hosts An array of host to look for
|
|
* @param int $userId
|
|
*
|
|
* @return array|null
|
|
*/
|
|
public function findOneByHostsAndUser($hosts, $userId)
|
|
{
|
|
$res = $this->createQueryBuilder('s')
|
|
->select('s.username', 's.password')
|
|
->where('s.host IN (:hosts)')->setParameter('hosts', $hosts)
|
|
->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;
|
|
}
|
|
}
|