Passed
Push — master ( 4f5b3b...1c5d75 )
by Darko
09:48
created

CaptchaStatus   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 21
eloc 46
c 1
b 0
f 0
dl 0
loc 79
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
D handle() 0 60 21
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
7
class CaptchaStatus extends Command
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'captcha:status';
15
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Check CAPTCHA configuration status';
22
23
    /**
24
     * Execute the console command.
25
     */
26
    public function handle(): int
27
    {
28
        $this->info('CAPTCHA Configuration Status');
29
        $this->info('================================');
30
        $this->newLine();
31
32
        $provider = config('captcha.provider', 'recaptcha');
33
        $this->line("Active Provider: <fg=cyan>{$provider}</>");
34
        $this->newLine();
35
36
        // Check reCAPTCHA
37
        $this->info('Google reCAPTCHA:');
38
        $recaptchaEnabled = config('captcha.recaptcha.enabled');
39
        $recaptchaSitekey = config('captcha.recaptcha.sitekey');
40
        $recaptchaSecret = config('captcha.recaptcha.secret');
41
42
        $this->line('  Enabled: '.($recaptchaEnabled ? '<fg=green>Yes</>' : '<fg=red>No</>'));
43
        $this->line('  Site Key: '.(! empty($recaptchaSitekey) ? '<fg=green>Configured</>' : '<fg=red>Missing</>'));
44
        $this->line('  Secret: '.(! empty($recaptchaSecret) ? '<fg=green>Configured</>' : '<fg=red>Missing</>'));
45
        $this->newLine();
46
47
        // Check Turnstile
48
        $this->info('Cloudflare Turnstile:');
49
        $turnstileEnabled = config('captcha.turnstile.enabled');
50
        $turnstileSitekey = config('captcha.turnstile.sitekey');
51
        $turnstileSecret = config('captcha.turnstile.secret');
52
53
        $this->line('  Enabled: '.($turnstileEnabled ? '<fg=green>Yes</>' : '<fg=red>No</>'));
54
        $this->line('  Site Key: '.(! empty($turnstileSitekey) ? '<fg=green>Configured</>' : '<fg=red>Missing</>'));
55
        $this->line('  Secret: '.(! empty($turnstileSecret) ? '<fg=green>Configured</>' : '<fg=red>Missing</>'));
56
        $this->newLine();
57
58
        // Validation
59
        $recaptchaReady = $recaptchaEnabled && ! empty($recaptchaSitekey) && ! empty($recaptchaSecret);
60
        $turnstileReady = $turnstileEnabled && ! empty($turnstileSitekey) && ! empty($turnstileSecret);
61
62
        if ($recaptchaReady && $turnstileReady) {
63
            $this->error('⚠ WARNING: Both providers are enabled!');
64
            $this->warn('Only one CAPTCHA provider should be enabled at a time.');
65
            $this->warn("The system will use: {$provider}");
66
            $this->newLine();
67
        }
68
69
        if ($provider === 'recaptcha' && $recaptchaReady) {
70
            $this->info('✓ reCAPTCHA is properly configured and active');
71
        } elseif ($provider === 'turnstile' && $turnstileReady) {
72
            $this->info('✓ Turnstile is properly configured and active');
73
        } elseif ($provider === 'recaptcha' && ! $recaptchaReady) {
74
            $this->error('✗ reCAPTCHA is selected but not properly configured');
75
        } elseif ($provider === 'turnstile' && ! $turnstileReady) {
76
            $this->error('✗ Turnstile is selected but not properly configured');
77
        } else {
78
            $this->warn('⚠ No CAPTCHA provider is active');
79
        }
80
81
        $this->newLine();
82
        $this->comment('To change providers, update CAPTCHA_PROVIDER in your .env file');
83
        $this->comment('Then run: php artisan config:clear');
84
85
        return Command::SUCCESS;
86
    }
87
}
88