diff --git a/core/classes/Misc/NamelessOAuth.php b/core/classes/Misc/NamelessOAuth.php
index 74264e91a7..b63da946db 100644
--- a/core/classes/Misc/NamelessOAuth.php
+++ b/core/classes/Misc/NamelessOAuth.php
@@ -42,6 +42,20 @@ public function getProviders(): array {
return $this->_providers;
}
+ /**
+ * Get or create an instance of a specific provider.
+ *
+ * @param string $provider The provider name
+ * @return null|array An array of registered OAuth provider.
+ */
+ public function getProvider(string $provider): ?array {
+ if (array_key_exists($provider, $this->_providers)) {
+ return $this->_providers[$provider];
+ }
+
+ return null;
+ }
+
/**
* Determine if OAuth is available if at least one provider is setup.
*
diff --git a/custom/panel_templates/Default/core/integrations_edit.tpl b/custom/panel_templates/Default/core/integrations_edit.tpl
index 6361c16843..affe58db9f 100644
--- a/custom/panel_templates/Default/core/integrations_edit.tpl
+++ b/custom/panel_templates/Default/core/integrations_edit.tpl
@@ -88,6 +88,67 @@
{/if}
+ {if isset($OAUTH)}
+
{$OAUTH}
+
+
+
{$INFO}
+ {$OAUTH_INFO}
+
+
+
+
+ {/if}
+
diff --git a/custom/panel_templates/Default/core/registration.tpl b/custom/panel_templates/Default/core/registration.tpl
index 81cb241061..24be861350 100644
--- a/custom/panel_templates/Default/core/registration.tpl
+++ b/custom/panel_templates/Default/core/registration.tpl
@@ -139,67 +139,6 @@
- {$OAUTH}
-
-
-
{$INFO}
- {$OAUTH_INFO}
-
-
-
-
-
diff --git a/modules/Core/pages/panel/integrations.php b/modules/Core/pages/panel/integrations.php
index 18a9bba97e..bb562b7920 100644
--- a/modules/Core/pages/panel/integrations.php
+++ b/modules/Core/pages/panel/integrations.php
@@ -57,12 +57,28 @@
if (Token::check()) {
if (Input::get('action') === 'general_settings') {
+ // Update general settings
DB::getInstance()->update('integrations', $integration->data()->id, [
'enabled' => Output::getClean(Input::get('enabled')),
'can_unlink' => Output::getClean(Input::get('can_unlink')),
'required' => Output::getClean(Input::get('required'))
]);
+ Session::flash('integrations_success', $language->get('admin', 'integration_updated_successfully'));
+ Redirect::to(URL::build('/panel/core/integrations/', 'integration=' . $integration->getName()));
+ } else if (Input::get('action') === 'oauth') {
+ // Update OAuth settings
+ $provider_name = strtolower($integration->getName());
+
+ $client_id = Input::get("client-id");
+ $client_secret = Input::get("client-secret");
+ if ($client_id && $client_secret) {
+ NamelessOAuth::getInstance()->setEnabled($provider_name, Input::get("enable") == 'on' ? 1 : 0);
+ } else {
+ NamelessOAuth::getInstance()->setEnabled($provider_name, 0);
+ }
+ NamelessOAuth::getInstance()->setCredentials($provider_name, $client_id, $client_secret);
+
Session::flash('integrations_success', $language->get('admin', 'integration_updated_successfully'));
Redirect::to(URL::build('/panel/core/integrations/', 'integration=' . $integration->getName()));
}
@@ -81,6 +97,37 @@
}
}
+ // OAuth integration?
+ $provider_name = strtolower($integration->getName());
+ $provider = NamelessOAuth::getInstance()->getProvider($provider_name);
+ if ($provider != null) {
+ [$client_id, $client_secret] = NamelessOAuth::getInstance()->getCredentials($provider_name);
+
+ $oauth_provider_data = [
+ 'name' => $provider_name,
+ 'enabled' => NamelessOAuth::getInstance()->isEnabled($provider_name),
+ 'setup' => NamelessOAuth::getInstance()->isSetup($provider_name),
+ 'icon' => $provider_data['icon'] ?? null,
+ 'logo_url' => $provider_data['logo_url'] ?? null,
+ 'client_id' => $client_id,
+ 'client_secret' => $client_secret,
+ 'client_url' => rtrim(URL::getSelfURL(), '/') . URL::build('/oauth', 'provider=' . $provider_name, 'non-friendly'),
+ ];
+
+ $smarty->assign([
+ 'OAUTH' => $language->get('admin', 'oauth'),
+ 'OAUTH_INFO' => $language->get('admin', 'oauth_info', [
+ 'docLinkStart' => '',
+ 'docLinkEnd' => ''
+ ]),
+ 'REDIRECT_URL' => $language->get('admin', 'redirect_url'),
+ 'CLIENT_ID' => $language->get('admin', 'client_id'),
+ 'CLIENT_SECRET' => $language->get('admin', 'client_secret'),
+ 'OAUTH_URL' => rtrim(URL::getSelfURL(), '/') . URL::build('/oauth', 'provider={{provider}}', 'non-friendly'),
+ 'OAUTH_PROVIDER_DATA' => $oauth_provider_data
+ ]);
+ }
+
$smarty->assign([
'EDITING_INTEGRATION' => $language->get('admin', 'editing_integration_x', ['integration' => Output::getClean($integration->getName())]),
'BACK' => $language->get('general', 'back'),
diff --git a/modules/Core/pages/panel/registration.php b/modules/Core/pages/panel/registration.php
index 91bbda8baa..55804e3873 100644
--- a/modules/Core/pages/panel/registration.php
+++ b/modules/Core/pages/panel/registration.php
@@ -34,66 +34,50 @@
} else {
// Registration settings
- if (Input::get('action') == 'oauth') {
-
- foreach (array_keys(NamelessOAuth::getInstance()->getProviders()) as $provider_name) {
- $client_id = Input::get("client-id-{$provider_name}");
- $client_secret = Input::get("client-secret-{$provider_name}");
- if ($client_id && $client_secret) {
- NamelessOAuth::getInstance()->setEnabled($provider_name, Input::get("enable-{$provider_name}") == 'on' ? 1 : 0);
- } else {
- NamelessOAuth::getInstance()->setEnabled($provider_name, 0);
- }
-
- NamelessOAuth::getInstance()->setCredentials($provider_name, $client_id, $client_secret);
- }
-
- } else {
- // Email verification
- Settings::set('email_verification', (isset($_POST['verification']) && $_POST['verification'] == 'on') ? '1' : '0');
+ // Email verification
+ Settings::set('email_verification', (isset($_POST['verification']) && $_POST['verification'] == 'on') ? '1' : '0');
- // Registration disabled message
- Settings::set('registration_disabled_message', (isset($_POST['message']) && !empty($_POST['message'])) ? $_POST['message'] : 'Website registration is disabled.');
+ // Registration disabled message
+ Settings::set('registration_disabled_message', (isset($_POST['message']) && !empty($_POST['message'])) ? $_POST['message'] : 'Website registration is disabled.');
- // reCAPTCHA type
- Settings::set('recaptcha_type', Input::get('captcha_type'));
+ // reCAPTCHA type
+ Settings::set('recaptcha_type', Input::get('captcha_type'));
- // Validate captcha key and secret key
- if (!empty(Input::get('recaptcha_key')) || !empty(Input::get('recaptcha_secret')) || Input::get('enable_recaptcha') == 1 || Input::get('enable_recaptcha_login') == 1) {
- CaptchaBase::setActiveProvider(Input::get('captcha_type'));
+ // Validate captcha key and secret key
+ if (!empty(Input::get('recaptcha_key')) || !empty(Input::get('recaptcha_secret')) || Input::get('enable_recaptcha') == 1 || Input::get('enable_recaptcha_login') == 1) {
+ CaptchaBase::setActiveProvider(Input::get('captcha_type'));
- $provider = CaptchaBase::getActiveProvider();
- if ($provider->validateSecret(Input::get('recaptcha_secret')) == false || $provider->validateKey(Input::get('recaptcha')) == false) {
- $captcha_warning = $language->get('admin', 'invalid_recaptcha_settings', [
- 'recaptchaProvider' => Text::bold(Input::get('captcha_type'))
- ]);
- }
+ $provider = CaptchaBase::getActiveProvider();
+ if ($provider->validateSecret(Input::get('recaptcha_secret')) == false || $provider->validateKey(Input::get('recaptcha')) == false) {
+ $captcha_warning = $language->get('admin', 'invalid_recaptcha_settings', [
+ 'recaptchaProvider' => Text::bold(Input::get('captcha_type'))
+ ]);
+ }
- Settings::set('recaptcha_key', Input::get('recaptcha'));
- Settings::set('recaptcha_secret', Input::get('recaptcha_secret'));
+ Settings::set('recaptcha_key', Input::get('recaptcha'));
+ Settings::set('recaptcha_secret', Input::get('recaptcha_secret'));
- } else if (empty(Input::get('recaptcha_key')) && empty(Input::get('recaptcha_secret'))) {
- Settings::set('recaptcha_key', '');
- Settings::set('recaptcha_secret', '');
- }
+ } else if (empty(Input::get('recaptcha_key')) && empty(Input::get('recaptcha_secret'))) {
+ Settings::set('recaptcha_key', '');
+ Settings::set('recaptcha_secret', '');
+ }
- Settings::set('recaptcha', (isset($_POST['enable_recaptcha']) && $_POST['enable_recaptcha'] == '1') ? '1' : '0');
- Settings::set('recaptcha_login', (isset($_POST['enable_recaptcha_login']) && $_POST['enable_recaptcha_login'] == '1') ? '1' : '0');
+ Settings::set('recaptcha', (isset($_POST['enable_recaptcha']) && $_POST['enable_recaptcha'] == '1') ? '1' : '0');
+ Settings::set('recaptcha_login', (isset($_POST['enable_recaptcha_login']) && $_POST['enable_recaptcha_login'] == '1') ? '1' : '0');
- // Config value
- if (Input::get('enable_recaptcha') == 1 || Input::get('enable_recaptcha_login') == 1) {
- if (is_writable(ROOT_PATH . '/' . implode(DIRECTORY_SEPARATOR, ['core', 'config.php']))) {
- Config::set('core.captcha', true);
- } else {
- $errors = [$language->get('admin', 'config_not_writable')];
- }
+ // Config value
+ if (Input::get('enable_recaptcha') == 1 || Input::get('enable_recaptcha_login') == 1) {
+ if (is_writable(ROOT_PATH . '/' . implode(DIRECTORY_SEPARATOR, ['core', 'config.php']))) {
+ Config::set('core.captcha', true);
+ } else {
+ $errors = [$language->get('admin', 'config_not_writable')];
}
-
- // Validation group
- $validation_action = json_decode(Settings::get('validate_user_action'), true);
- $new_value = json_encode(['action' => $validation_action['action'] ?? 'promote', 'group' => $_POST['promote_group']]);
- Settings::set('validate_user_action', $new_value);
}
+
+ // Validation group
+ $validation_action = json_decode(Settings::get('validate_user_action'), true);
+ $new_value = json_encode(['action' => $validation_action['action'] ?? 'promote', 'group' => $_POST['promote_group']]);
+ Settings::set('validate_user_action', $new_value);
}
if (!count($errors)) {
@@ -154,19 +138,6 @@
];
}
-$oauth_provider_data = [];
-foreach (NamelessOAuth::getInstance()->getProviders() as $provider_name => $provider_data) {
- [$client_id, $client_secret] = NamelessOAuth::getInstance()->getCredentials($provider_name);
- $oauth_provider_data[$provider_name] = [
- 'enabled' => NamelessOAuth::getInstance()->isEnabled($provider_name),
- 'setup' => NamelessOAuth::getInstance()->isSetup($provider_name),
- 'icon' => $provider_data['icon'] ?? null,
- 'logo_url' => $provider_data['logo_url'] ?? null,
- 'client_id' => $client_id,
- 'client_secret' => $client_secret,
- ];
-}
-
$smarty->assign([
'EMAIL_VERIFICATION' => $language->get('admin', 'email_verification'),
'EMAIL_VERIFICATION_VALUE' => Settings::get('email_verification') === '1',
@@ -188,15 +159,6 @@
'GROUPS' => DB::getInstance()->get('groups', ['staff', 0])->results(),
'VALIDATION_GROUP' => $validation_group,
'CAPTCHA_OPTIONS' => $captcha_options,
- 'OAUTH' => $language->get('admin', 'oauth'),
- 'OAUTH_INFO' => $language->get('admin', 'oauth_info', [
- 'docLinkStart' => '',
- 'docLinkEnd' => ''
- ]),
- 'REDIRECT_URL' => $language->get('admin', 'redirect_url'),
- 'CLIENT_ID' => $language->get('admin', 'client_id'),
- 'CLIENT_SECRET' => $language->get('admin', 'client_secret'),
- 'OAUTH_URL' => rtrim(URL::getSelfURL(), '/') . URL::build('/oauth', 'provider={{provider}}', 'non-friendly'),
'PARENT_PAGE' => PARENT_PAGE,
'DASHBOARD' => $language->get('admin', 'dashboard'),
'CONFIGURATION' => $language->get('admin', 'configuration'),
@@ -206,7 +168,6 @@
'SUBMIT' => $language->get('general', 'submit'),
'ENABLE_REGISTRATION' => $language->get('admin', 'enable_registration'),
'REGISTRATION_ENABLED' => $registration_enabled,
- 'OAUTH_PROVIDER_DATA' => $oauth_provider_data,
]);
$template->onPageLoad();