Files
clinicpro/src/Shared/Captcha/CaptchaController.php
T
hamed c3c520801d feat(captcha): add ALTCHA configuration endpoint and integrate into HomeController
- Introduced a new endpoint `/api/v1/altcha/config` in CaptchaController to return the status of the ALTCHA captcha.
- Updated HomeController to inject AltchaService and pass the captcha status to the home page template.
- Modified the home.html.twig template to conditionally render the ALTCHA widget based on the captcha status.
- Updated manifest.json and cache files to reflect changes in the codebase.
2026-07-10 11:18:40 +03:30

37 lines
1.3 KiB
PHP

<?php
namespace App\Shared\Captcha;
use App\Shared\Controller\BaseController;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
#[OA\Tag(name: 'Captcha')]
class CaptchaController extends BaseController
{
public function __construct(private readonly AltchaService $altcha) {}
#[OA\Get(
path: '/api/v1/altcha/challenge',
summary: 'صدور یک challenge امضاشده‌ی ALTCHA برای حل proof-of-work سمت مرورگر',
responses: [new OA\Response(response: 200, description: 'ALTCHA challenge object')]
)]
#[Route('/api/v1/altcha/challenge', methods: ['GET'])]
public function challenge(): JsonResponse
{
return new JsonResponse($this->altcha->createChallenge());
}
#[OA\Get(
path: '/api/v1/altcha/config',
summary: 'وضعیت فعال/غیرفعال بودن کپچا — کلاینت‌ها بر اساس آن widget را رندر می‌کنند',
responses: [new OA\Response(response: 200, description: '{ "enabled": bool }')]
)]
#[Route('/api/v1/altcha/config', methods: ['GET'])]
public function config(): JsonResponse
{
return new JsonResponse(['enabled' => $this->altcha->enabled()]);
}
}