Task: Simplify spam protection service
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
namespace EP\EpEvents\Service;
|
||||
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use TYPO3\CMS\Core\SingletonInterface;
|
||||
|
||||
class SpamProtectService implements SingletonInterface
|
||||
@@ -13,23 +12,23 @@ class SpamProtectService implements SingletonInterface
|
||||
$client = HttpClient::create();
|
||||
|
||||
try {
|
||||
$response = $client->request('GET', 'https://api.stopforumspam.org/api', [
|
||||
$response = $client->request('POST', 'https://api.stopforumspam.org/api', [
|
||||
'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;
|
||||
}
|
||||
|
||||
$appears = (string)$result->appears === 'yes';
|
||||
if (true === $appears) {
|
||||
return true;
|
||||
}
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
return (bool) $result['appears'];
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user