1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-25 23:36:29 +02:00

New API to detect if social login is enabled site-wide

The site-wide social login system is now backwards-compatible with how
the social_login_active core pref worked since commit
3b2d8333b6.

social_login_active's least significant bit is now treated as a global
bit, so if it's not set, no other bits are allowed to be set. This
un-breaks all existing checks for whether social_login_active is empty.

Except in themes, the social_login_active check has been replaced with
an e_user_provider API to check if social login is enabled site-wide.
This commit is contained in:
Nick Liu
2020-02-22 23:55:20 +01:00
parent 616add5c93
commit 379a963902
10 changed files with 110 additions and 18 deletions

View File

@@ -35,16 +35,24 @@ class SocialLoginConfigManager
/**
* Check a social login boolean (toggle) setting
*
* For backwards compatibility, if the global bit (0) is off, no other bits can be on.
*
* @param int $bit Which setting to check
* @return boolean TRUE if the setting is enabled, FALSE otherwise
*/
public function isFlagActive($bit = self::ENABLE_BIT_GLOBAL)
{
return (bool)($this->config->get(self::SOCIAL_LOGIN_FLAGS) & 1 << $bit);
$flags = $this->config->get(self::SOCIAL_LOGIN_FLAGS);
if (!($flags & 1 << self::ENABLE_BIT_GLOBAL)) return false;
return (bool)($flags & 1 << $bit);
}
/**
* Set a social login boolean (toggle) setting
*
* For backwards compatibility, if the global bit (0) is off, no other bits can be on.
*
* @param int $bit Which setting to change
* @param boolean $active TRUE to enable the setting, FALSE to disable the setting
*/
@@ -54,7 +62,9 @@ class SocialLoginConfigManager
if (!is_numeric($flags)) $flags = 0x0;
$flags = $flags & ~(1 << $bit) | ($active << $bit);
$this->config->set(self::SOCIAL_LOGIN_FLAGS, $flags);
if (!($flags & 1 << self::ENABLE_BIT_GLOBAL)) $this->config->set(self::SOCIAL_LOGIN_FLAGS, 0x0);
else $this->config->set(self::SOCIAL_LOGIN_FLAGS, $flags);
$this->saveConfig();
}

View File

@@ -225,7 +225,9 @@ class social_ui extends e_admin_ui
return "<p>" . LAN_SOCIAL_UPDATE_REQUIRED . "</p>";
}
$text = "<table class='table adminform'>
$text = $this->generateAdminFormJs();
$text .= "<table class='table adminform'>
<colgroup>
<col class='col-label' />
<col class='col-control' />
@@ -466,6 +468,53 @@ class social_ui extends e_admin_ui
return $text;
}
private function generateAdminFormJs()
{
return <<<EOD
<script type='text/javascript'>
var e107 = e107 || {'settings': {}, 'behaviors': {}};
let socialLoginSwitches = {
'social-login-test-page__switch': null,
};
function socialLoginSwitchesHighstate(element) {
if (element === undefined) return;
let isActive = element.checked;
if (isActive) {
for (let key in socialLoginSwitches) {
let toggle = $('[name='+key+']');
toggle.bootstrapSwitch('disabled', false);
if (socialLoginSwitches[key] !== null) toggle.bootstrapSwitch('state', socialLoginSwitches[key]);
}
} else {
for (let key in socialLoginSwitches) {
let toggle = $('[name='+key+']');
socialLoginSwitches[key] = toggle.bootstrapSwitch('state');
toggle.bootstrapSwitch('state', false);
toggle.bootstrapSwitch('disabled', true);
}
}
}
(function ($)
{
e107.behaviors.manageSocialLoginSwitches = {
attach: function (context, settings) {
let globalSwitch = $('[name=social-login-active__switch]');
socialLoginSwitchesHighstate(globalSwitch.get(0));
globalSwitch.on('switchChange.bootstrapSwitch', function(event) {
socialLoginSwitchesHighstate(event.target);
});
},
};
})(jQuery);
</script>
EOD;
}
}

View File

@@ -164,7 +164,7 @@ class social_shortcodes extends e_shortcode
function sc_social_login($parm=null)
{
$pref = e107::pref('core', 'social_login_active');
$pref = e107::getUserProvider()->isSocialLoginEnabled();