mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-22 23:56:29 +00:00
Changed parsing of login_extra_fields in guzzle auth
This commit is contained in:
parent
5b914b0422
commit
662db41bae
2 changed files with 28 additions and 2 deletions
|
@ -54,7 +54,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
|
|||
'loginUri' => $config->login_uri ?: null,
|
||||
'usernameField' => $config->login_username_field ?: null,
|
||||
'passwordField' => $config->login_password_field ?: null,
|
||||
'extraFields' => is_array($config->login_extra_fields) ? $config->login_extra_fields : [],
|
||||
'extraFields' => $this->processExtraFields($config->login_extra_fields),
|
||||
'notLoggedInXpath' => $config->not_logged_in_xpath ?: null,
|
||||
];
|
||||
|
||||
|
@ -65,4 +65,30 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
|
|||
|
||||
return new SiteConfig($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes login_extra_fields config, transforming an '=' separated array of strings
|
||||
* into a key/value array.
|
||||
*
|
||||
* @param array|mixed $extraFieldsStrings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function processExtraFields($extraFieldsStrings)
|
||||
{
|
||||
if (!is_array($extraFieldsStrings)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$extraFields = [];
|
||||
foreach ($extraFieldsStrings as $extraField) {
|
||||
if (strpos($extraField, '=') === false) {
|
||||
continue;
|
||||
}
|
||||
list($fieldName, $fieldValue) = explode('=', $extraField, 2);
|
||||
$extraFields[$fieldName] = $fieldValue;
|
||||
}
|
||||
|
||||
return $extraFields;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase
|
|||
$grabySiteConfig->login_uri = 'http://example.com/login';
|
||||
$grabySiteConfig->login_username_field = 'login';
|
||||
$grabySiteConfig->login_password_field = 'password';
|
||||
$grabySiteConfig->login_extra_fields = ['field' => 'value'];
|
||||
$grabySiteConfig->login_extra_fields = ['field=value'];
|
||||
$grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]';
|
||||
|
||||
$grabyConfigBuilderMock
|
||||
|
|
Loading…
Reference in a new issue