mirror of
https://github.com/wallabag/wallabag.git
synced 2025-10-20 19:52:09 +00:00
Merge pull request #2683 from wallabag/credentials-in-db
Store credentials in DB
This commit is contained in:
commit
80784b782b
41 changed files with 1605 additions and 39 deletions
|
@ -0,0 +1,47 @@
|
|||
<?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 user & password before returning them
|
||||
$res['username'] = $this->cryptoProxy->decrypt($res['username']);
|
||||
$res['password'] = $this->cryptoProxy->decrypt($res['password']);
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue