You've already forked Atomcms-edit
Initial commit
This commit is contained in:
Executable
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/* Credits to Kani for this */
|
||||
|
||||
readonly class FindRetrosService
|
||||
{
|
||||
private const string FIND_RETROS_VERIFY_URI = '%s/validate.php?user=%s&ip=%s';
|
||||
|
||||
private const string FIND_RETROS_REDIRECT_URI = '%s/servers/%s/vote?minimal=1&return=1';
|
||||
|
||||
private const string FIND_RETROS_CACHE_KEY = 'voted.%s';
|
||||
|
||||
private Client $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new Client(['verify' => false]);
|
||||
}
|
||||
|
||||
public function checkHasVoted(): bool
|
||||
{
|
||||
if (! config('habbo.findretros.enabled')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$ip = request()->ip();
|
||||
if ($ip === '127.0.0.1') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (request()->has('novote')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$cacheKey = sprintf(self::FIND_RETROS_CACHE_KEY, $ip);
|
||||
if (Cache::has($cacheKey)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$uri = sprintf(
|
||||
self::FIND_RETROS_VERIFY_URI,
|
||||
config('habbo.findretros.api'),
|
||||
config('habbo.findretros.name'),
|
||||
$ip,
|
||||
);
|
||||
|
||||
$request = $this->client->get($uri);
|
||||
$response = $request->getBody()->getContents();
|
||||
|
||||
if (in_array($response, ['1', '2'], true)) {
|
||||
Cache::put($cacheKey, true, now()->addMinutes(30));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getRedirectUri(): string
|
||||
{
|
||||
return sprintf(
|
||||
self::FIND_RETROS_REDIRECT_URI,
|
||||
config('habbo.findretros.api'),
|
||||
config('habbo.findretros.name'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user