Skip to content

Commit 9ed1de7

Browse files
committed
Bugfix: Robustness if provider is assigned to an user, but provider is not configured
1 parent 402ede3 commit 9ed1de7

File tree

8 files changed

+41
-56
lines changed

8 files changed

+41
-56
lines changed

resources/lang/de.mo

-74 Bytes
Binary file not shown.

resources/lang/de.po

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
msgid ""
22
msgstr ""
33
"Project-Id-Version: OAuth2Client\n"
4-
"POT-Creation-Date: 2025-01-27 19:04+0100\n"
5-
"PO-Revision-Date: 2025-01-27 19:05+0100\n"
4+
"POT-Creation-Date: 2025-01-28 19:59+0100\n"
5+
"PO-Revision-Date: 2025-01-28 19:59+0100\n"
66
"Last-Translator: \n"
77
"Language-Team: \n"
88
"Language: de\n"
@@ -272,14 +272,14 @@ msgstr ""
272272
msgid "Custom module"
273273
msgstr "Benutzerdefiniertes Modul"
274274

275-
#: resources/views/edit-account-page.phtml:49
275+
#: resources/views/edit-account-page.phtml:67
276276
#, php-format
277277
msgid ""
278-
"The authorization provider \"%s\" is not available. Please check the "
279-
"configuration in the following file: data/config.ini.php"
278+
"The authorization provider \"%s\" is not available. Please contact the "
279+
"webtrees administrator."
280280
msgstr ""
281-
"Der Authorisierungsanbieter \"%s\" ist nicht verfügbar. Bitte prüfen Sie "
282-
"die Konfiguration in der folgenden Datei: data/config.ini.php"
281+
"The authorization provider \"%s\" is not available. Please contact the "
282+
"webtrees administrator."
283283

284284
#: resources/views/edit-account-page.phtml:73
285285
#, php-format

resources/lang/en-AU.mo

-62 Bytes
Binary file not shown.

resources/lang/en-AU.po

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
msgid ""
22
msgstr ""
33
"Project-Id-Version: OAuth2Client\n"
4-
"POT-Creation-Date: 2025-01-27 18:28+0100\n"
5-
"PO-Revision-Date: 2025-01-27 18:33+0100\n"
4+
"POT-Creation-Date: 2025-01-28 19:58+0100\n"
5+
"PO-Revision-Date: 2025-01-28 19:59+0100\n"
66
"Last-Translator: Rick Malkin <[email protected]>\n"
77
"Language-Team: \n"
88
"Language: en_AU\n"
@@ -69,7 +69,7 @@ msgstr ""
6969
"Failed to get the access token or the user details from the authorisation "
7070
"provider"
7171

72-
#: src/LoginWithAuthorizationProviderAction.php:271
72+
#: src/LoginWithAuthorizationProviderAction.php:274
7373
msgid ""
7474
"The identity received by the authorization provider cannot be connected to "
7575
"the requested user, because it is already used to sign in by another "
@@ -79,7 +79,7 @@ msgstr ""
7979
"the requested user, because it is already used to sign in by another "
8080
"webtrees user."
8181

82-
#: src/LoginWithAuthorizationProviderAction.php:282
82+
#: src/LoginWithAuthorizationProviderAction.php:285
8383
#, php-format
8484
msgid "Sucessfully connected existing user %s with provider: %s"
8585
msgstr ""
@@ -100,6 +100,7 @@ msgstr ""
100100
#: src/LoginWithAuthorizationProviderAction.php:304
101101
#: src/LoginWithAuthorizationProviderAction.php:311
102102
#: src/LoginWithAuthorizationProviderAction.php:323
103+
#: src/LoginWithAuthorizationProviderAction.php:424
103104
#, php-format
104105
msgid ""
105106
"To connect an existing user with %s, sign in and select: My pages / My "
@@ -111,7 +112,7 @@ msgstr ""
111112
msgid "Invalid user data received from %s. Email or username missing."
112113
msgstr ""
113114

114-
#: src/LoginWithAuthorizationProviderAction.php:317
115+
#: src/LoginWithAuthorizationProviderAction.php:318
115116
msgid "Requesting a new webtrees user account is currently not allowed."
116117
msgstr ""
117118

