Add AST cache files for AltchaService, API documentation, and AltchaService tests
- Created JSON representation of AltchaService class and its methods, including imports and relationships. - Added documentation for the Captcha API, detailing endpoints and responses. - Introduced test cases for AltchaService, covering various functionalities and edge cases.
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Shared\Captcha;
|
||||
|
||||
use AltchaOrg\Altcha\V1\Altcha;
|
||||
use AltchaOrg\Altcha\V1\ChallengeOptions;
|
||||
use App\Config\Repository\SiteConfigRepository;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
|
||||
/**
|
||||
@@ -20,17 +21,26 @@ class AltchaService
|
||||
|
||||
public function __construct(
|
||||
private readonly string $hmacKey,
|
||||
private readonly bool $enabled,
|
||||
private readonly bool $envEnabled,
|
||||
private readonly int $maxNumber,
|
||||
private readonly int $expireSeconds,
|
||||
private readonly CacheItemPoolInterface $altchaPool,
|
||||
private readonly SiteConfigRepository $configRepo,
|
||||
) {
|
||||
$this->altcha = new Altcha($this->hmacKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* فعال بودن کپچا: override پنل ادمین (site_config) مقدم است؛ اگر ست نشده باشد،
|
||||
* به مقدار env (`ALTCHA_ENABLED`) برمیگردد. پس هم از env هم از پنل قابل کنترل است.
|
||||
*/
|
||||
public function enabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
$override = $this->configRepo->get('altcha_enabled');
|
||||
if ($override !== null && $override !== '') {
|
||||
return $override === '1' || strtolower($override) === 'true';
|
||||
}
|
||||
return $this->envEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user