yepsua/filament-captcha-field 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yepsua/filament-captcha-field

最新稳定版本:v0.1.1

Composer 安装命令:

composer require yepsua/filament-captcha-field

包简介

Provides a captcha field for the Filament Forms

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Easy integration with mewebstudio/captcha for the Filament forms.

Requirements:

  • PHP extension: ext-gd

Installation

Install the package via composer:

composer require yepsua/filament-captcha-field

Publish the package mewebstudio/captcha config file:

php artisan vendor:publish --provider="Mews\Captcha\CaptchaServiceProvider" --tag="config"

Usage

You can include the captcha field like any other filament field.

    use Yepsua\Filament\Forms\Components\Captcha;
    ...
    protected function getFormSchema(): array
    {
        return [
            Forms\Components\TextInput::make('username'),
            Forms\Components\TextInput::make('password')->type('password'),
            Captcha::make('captcha')
        ];
    }

You can also just display the image and validate the captcha using any other TextInput field:

    use Yepsua\Filament\Forms\Components\CaptchaImage;
    ...
    protected function getFormSchema(): array
    {
        return [
            Forms\Components\TextInput::make('username'),
            Forms\Components\TextInput::make('password')->type('password'),
            Forms\Components\TextInput::make('captcha')->required()->rules('required|captcha'),
            CaptchaImage::make('captchaImg')
        ];
    }

The captcha uses by default the flat config. You can create/update the captcha configs in the file: config/captcha.php.

You can switch to any other available captcha config, like the math config:

    use Yepsua\Filament\Forms\Components\Captcha;
    ...
    protected function getFormSchema(): array
    {
        return [
            Captcha::make('captcha')->config('math')
        ];
    }

For more info about the captcha configuration, please read the mewebstudio/captcha documentation.

Translations

This package and mewebstudio/captcha don't provide any translation for the captcha validation message, but you can translate the message by yourself, just add the item in the file resources/lang/{lang}/validation.php

return [
    ...
    'captcha'             => 'Invalid captcha.',
    ...
]

Case of use: Add a captcha in the filament login form:

  1. Extend the Login page class to add the new field into the form:
<?php

namespace  App\Filament\Pages\Auth;

use Filament\Http\Livewire\Auth\Login as BaseLoginPage;
use Yepsua\Filament\Forms\Components\Captcha;

class Login extends BaseLoginPage
{

    protected function getFormSchema(): array
    {
        $formSchema = parent::getFormSchema();
        $formSchema[] = Captcha::make('captcha');

        return $formSchema;
    }
}
  1. Use the new Login page instead the original filament page.
return [
    ...
    'auth' => [
        'guard' => env('FILAMENT_AUTH_GUARD', 'web'),
        'pages' => [
            // 'login' => \Filament\Http\Livewire\Auth\Login::class, // <- Original form
            'login' => \App\Filament\Pages\Auth\Login::class,        // <- Form with captcha
        ],
    ],
    ...
]
  1. Done. Finally you can test the captcha in the login form.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 4.87k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 18
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 18
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-03