@@ -130,9 +131,7 @@ msgid "The email address for user %s was updated to: %s"
130131
msgstr ""
131132

132133
#: src/LoginWithAuthorizationProviderAction.php:423
133-
msgid ""
134-
"Login denied. The email address or username already exists. To connect an "
135-
"existing user, select: My pages / My account / Connect with"
134+
msgid "Login denied. The email address or username already exists."
136135
msgstr ""
137136

138137
#: src/OAuth2Client.php:223
@@ -236,14 +235,14 @@ msgstr "Automatic user registration after sign in with authorisation provider"
236235
msgid "Custom module"
237236
msgstr ""
238237

239-
#: resources/views/edit-account-page.phtml:49
238+
#: resources/views/edit-account-page.phtml:67
240239
#, php-format
241240
msgid ""
242-
"The authorization provider \"%s\" is not available. Please check the "
243-
"configuration in the following file: data/config.ini.php"
241+
"The authorization provider \"%s\" is not available. Please contact the "
242+
"webtrees administrator."
244243
msgstr ""
245-
"The authorisation provider \"%s\" is not available. Please check the "
246-
"configuration in the following file: data/config.ini.php"
244+
"The authorisation provider \"%s\" is not available. Please contact the "
245+
"webtrees administrator."
247246

248247
#: resources/views/edit-account-page.phtml:73
249248
#, php-format

resources/lang/en-GB.mo

-62 Bytes
Binary file not shown.

resources/lang/en-GB.po

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
msgid ""
22
msgstr ""
33
"Project-Id-Version: OAuth2Client\n"
4-
"POT-Creation-Date: 2025-01-27 18:33+0100\n"
5-
"PO-Revision-Date: 2025-01-27 18:34+0100\n"
4+
"POT-Creation-Date: 2025-01-28 19:59+0100\n"
5+
"PO-Revision-Date: 2025-01-28 19:59+0100\n"
66
"Last-Translator: Rick Malkin <[email protected]>\n"
77
"Language-Team: \n"
88
"Language: en_AU\n"
@@ -69,7 +69,7 @@ msgstr ""
6969
"Failed to get the access token or the user details from the authorisation "
7070
"provider"
7171

72-
#: src/LoginWithAuthorizationProviderAction.php:271
72+
#: src/LoginWithAuthorizationProviderAction.php:274
7373
msgid ""
7474
"The identity received by the authorization provider cannot be connected to "
7575
"the requested user, because it is already used to sign in by another "
@@ -79,7 +79,7 @@ msgstr ""
7979
"the requested user, because it is already used to sign in by another "
8080
"webtrees user."
8181

82-
#: src/LoginWithAuthorizationProviderAction.php:282
82+
#: src/LoginWithAuthorizationProviderAction.php:285
8383
#, php-format
8484
msgid "Sucessfully connected existing user %s with provider: %s"
8585
msgstr ""
@@ -100,6 +100,7 @@ msgstr ""
100100
#: src/LoginWithAuthorizationProviderAction.php:304
101101
#: src/LoginWithAuthorizationProviderAction.php:311
102102
#: src/LoginWithAuthorizationProviderAction.php:323
103+
#: src/LoginWithAuthorizationProviderAction.php:424
103104
#, php-format
104105
msgid ""
105106
"To connect an existing user with %s, sign in and select: My pages / My "
@@ -111,7 +112,7 @@ msgstr ""
111112
msgid "Invalid user data received from %s. Email or username missing."
112113
msgstr ""
113114

114-
#: src/LoginWithAuthorizationProviderAction.php:317
115+
#: src/LoginWithAuthorizationProviderAction.php:318
115116
msgid "Requesting a new webtrees user account is currently not allowed."
116117
msgstr ""
117118

@@ -130,9 +131,7 @@ msgid "The email address for user %s was updated to: %s"
130131
msgstr ""
131132

132133
#: src/LoginWithAuthorizationProviderAction.php:423
133-
msgid ""
134-
"Login denied. The email address or username already exists. To connect an "
135-
"existing user, select: My pages / My account / Connect with"
134+
msgid "Login denied. The email address or username already exists."
136135
msgstr ""
137136

