mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-28 12:01:13 +00:00
Use DomCrawler in LoginFormAuthenticator
This commit is contained in:
parent
c0d02153ab
commit
4e7b5c66ad
1 changed files with 6 additions and 11 deletions
|
@ -4,6 +4,7 @@ namespace Wallabag\SiteConfig\Authenticator;
|
||||||
|
|
||||||
use GuzzleHttp\ClientInterface;
|
use GuzzleHttp\ClientInterface;
|
||||||
use GuzzleHttp\Cookie\CookieJar;
|
use GuzzleHttp\Cookie\CookieJar;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||||
use Wallabag\ExpressionLanguage\AuthenticatorProvider;
|
use Wallabag\ExpressionLanguage\AuthenticatorProvider;
|
||||||
use Wallabag\SiteConfig\SiteConfig;
|
use Wallabag\SiteConfig\SiteConfig;
|
||||||
|
@ -54,22 +55,16 @@ class LoginFormAuthenticator implements Authenticator
|
||||||
|
|
||||||
public function isLoginRequired($html)
|
public function isLoginRequired($html)
|
||||||
{
|
{
|
||||||
$useInternalErrors = libxml_use_internal_errors(true);
|
|
||||||
|
|
||||||
// need to check for the login dom element ($options['not_logged_in_xpath']) in the HTML
|
// need to check for the login dom element ($options['not_logged_in_xpath']) in the HTML
|
||||||
$doc = new \DOMDocument();
|
try {
|
||||||
$doc->loadHTML($html);
|
$crawler = new Crawler((string) $html);
|
||||||
|
|
||||||
$xpath = new \DOMXPath($doc);
|
$loggedIn = $crawler->evaluate((string) $this->siteConfig->getNotLoggedInXpath());
|
||||||
$loggedIn = $xpath->evaluate((string) $this->siteConfig->getNotLoggedInXpath());
|
} catch (\Throwable $e) {
|
||||||
|
|
||||||
if (false === $loggedIn) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
libxml_use_internal_errors($useInternalErrors);
|
return \count($loggedIn) > 0;
|
||||||
|
|
||||||
return $loggedIn->length > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue