Revived API /api/v1/captcha.
Now a new captcha is created to check for a bot.
This commit is contained in:
@@ -36,4 +36,9 @@ final readonly class CaptchaTokenRepository
|
||||
|
||||
return $this->createSearchInstanceCommand->execute($query);
|
||||
}
|
||||
|
||||
public function getCaptchaTokenByPublicToken(string $token): ?CaptchaToken
|
||||
{
|
||||
return CaptchaToken::query()->where('public_token', '=', $token)->first();
|
||||
}
|
||||
}
|
||||
|
31
app/Repositories/DataCaptchaRepository.php
Normal file
31
app/Repositories/DataCaptchaRepository.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Exceptions\Repositories\DataCaptchaRepositoryException;
|
||||
use App\Models\Captcha;
|
||||
use App\Services\GenerateTokenCommand\GenerateTokenUlidCommand;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
final readonly class DataCaptchaRepository
|
||||
{
|
||||
public function __construct(
|
||||
private GenerateTokenUlidCommand $generateTokenUlidCommand,
|
||||
) { }
|
||||
|
||||
public function store(Captcha $captcha, array $coordinators, Carbon $expires): string
|
||||
{
|
||||
$key = $this->generateTokenUlidCommand->execute() . '_' . time();
|
||||
$data = [
|
||||
'id' => $captcha->id,
|
||||
'coordinators' => $coordinators
|
||||
];
|
||||
|
||||
if (!Cache::driver('redis')->add($key, $data, $expires) ) {
|
||||
throw new DataCaptchaRepositoryException('Could not create cache for captcha: ' . $captcha->id . ' key: ' . $key);
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user