mirror of
https://github.com/e107inc/e107.git
synced 2025-08-03 13:17:24 +02:00
New interface for varied social login configuration fields
Uses the new e_user_provider::getFieldsOf() API
This commit is contained in:
@@ -1260,6 +1260,21 @@ class e_user_provider
|
|||||||
return $type;
|
return $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get standard and supplementary fields of the specified provider
|
||||||
|
* @param $providerName string Name of the supported social login provider
|
||||||
|
* @return array Multidimensional associative array where the keys are the known field names and the values are a
|
||||||
|
* description of what their key is for. Keys can be nested in parent keys. Parent keys will not
|
||||||
|
* have a description of the key. All fields take a string value. Return will be empty if the
|
||||||
|
* specified provider does not have any known fields.
|
||||||
|
*/
|
||||||
|
public static function getFieldsOf($providerName)
|
||||||
|
{
|
||||||
|
$standardFields = self::getStandardFieldsOf($providerName);
|
||||||
|
$supplementaryFields = self::getSupplementalFieldsOf($providerName);
|
||||||
|
return self::array_merge_recursive_distinct($standardFields, $supplementaryFields);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the standard/common/parent fields of the specified provider
|
* Get the standard/common/parent fields of the specified provider
|
||||||
* @param $providerName string Name of the supported social login provider
|
* @param $providerName string Name of the supported social login provider
|
||||||
@@ -1362,7 +1377,7 @@ class e_user_provider
|
|||||||
{
|
{
|
||||||
if (!isset($adapterTokens[$index][1]))
|
if (!isset($adapterTokens[$index][1]))
|
||||||
{
|
{
|
||||||
if (in_array($adapterTokens[$index], [';', '.', ','])) return $carry;
|
if (in_array($adapterTokens[$index], [';', '.', ',', '?'])) return $carry;
|
||||||
++$index;
|
++$index;
|
||||||
return self::adapterTokenParseConfig($adapterTokens, $index, $carry);
|
return self::adapterTokenParseConfig($adapterTokens, $index, $carry);
|
||||||
}
|
}
|
||||||
|
@@ -203,6 +203,19 @@ class SocialLoginConfigManager
|
|||||||
return e_user_provider::getTypeOf($providerName);
|
return e_user_provider::getTypeOf($providerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get standard and supplementary fields of the specified provider
|
||||||
|
* @param $providerName string Name of the supported social login provider
|
||||||
|
* @return array Multidimensional associative array where the keys are the known field names and the values are a
|
||||||
|
* description of what their key is for. Keys can be nested in parent keys. Parent keys will not
|
||||||
|
* have a description of the key. All fields take a string value. Return will be empty if the
|
||||||
|
* specified provider does not have any known fields.
|
||||||
|
*/
|
||||||
|
public function getFieldsOf($providerName)
|
||||||
|
{
|
||||||
|
return e_user_provider::getFieldsOf($providerName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the providers that are currently configured in the core preferences
|
* Get the providers that are currently configured in the core preferences
|
||||||
* @return array String list of configured provider names
|
* @return array String list of configured provider names
|
||||||
|
@@ -370,17 +370,13 @@ class social_ui extends e_admin_ui
|
|||||||
<col style='width:10%' />
|
<col style='width:10%' />
|
||||||
<col style='width:5%' />
|
<col style='width:5%' />
|
||||||
<col class='col-control' />
|
<col class='col-control' />
|
||||||
<col class='col-control' />
|
|
||||||
<col class='col-control' />
|
|
||||||
<col style='width:5%' />
|
<col style='width:5%' />
|
||||||
</colgroup>
|
</colgroup>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>" . LAN_SOCIAL_ADMIN_04 . "</th>
|
<th>" . LAN_SOCIAL_ADMIN_04 . "</th>
|
||||||
<th>" . LAN_SOCIAL_ADMIN_AUTH_TYPE . "</th>
|
<th>" . LAN_SOCIAL_ADMIN_AUTH_TYPE . "</th>
|
||||||
<th>" . LAN_SOCIAL_ADMIN_05 . "</th>
|
<th>" . LAN_SOCIAL_ADMIN_COLUMN_CONFIGURATION . "</th>
|
||||||
<th>" . LAN_SOCIAL_ADMIN_06 . "</th>
|
|
||||||
<th>" . LAN_SOCIAL_ADMIN_38 . "</th>
|
|
||||||
<th class='center'>" . LAN_SOCIAL_ADMIN_03 . "</th>
|
<th class='center'>" . LAN_SOCIAL_ADMIN_03 . "</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -422,41 +418,27 @@ class social_ui extends e_admin_ui
|
|||||||
<td>$provider_type</td>
|
<td>$provider_type</td>
|
||||||
";
|
";
|
||||||
|
|
||||||
if ($provider_type == "OpenID")
|
$text .= "<td>";
|
||||||
|
$fieldInfo = self::array_slash($slcm->getFieldsOf($provider_name));
|
||||||
|
foreach ($fieldInfo as $fieldSlash => $description)
|
||||||
{
|
{
|
||||||
$openid_identifier = $slcm->getProviderConfig($provider_name, '/openid_identifier');
|
$field = str_replace("/", "][", $fieldSlash);
|
||||||
$frm_options = ['size' => 'block-level'];
|
$frm_options = [
|
||||||
if (empty($openid_identifier))
|
'size' => 'block-level',
|
||||||
{
|
'placeholder' => self::getPlaceholderFor($provider_name, $fieldSlash),
|
||||||
try
|
];
|
||||||
{
|
|
||||||
$class = "\Hybridauth\Provider\\$provider_name";
|
$text .= "<div><label>$fieldSlash</label>";
|
||||||
$reflection = new ReflectionClass($class);
|
$text .= $frm->text(
|
||||||
$properties = $reflection->getDefaultProperties();
|
"social_login[$provider_name][$field]",
|
||||||
$frm_options['placeholder'] = $properties['openidIdentifier'];
|
$slcm->getProviderConfig($provider_name, $fieldSlash),
|
||||||
}
|
256,
|
||||||
catch (Exception $e)
|
$frm_options
|
||||||
{
|
);
|
||||||
$openid_identifier = "";
|
$text .= "<div class='smalltext field-help'>$description</div>";
|
||||||
}
|
$text .= "</div>";
|
||||||
}
|
|
||||||
$textKeys .= "<td>" .
|
|
||||||
$frm->text("social_login[$provider_name][openid_identifier]", $openid_identifier, 256, $frm_options) .
|
|
||||||
"</td><td></td><td></td>";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$textKeys .= "<td>" . $frm->text("social_login[$provider_name][keys][id]", $slcm->getProviderConfig($provider_name, '/keys/id'), 128, ['size' => 'block-level']);
|
|
||||||
$textKeys .= "<td>" . $frm->text("social_login[$provider_name][keys][secret]", $slcm->getProviderConfig($provider_name, '/keys/secret'), 128, ['size' => 'block-level']);
|
|
||||||
if ($provider_type == "OAuth2" || $slcm->getProviderConfig($provider_name, '/scope'))
|
|
||||||
{
|
|
||||||
$textKeys .= "<td>" . $frm->text("social_login[$provider_name][scope]", $slcm->getProviderConfig($provider_name, '/scope'), 128, ['size' => 'block-level']);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$textKeys .= "<td></td>";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$text .= "</td>";
|
||||||
|
|
||||||
$textEnabled = $frm->radio_switch("social_login[$provider_name][enabled]", $slcm->isProviderEnabled($provider_name), '', '', ['class' => 'e-expandit']);
|
$textEnabled = $frm->radio_switch("social_login[$provider_name][enabled]", $slcm->isProviderEnabled($provider_name), '', '', ['class' => 'e-expandit']);
|
||||||
|
|
||||||
@@ -469,6 +451,60 @@ class social_ui extends e_admin_ui
|
|||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on Illuminate\Support\Arr::dot()
|
||||||
|
* @copyright Copyright (c) Taylor Otwell
|
||||||
|
* @license https://github.com/illuminate/support/blob/master/LICENSE.md MIT License
|
||||||
|
* @param $array
|
||||||
|
* @param string $prepend
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function array_slash($array, $prepend = '')
|
||||||
|
{
|
||||||
|
$results = [];
|
||||||
|
|
||||||
|
foreach ($array as $key => $value)
|
||||||
|
{
|
||||||
|
if (is_array($value) && !empty($value))
|
||||||
|
{
|
||||||
|
$results = array_merge($results, static::array_slash($value, $prepend . $key . '/'));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$results[$prepend . $key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getPlaceholderFor($providerName, $fieldSlash)
|
||||||
|
{
|
||||||
|
switch ($fieldSlash)
|
||||||
|
{
|
||||||
|
case "scope":
|
||||||
|
$propertyName = "scope";
|
||||||
|
break;
|
||||||
|
case "openid_identifier":
|
||||||
|
$propertyName = "openidIdentifier";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$propertyName = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$class = "\Hybridauth\Provider\\$providerName";
|
||||||
|
$reflection = new ReflectionClass($class);
|
||||||
|
$properties = $reflection->getDefaultProperties();
|
||||||
|
return isset($properties[$propertyName]) ? $properties[$propertyName] : null;
|
||||||
|
}
|
||||||
|
catch (ReflectionException $e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function generateAdminFormJs()
|
private function generateAdminFormJs()
|
||||||
{
|
{
|
||||||
return <<<EOD
|
return <<<EOD
|
||||||
|
@@ -55,6 +55,8 @@ define("LAN_SOCIAL_UPDATE_REQUIRED",
|
|||||||
"A <a href=\"" . e_ADMIN_ABS . "e107_update.php\">database update</a> is required to continue using this plugin."
|
"A <a href=\"" . e_ADMIN_ABS . "e107_update.php\">database update</a> is required to continue using this plugin."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
define("LAN_SOCIAL_ADMIN_COLUMN_CONFIGURATION", "Configuration");
|
||||||
|
|
||||||
define("LAN_SOCIAL_ADMIN_TEST_PAGE_TOGGLE", "Test Page");
|
define("LAN_SOCIAL_ADMIN_TEST_PAGE_TOGGLE", "Test Page");
|
||||||
define("LAN_SOCIAL_ADMIN_TEST_PAGE_INFO", "Enable or disable the social login test page");
|
define("LAN_SOCIAL_ADMIN_TEST_PAGE_INFO", "Enable or disable the social login test page");
|
||||||
define("LAN_SOCIAL_ADMIN_08", "Note: In most cases, you will need to obtain an application ID and secret key from social login providers.\nIf a provider's name is a link, that link should take you to the login application configuration documentation.\n\nYou may test your configuration with the following URL after enabling the \"".LAN_SOCIAL_ADMIN_TEST_PAGE_TOGGLE."\" option:");
|
define("LAN_SOCIAL_ADMIN_08", "Note: In most cases, you will need to obtain an application ID and secret key from social login providers.\nIf a provider's name is a link, that link should take you to the login application configuration documentation.\n\nYou may test your configuration with the following URL after enabling the \"".LAN_SOCIAL_ADMIN_TEST_PAGE_TOGGLE."\" option:");
|
||||||
|
@@ -42,6 +42,7 @@ class social_setup
|
|||||||
$actualNormalizedProviderName = $manager->normalizeProviderName($denormalizedProviderName);
|
$actualNormalizedProviderName = $manager->normalizeProviderName($denormalizedProviderName);
|
||||||
|
|
||||||
$newOptions = $oldOptions;
|
$newOptions = $oldOptions;
|
||||||
|
/* Commented out because there are no known options to migrate from HybridAuth 2 to Hybridauth 3
|
||||||
if (isset($newOptions['keys']['key']))
|
if (isset($newOptions['keys']['key']))
|
||||||
{
|
{
|
||||||
$newOptions['keys']['id'] = $newOptions['keys']['key'];
|
$newOptions['keys']['id'] = $newOptions['keys']['key'];
|
||||||
@@ -55,6 +56,7 @@ class social_setup
|
|||||||
"Updated configuration format of social login provider $denormalizedProviderName"
|
"Updated configuration format of social login provider $denormalizedProviderName"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if ($actualNormalizedProviderName !== $oldNormalizedProviderName)
|
if ($actualNormalizedProviderName !== $oldNormalizedProviderName)
|
||||||
{
|
{
|
||||||
|
@@ -109,6 +109,7 @@ class e_user_providerTest extends \Codeception\Test\Unit
|
|||||||
$result = e_user_provider::getSupplementalFieldsOf("Twitter");
|
$result = e_user_provider::getSupplementalFieldsOf("Twitter");
|
||||||
$this->assertTrue(array_key_exists('authorize', $result));
|
$this->assertTrue(array_key_exists('authorize', $result));
|
||||||
$this->assertTrue(array_key_exists('photo_size', $result));
|
$this->assertTrue(array_key_exists('photo_size', $result));
|
||||||
|
$this->assertIsNotArray($result['photo_size']);
|
||||||
|
|
||||||
$result = e_user_provider::getSupplementalFieldsOf("Vkontakte");
|
$result = e_user_provider::getSupplementalFieldsOf("Vkontakte");
|
||||||
$this->assertTrue(array_key_exists('photo_size', $result));
|
$this->assertTrue(array_key_exists('photo_size', $result));
|
||||||
|
Reference in New Issue
Block a user