Skip to content

Commit a0906fa

Browse files
committed
show captchas on register page
closes #13
1 parent 33e2e45 commit a0906fa

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

register/src/Filament/Pages/Auth/Register.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,43 @@
22

33
namespace Boy132\Register\Filament\Pages\Auth;
44

5+
use App\Extensions\Captcha\CaptchaService;
56
use Filament\Auth\Pages\Register as BaseRegister;
67
use Filament\Forms\Components\TextInput;
78
use Filament\Schemas\Components\Component;
9+
use Filament\Schemas\Schema;
810

911
class Register extends BaseRegister
1012
{
13+
protected CaptchaService $captchaService;
14+
15+
public function boot(CaptchaService $captchaService): void
16+
{
17+
$this->captchaService = $captchaService;
18+
}
19+
20+
public function form(Schema $schema): Schema
21+
{
22+
$components = [
23+
$this->getNameFormComponent(),
24+
$this->getEmailFormComponent(),
25+
$this->getPasswordFormComponent(),
26+
$this->getPasswordConfirmationFormComponent(),
27+
];
28+
29+
if ($captchaComponent = $this->getCaptchaComponent()) {
30+
$components[] = $captchaComponent;
31+
}
32+
33+
return $schema
34+
->components($components);
35+
}
36+
37+
private function getCaptchaComponent(): ?Component
38+
{
39+
return $this->captchaService->getActiveSchema()?->getFormComponent();
40+
}
41+
1142
protected function getNameFormComponent(): Component
1243
{
1344
/** @var TextInput $parent */

0 commit comments

Comments
 (0)