diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-04-23 22:28:36 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-04-23 22:39:31 +0200 |
commit | f45496336f5bbd31b69553fcfae9cdfd03b280cc (patch) | |
tree | cd085115f041cf0e56a5c5a23dd2706160f2950d /src/Wallabag | |
parent | bfd69c74e5b4f2ebfcb304b1983bf771c2bb11f7 (diff) | |
download | wallabag-f45496336f5bbd31b69553fcfae9cdfd03b280cc.tar.gz wallabag-f45496336f5bbd31b69553fcfae9cdfd03b280cc.tar.zst wallabag-f45496336f5bbd31b69553fcfae9cdfd03b280cc.zip |
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.
Diffstat (limited to 'src/Wallabag')
14 files changed, 27 insertions, 17 deletions
diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php index 90e00c62..718441bd 100644 --- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php +++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php | |||
@@ -64,7 +64,17 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder | |||
64 | 64 | ||
65 | $credentials = null; | 65 | $credentials = null; |
66 | if ($this->currentUser) { | 66 | if ($this->currentUser) { |
67 | $credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId()); | 67 | $hosts = [$host]; |
68 | // will try to see for a host without the first subdomain (fr.example.org & .example.org) | ||
69 | $split = explode('.', $host); | ||
70 | |||
71 | if (\count($split) > 1) { | ||
72 | // remove first subdomain | ||
73 | array_shift($split); | ||
74 | $hosts[] = '.' . implode('.', $split); | ||
75 | } | ||
76 | |||
77 | $credentials = $this->credentialRepository->findOneByHostsAndUser($hosts, $this->currentUser->getId()); | ||
68 | } | 78 | } |
69 | 79 | ||
70 | if (null === $credentials) { | 80 | if (null === $credentials) { |
diff --git a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php index b2e212a4..aeadd770 100644 --- a/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php +++ b/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php | |||
@@ -19,16 +19,16 @@ class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository | |||
19 | /** | 19 | /** |
20 | * Retrieve one username/password for the given host and userId. | 20 | * Retrieve one username/password for the given host and userId. |
21 | * | 21 | * |
22 | * @param string $host | 22 | * @param array $hosts An array of host to look for |
23 | * @param int $userId | 23 | * @param int $userId |
24 | * | 24 | * |
25 | * @return array|null | 25 | * @return array|null |
26 | */ | 26 | */ |
27 | public function findOneByHostAndUser($host, $userId) | 27 | public function findOneByHostsAndUser($hosts, $userId) |
28 | { | 28 | { |
29 | $res = $this->createQueryBuilder('s') | 29 | $res = $this->createQueryBuilder('s') |
30 | ->select('s.username', 's.password') | 30 | ->select('s.username', 's.password') |
31 | ->where('s.host = :hostname')->setParameter('hostname', $host) | 31 | ->where('s.host IN (:hosts)')->setParameter('hosts', $hosts) |
32 | ->andWhere('s.user = :userId')->setParameter('userId', $userId) | 32 | ->andWhere('s.user = :userId')->setParameter('userId', $userId) |
33 | ->setMaxResults(1) | 33 | ->setMaxResults(1) |
34 | ->getQuery() | 34 | ->getQuery() |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index 97eb874d..6f842534 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml | |||
@@ -550,7 +550,7 @@ site_credential: | |||
550 | # create_new_one: Create a new credential | 550 | # create_new_one: Create a new credential |
551 | # form: | 551 | # form: |
552 | # username_label: 'Username' | 552 | # username_label: 'Username' |
553 | # host_label: 'Host' | 553 | # host_label: 'Host (subdomain.example.org, .example.org, etc.)' |
554 | # password_label: 'Password' | 554 | # password_label: 'Password' |
555 | # save: Save | 555 | # save: Save |
556 | # delete: Delete | 556 | # delete: Delete |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index 0cf3b138..874908b9 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml | |||
@@ -550,7 +550,7 @@ site_credential: | |||
550 | create_new_one: 'Einen neuen Seitenzugang anlegen' | 550 | create_new_one: 'Einen neuen Seitenzugang anlegen' |
551 | form: | 551 | form: |
552 | username_label: 'Benutzername' | 552 | username_label: 'Benutzername' |
553 | host_label: 'Host' | 553 | host_label: 'Host (subdomain.example.org, .example.org, etc.)' |
554 | password_label: 'Passwort' | 554 | password_label: 'Passwort' |
555 | save: 'Speichern' | 555 | save: 'Speichern' |
556 | delete: 'Löschen' | 556 | delete: 'Löschen' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 6085be14..598ad58d 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml | |||
@@ -550,7 +550,7 @@ site_credential: | |||
550 | create_new_one: Create a new credential | 550 | create_new_one: Create a new credential |
551 | form: | 551 | form: |
552 | username_label: 'Username' | 552 | username_label: 'Username' |
553 | host_label: 'Host' | 553 | host_label: 'Host (subdomain.example.org, .example.org, etc.)' |
554 | password_label: 'Password' | 554 | password_label: 'Password' |
555 | save: Save | 555 | save: Save |
556 | delete: Delete | 556 | delete: Delete |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index f2a8fb89..f8aa4109 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml | |||
@@ -550,7 +550,7 @@ site_credential: | |||
550 | # create_new_one: Create a new credential | 550 | # create_new_one: Create a new credential |
551 | # form: | 551 | # form: |
552 | # username_label: 'Username' | 552 | # username_label: 'Username' |
553 | # host_label: 'Host' | 553 | # host_label: 'Host (subdomain.example.org, .example.org, etc.)' |
554 | # password_label: 'Password' | 554 | # password_label: 'Password' |
555 | # save: Save | 555 | # save: Save |
556 | # delete: Delete | 556 | # delete: Delete |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index a5cbd7ec..785e39ee 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml | |||
@@ -550,7 +550,7 @@ site_credential: | |||
550 | # create_new_one: Create a new credential | 550 | # create_new_one: Create a new credential |
551 | # form: | 551 | # form: |
552 | # username_label: 'Username' | 552 | # username_label: 'Username' |
553 | # host_label: 'Host' | 553 | # host_label: 'Host (subdomain.example.org, .example.org, etc.)' |
554 | # password_label: 'Password' | 554 | # password_label: 'Password' |
555 | # save: Save | 555 | # save: Save |
556 | # delete: Delete | 556 | # delete: Delete |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index a36d84ae..b2fa1c50 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml | |||
@@ -550,7 +550,7 @@ site_credential: | |||
550 | create_new_one: Créer un nouvel accès à un site | 550 | create_new_one: Créer un nouvel accès à un site |
551 | form: | 551 | form: |
552 | username_label: 'Identifiant' | 552 | username_label: 'Identifiant' |
553 | host_label: 'Domaine' | 553 | host_label: 'Domaine (subdomain.example.org, .example.org, etc.)' |
554 | password_label: 'Mot de passe' | 554 | password_label: 'Mot de passe' |
555 | save: "Sauvegarder" | 555 | save: "Sauvegarder" |
556 | delete: "Supprimer" | 556 | delete: "Supprimer" |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 1649c0e4..ecaa3b60 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml | |||
@@ -550,7 +550,7 @@ site_credential: | |||
550 | # create_new_one: Create a new credential | 550 | # create_new_one: Create a new credential |
551 | # form: | 551 | # form: |
552 | # username_label: 'Username' | 552 | # username_label: 'Username' |
553 | # host_label: 'Host' | 553 | # host_label: 'Host (subdomain.example.org, .example.org, etc.)' |
554 | # password_label: 'Password' | 554 | # password_label: 'Password' |
555 | # save: Save | 555 | # save: Save |
556 | # delete: Delete | 556 | # delete: Delete |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index e2298f1f..848c88d2 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml | |||
@@ -550,7 +550,7 @@ site_credential: | |||
550 | create_new_one: Crear un novèl identificant | 550 | create_new_one: Crear un novèl identificant |
551 | form: | 551 | form: |
552 | username_label: "Nom d'utilizaire" | 552 | username_label: "Nom d'utilizaire" |
553 | host_label: 'Òste' | 553 | host_label: 'Òste (subdomain.example.org, .example.org, etc.)' |
554 | password_label: 'Senhal' | 554 | password_label: 'Senhal' |
555 | save: 'Enregistrar' | 555 | save: 'Enregistrar' |
556 | delete: 'Suprimir' | 556 | delete: 'Suprimir' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index a5712733..a0032fe8 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml | |||
@@ -550,7 +550,7 @@ site_credential: | |||
550 | create_new_one: Stwórz nowe poświadczenie | 550 | create_new_one: Stwórz nowe poświadczenie |
551 | form: | 551 | form: |
552 | username_label: 'Nazwa użytkownika' | 552 | username_label: 'Nazwa użytkownika' |
553 | host_label: 'Host' | 553 | host_label: 'Host (subdomain.example.org, .example.org, etc.)' |
554 | password_label: 'Hasło' | 554 | password_label: 'Hasło' |
555 | save: Zapisz | 555 | save: Zapisz |
556 | delete: Usuń | 556 | delete: Usuń |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml index 1ccf49e1..292fad61 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml | |||
@@ -550,7 +550,7 @@ site_credential: | |||
550 | # create_new_one: Create a new credential | 550 | # create_new_one: Create a new credential |
551 | form: | 551 | form: |
552 | # username_label: 'Username' | 552 | # username_label: 'Username' |
553 | # host_label: 'Host' | 553 | # host_label: 'Host (subdomain.example.org, .example.org, etc.)' |
554 | # password_label: 'Password' | 554 | # password_label: 'Password' |
555 | save: 'Salvar' | 555 | save: 'Salvar' |
556 | delete: 'Apagar' | 556 | delete: 'Apagar' |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 6c0e18e1..9e8d68b3 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml | |||
@@ -550,7 +550,7 @@ site_credential: | |||
550 | # create_new_one: Create a new credential | 550 | # create_new_one: Create a new credential |
551 | # form: | 551 | # form: |
552 | # username_label: 'Username' | 552 | # username_label: 'Username' |
553 | # host_label: 'Host' | 553 | # host_label: 'Host (subdomain.example.org, .example.org, etc.)' |
554 | # password_label: 'Password' | 554 | # password_label: 'Password' |
555 | # save: Save | 555 | # save: Save |
556 | # delete: Delete | 556 | # delete: Delete |
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml index 5524b1f1..cb3b0f23 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml | |||
@@ -548,7 +548,7 @@ site_credential: | |||
548 | create_new_one: สร้างข้อมูลส่วนตัวใหม่ | 548 | create_new_one: สร้างข้อมูลส่วนตัวใหม่ |
549 | form: | 549 | form: |
550 | username_label: 'ชื่อผู้ใช้' | 550 | username_label: 'ชื่อผู้ใช้' |
551 | host_label: 'โฮส' | 551 | host_label: 'โฮส (subdomain.example.org, .example.org, etc.)' |
552 | password_label: 'รหัสผ่าน' | 552 | password_label: 'รหัสผ่าน' |
553 | save: บันทึก | 553 | save: บันทึก |
554 | delete: ลบ | 554 | delete: ลบ |