Task: Simplify spam protection service

This commit is contained in:
Björn Fromme
2023-07-07 09:42:36 +02:00
parent fa79ef8c80
commit 5c857d3afc
@@ -3,7 +3,6 @@
namespace EP\EpEvents\Service; namespace EP\EpEvents\Service;
use Symfony\Component\HttpClient\HttpClient; use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\SingletonInterface;
class SpamProtectService implements SingletonInterface class SpamProtectService implements SingletonInterface
@@ -13,23 +12,23 @@ class SpamProtectService implements SingletonInterface
$client = HttpClient::create(); $client = HttpClient::create();
try { try {
$response = $client->request('GET', 'https://api.stopforumspam.org/api', [ $response = $client->request('POST', 'https://api.stopforumspam.org/api', [
'query' => [ 'query' => [
'emailhash' => md5($email), 'json' => true,
],
'body' => [
'email' => $email,
] ]
]); ]);
$result = simplexml_load_string($response->getContent());
$success = (bool)$result->attributes()['success'];
if (false === $success) { $result = $response->toArray();
if (false === (bool) $result['success']) {
return false; return false;
} }
$appears = (string)$result->appears === 'yes'; return (bool) $result['appears'];
if (true === $appears) { } catch (\Throwable $e) {
return true;
}
} catch (TransportExceptionInterface $e) {
} }
return false; return false;