Implement 'stop forum spam' api to prevent form spam
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user