Implement 'stop forum spam' api to prevent form spam

This commit is contained in:
Björn Fromme
2022-08-06 22:13:49 +02:00
parent 0cc08e0a30
commit 7cc7fa4b69
5 changed files with 1916 additions and 30 deletions
@@ -0,0 +1,37 @@
<?php
namespace EP\EpEvents\Service;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use TYPO3\CMS\Core\SingletonInterface;
class SpamProtectService implements SingletonInterface
{
public function isSpamEmail(string $email): bool
{
$client = HttpClient::create();
try {
$response = $client->request('GET', 'https://api.stopforumspam.org/api', [
'query' => [
'emailhash' => md5($email),
]
]);
$result = simplexml_load_string($response->getContent());
$success = (bool)$result->attributes()['success'];
if (false === $success) {
return false;
}
$appears = (string)$result->appears === 'yes';
if (true === $appears) {
return true;
}
} catch (TransportExceptionInterface $e) {
}
return false;
}
}