diff --git a/plugins/jsconnect/class.jsconnect.plugin.php b/plugins/jsconnect/class.jsconnect.plugin.php index 399305431..aa7f949bb 100644 --- a/plugins/jsconnect/class.jsconnect.plugin.php +++ b/plugins/jsconnect/class.jsconnect.plugin.php @@ -563,6 +563,18 @@ public function entryController_jsConnect_create($sender, $action = '', $target $get = arrayTranslate($sender->Request->get(), ['client_id', 'display']); $sender->addDefinition('JsAuthenticateUrl', self::connectUrl($provider, true)); + if ($provider['TestMode'] ?? false) { + $sender->addDefinition('JsConnectTestMode', true); + } + + if (gdn::config('Garden.PrivateCommunity') && $provider['IsDefault']) { + // jsconnect.js needs to know to not to redirect if there is an error + // and PrivateCommunity is on and this is the only log in method, + // this causes a loop. + $sender->addDefinition('PrivateCommunity', true); + $sender->addDefinition('GenericSSOErrorMessage', gdn::translate('An error has occurred, please try again.')); + } + $sender->addJsFile('jsconnect.js', 'plugins/jsconnect'); $sender->setData('Title', t('Connecting...')); $sender->Form->Action = url('/entry/connect/jsconnect?'.http_build_query($get)); diff --git a/plugins/jsconnect/js/jsconnect.js b/plugins/jsconnect/js/jsconnect.js index 3599be655..59a065a11 100644 --- a/plugins/jsconnect/js/jsconnect.js +++ b/plugins/jsconnect/js/jsconnect.js @@ -21,8 +21,12 @@ $.jsConnectAuthenticate = function(url) { url: url, dataType: 'json', timeout: 10000, + cache: false, success: function(data) { var connectData = $.param(data); + if (gdn.definition('JsConnectTestMode', false)) { + console.log('AuthenticationResponse', JSON.stringify(data)); + } if ($('#Form_JsConnect-Connect').length > 0) { if (data['error']) { @@ -30,8 +34,18 @@ $.jsConnectAuthenticate = function(url) { } else if (!data['uniqueid']) { // Just redirect to the target. var target = $('#Form_Target').val(); - if (!target) + if (!target) { target = '/'; + } + + // Do not redirect if it is a private community, this will cause a loop. + if (gdn.definition('PrivateCommunity', false)) { + setTimeout(function() { + $('.Connect-Wait').hide(); + $('.jsConnect-Connecting').html('