138137
#: src/OAuth2Client.php:223
@@ -236,14 +235,14 @@ msgstr "Automatic user registration after sign in with authorisation provider"
236235
msgid "Custom module"
237236
msgstr ""
238237

239-
#: resources/views/edit-account-page.phtml:49
238+
#: resources/views/edit-account-page.phtml:67
240239
#, php-format
241240
msgid ""
242-
"The authorization provider \"%s\" is not available. Please check the "
243-
"configuration in the following file: data/config.ini.php"
241+
"The authorization provider \"%s\" is not available. Please contact the "
242+
"webtrees administrator."
244243
msgstr ""
245-
"The authorisation provider \"%s\" is not available. Please check the "
246-
"configuration in the following file: data/config.ini.php"
244+
"The authorization provider \"%s\" is not available. Please contact the "
245+
"webtrees administrator."
247246

248247
#: resources/views/edit-account-page.phtml:73
249248
#, php-format

resources/views/edit-account-page.phtml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,13 @@ $connect_with_providers = boolval($oauth2_client->getPreference(OAuth2Client::P
4545

4646
if ($is_oauth2_user) {
4747

48-
if (!AuthorizationProviderFactory::isValidProvider($provider_name)) {
49-
FlashMessages::addMessage(I18N::translate('The authorization provider "%s" is not available. Please check the configuration in the following file: data/config.ini.php', $provider_name), 'danger');
50-
return;
51-
}
52-
53-
$provider = (new AuthorizationProviderFactory())::make($provider_name, '');
48+
$provider = AuthorizationProviderFactory::make($provider_name, '');
49+
$provider_label = $provider !== null ? $provider->getSignInButtonLabel() : $provider_name;
5450

5551
//Determine, whether the email address can be edited
5652
$different_email = $user->email() !== $user->getPreference(OAuth2Client::USER_PREF_EMAIL_AT_PROVIDER, '');
5753
$sync_email = boolval($oauth2_client->getPreference(OAuth2Client::PREF_SYNC_PROVIDER_EMAIL, '0'));
5854
$edit_email = ($different_email || !$sync_email);
59-
60-
//Determine
6155
}
6256

6357
$edit_password = (!$is_oauth2_user || boolval($oauth2_client->getPreference(OAuth2Client::PREF_USE_WEBTREES_PASSWORD, '0')));
@@ -68,11 +62,17 @@ $edit_password = (!$is_oauth2_user || boolval($oauth2_client->getPreference(OAut
6862
<?= $title ?>
6963
</h2>
7064

65+
<?php if ($provider === null) : ?>
66+
<div class="alert alert-danger">
67+
<p><?= I18N::translate('The authorization provider "%s" is not available. Please contact the webtrees administrator.', $provider_name) ?></p>
68+
</div>
69+
<?php endif ?>
70+
7171
<div class="h4">
7272
<?php if ($is_oauth2_user && $signed_in_with_provider) : ?>
73-
<?= I18N::translate('Signed in with %s', $provider->getSignInButtonLabel()) ?>
73+
<?= I18N::translate('Signed in with %s', $provider_label) ?>
7474
<?php elseif ($is_oauth2_user && !$signed_in_with_provider) : ?>
75-
<?= I18N::translate('This user can sign in with %s', $provider->getSignInButtonLabel()) ?>
75+
<?= I18N::translate('This user can sign in with %s', $provider_label) ?>
7676
<?php endif ?>
7777
<?php if ($is_oauth2_user && (!$edit_email OR !$edit_password)) : ?>
7878
<?= ' - ' . I18N::translate('The administrator might have disabled to change the email address or the password') ?>

src/Factories/AuthorizationProviderFactory.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,4 @@ public static function getSignInButtonLabelsByUsers(Collection $users, $registra
253253

254254
return $labels_for_users;
255255
}
256-
257-
/**
258-
* Whether a provider name is an available and valid provider
259-
*
260-
* @param string $provider_name
261-
*
262-
* @return bool
263-
*/
264-
265-
public static function isValidProvider(string $provider_name): bool {
266-
267-
return in_array($provider_name, self::getAuthorizatonProviderNames());
268-
}
269256
}

0 commit comments

Comments
 (0)