mirror of
https://github.com/wallabag/wallabag.git
synced 2025-01-09 08:25:25 +00:00
Add ability to match many domains for credentials
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.
This commit is contained in:
parent
bfd69c74e5
commit
f45496336f
15 changed files with 36 additions and 26 deletions
|
@ -64,7 +64,17 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
|
|||
|
||||
$credentials = null;
|
||||
if ($this->currentUser) {
|
||||
$credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId());
|
||||
$hosts = [$host];
|
||||
// will try to see for a host without the first subdomain (fr.example.org & .example.org)
|
||||
$split = explode('.', $host);
|
||||
|
||||
if (\count($split) > 1) {
|
||||
// remove first subdomain
|
||||
array_shift($split);
|
||||
$hosts[] = '.' . implode('.', $split);
|
||||
}
|
||||
|
||||
$credentials = $this->credentialRepository->findOneByHostsAndUser($hosts, $this->currentUser->getId());
|
||||
}
|
||||
|
||||
if (null === $credentials) {
|
||||
|
|
|
@ -19,16 +19,16 @@ class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository
|
|||
/**
|
||||
* Retrieve one username/password for the given host and userId.
|
||||
*
|
||||
* @param string $host
|
||||
* @param array $hosts An array of host to look for
|
||||
* @param int $userId
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function findOneByHostAndUser($host, $userId)
|
||||
public function findOneByHostsAndUser($hosts, $userId)
|
||||
{
|
||||
$res = $this->createQueryBuilder('s')
|
||||
->select('s.username', 's.password')
|
||||
->where('s.host = :hostname')->setParameter('hostname', $host)
|
||||
->where('s.host IN (:hosts)')->setParameter('hosts', $hosts)
|
||||
->andWhere('s.user = :userId')->setParameter('userId', $userId)
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
|
|
|
@ -550,7 +550,7 @@ site_credential:
|
|||
# create_new_one: Create a new credential
|
||||
# form:
|
||||
# username_label: 'Username'
|
||||
# host_label: 'Host'
|
||||
# host_label: 'Host (subdomain.example.org, .example.org, etc.)'
|
||||
# password_label: 'Password'
|
||||
# save: Save
|
||||
# delete: Delete
|
||||
|
|
|
@ -550,7 +550,7 @@ site_credential:
|
|||
create_new_one: 'Einen neuen Seitenzugang anlegen'
|
||||
form:
|
||||
username_label: 'Benutzername'
|
||||
host_label: 'Host'
|
||||
host_label: 'Host (subdomain.example.org, .example.org, etc.)'
|
||||
password_label: 'Passwort'
|
||||
save: 'Speichern'
|
||||
delete: 'Löschen'
|
||||
|
|
|
@ -550,7 +550,7 @@ site_credential:
|
|||
create_new_one: Create a new credential
|
||||
form:
|
||||
username_label: 'Username'
|
||||
host_label: 'Host'
|
||||
host_label: 'Host (subdomain.example.org, .example.org, etc.)'
|
||||
password_label: 'Password'
|
||||
save: Save
|
||||
delete: Delete
|
||||
|
|
|
@ -550,7 +550,7 @@ site_credential:
|
|||
# create_new_one: Create a new credential
|
||||
# form:
|
||||
# username_label: 'Username'
|
||||
# host_label: 'Host'
|
||||
# host_label: 'Host (subdomain.example.org, .example.org, etc.)'
|
||||
# password_label: 'Password'
|
||||
# save: Save
|
||||
# delete: Delete
|
||||
|
|
|
@ -550,7 +550,7 @@ site_credential:
|
|||
# create_new_one: Create a new credential
|
||||
# form:
|
||||
# username_label: 'Username'
|
||||
# host_label: 'Host'
|
||||
# host_label: 'Host (subdomain.example.org, .example.org, etc.)'
|
||||
# password_label: 'Password'
|
||||
# save: Save
|
||||
# delete: Delete
|
||||
|
|
|
@ -550,7 +550,7 @@ site_credential:
|
|||
create_new_one: Créer un nouvel accès à un site
|
||||
form:
|
||||
username_label: 'Identifiant'
|
||||
host_label: 'Domaine'
|
||||
host_label: 'Domaine (subdomain.example.org, .example.org, etc.)'
|
||||
password_label: 'Mot de passe'
|
||||
save: "Sauvegarder"
|
||||
delete: "Supprimer"
|
||||
|
|
|
@ -550,7 +550,7 @@ site_credential:
|
|||
# create_new_one: Create a new credential
|
||||
# form:
|
||||
# username_label: 'Username'
|
||||
# host_label: 'Host'
|
||||
# host_label: 'Host (subdomain.example.org, .example.org, etc.)'
|
||||
# password_label: 'Password'
|
||||
# save: Save
|
||||
# delete: Delete
|
||||
|
|
|
@ -550,7 +550,7 @@ site_credential:
|
|||
create_new_one: Crear un novèl identificant
|
||||
form:
|
||||
username_label: "Nom d'utilizaire"
|
||||
host_label: 'Òste'
|
||||
host_label: 'Òste (subdomain.example.org, .example.org, etc.)'
|
||||
password_label: 'Senhal'
|
||||
save: 'Enregistrar'
|
||||
delete: 'Suprimir'
|
||||
|
|
|
@ -550,7 +550,7 @@ site_credential:
|
|||
create_new_one: Stwórz nowe poświadczenie
|
||||
form:
|
||||
username_label: 'Nazwa użytkownika'
|
||||
host_label: 'Host'
|
||||
host_label: 'Host (subdomain.example.org, .example.org, etc.)'
|
||||
password_label: 'Hasło'
|
||||
save: Zapisz
|
||||
delete: Usuń
|
||||
|
|
|
@ -550,7 +550,7 @@ site_credential:
|
|||
# create_new_one: Create a new credential
|
||||
form:
|
||||
# username_label: 'Username'
|
||||
# host_label: 'Host'
|
||||
# host_label: 'Host (subdomain.example.org, .example.org, etc.)'
|
||||
# password_label: 'Password'
|
||||
save: 'Salvar'
|
||||
delete: 'Apagar'
|
||||
|
|
|
@ -550,7 +550,7 @@ site_credential:
|
|||
# create_new_one: Create a new credential
|
||||
# form:
|
||||
# username_label: 'Username'
|
||||
# host_label: 'Host'
|
||||
# host_label: 'Host (subdomain.example.org, .example.org, etc.)'
|
||||
# password_label: 'Password'
|
||||
# save: Save
|
||||
# delete: Delete
|
||||
|
|
|
@ -548,7 +548,7 @@ site_credential:
|
|||
create_new_one: สร้างข้อมูลส่วนตัวใหม่
|
||||
form:
|
||||
username_label: 'ชื่อผู้ใช้'
|
||||
host_label: 'โฮส'
|
||||
host_label: 'โฮส (subdomain.example.org, .example.org, etc.)'
|
||||
password_label: 'รหัสผ่าน'
|
||||
save: บันทึก
|
||||
delete: ลบ
|
||||
|
|
|
@ -24,7 +24,7 @@ class GrabySiteConfigBuilderTest extends TestCase
|
|||
|
||||
$grabySiteConfig = new GrabySiteConfig();
|
||||
$grabySiteConfig->requires_login = true;
|
||||
$grabySiteConfig->login_uri = 'http://www.example.com/login';
|
||||
$grabySiteConfig->login_uri = 'http://api.example.com/login';
|
||||
$grabySiteConfig->login_username_field = 'login';
|
||||
$grabySiteConfig->login_password_field = 'password';
|
||||
$grabySiteConfig->login_extra_fields = ['field=value'];
|
||||
|
@ -32,7 +32,7 @@ class GrabySiteConfigBuilderTest extends TestCase
|
|||
|
||||
$grabyConfigBuilderMock
|
||||
->method('buildForHost')
|
||||
->with('example.com')
|
||||
->with('api.example.com')
|
||||
->will($this->returnValue($grabySiteConfig));
|
||||
|
||||
$logger = new Logger('foo');
|
||||
|
@ -43,8 +43,8 @@ class GrabySiteConfigBuilderTest extends TestCase
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$siteCrentialRepo->expects($this->once())
|
||||
->method('findOneByHostAndUser')
|
||||
->with('example.com', 1)
|
||||
->method('findOneByHostsAndUser')
|
||||
->with(['api.example.com', '.example.com'], 1)
|
||||
->willReturn(['username' => 'foo', 'password' => 'bar']);
|
||||
|
||||
$user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User')
|
||||
|
@ -66,11 +66,11 @@ class GrabySiteConfigBuilderTest extends TestCase
|
|||
$logger
|
||||
);
|
||||
|
||||
$config = $this->builder->buildForHost('www.example.com');
|
||||
$config = $this->builder->buildForHost('api.example.com');
|
||||
|
||||
$this->assertSame('example.com', $config->getHost());
|
||||
$this->assertSame('api.example.com', $config->getHost());
|
||||
$this->assertTrue($config->requiresLogin());
|
||||
$this->assertSame('http://www.example.com/login', $config->getLoginUri());
|
||||
$this->assertSame('http://api.example.com/login', $config->getLoginUri());
|
||||
$this->assertSame('login', $config->getUsernameField());
|
||||
$this->assertSame('password', $config->getPasswordField());
|
||||
$this->assertSame(['field' => 'value'], $config->getExtraFields());
|
||||
|
@ -103,8 +103,8 @@ class GrabySiteConfigBuilderTest extends TestCase
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$siteCrentialRepo->expects($this->once())
|
||||
->method('findOneByHostAndUser')
|
||||
->with('unknown.com', 1)
|
||||
->method('findOneByHostsAndUser')
|
||||
->with(['unknown.com', '.com'], 1)
|
||||
->willReturn(null);
|
||||
|
||||
$user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User')
|
||||
|
|
Loading…
Reference in a new issue