tejas/tejascaptcha

适用于 Laravel 框架的 Tejas Captcha


README

tejas/tejascaptcha 是 Laravel 的服务提供者。该包随机生成字母数字验证码或数学验证码,并提供刷新和音频功能。

章节链接

预览

The preview image is not available

兼容性

tejas/tejascaptcha 服务提供者已在 Laravel 版本 5、6 和 7 上进行了测试。测试是在 Linux / Debian / Apache2 网络服务器上进行的。

安装

Tejas Captcha

TejasCaptcha 服务提供者通过 Composer 安装。

从您项目根目录,打开终端并运行以下命令

  • composer require tejas/tejascaptcha
  • npm install bootstrap
  • npm install @fortawesome/fontawesome-free

The composer require cmd image is not available

Tejas Captcha 中间件 - 验证码验证

app/Http/Middleware/VerifyTejasCaptcha.php

中间件用于验证验证码是否正确输入。

从您项目根目录,打开终端并运行以下命令

  • cp vendor/tejas/tejascaptcha/src/app/Http/Middleware/VerifyTejasCaptcha.php app/Http/Middleware/.

此命令将 VerifyTejasCaptcha.php 中间件占位符文件复制到您的项目 app/Http/Middleware 文件夹。

namespace App\Http\Middleware;

use Tejas\TejasCaptcha\Http\Middleware\VerifyTejasCaptcha as Middleware;

class VerifyTejasCaptcha extends Middleware
{
    /*
      Uses the tejas/tejascaptcha service providers middleware
    */
}

The tejascaptcha middleware image is not available

app/Http/Kernel.php

app/Http/Kernel.php 文件的 routeMiddleware 部分的底部插入以下行

  • 'tejascaptcha_verify_captcha' => \App\Http\Middleware\VerifyTejasCaptcha::class,

The tejascaptcha middleware Kernel file image is not available

在需要包含 tejas/tejascaptcha 的 Post 提交的地方使用此中间件声明。

example/routes/web.php

使用 tejascaptcha 中间件示例表单提交路由

此路由声明在 example/routes/web.php 文件中。它是 Tejas Captcha 包附带的工作示例文件的一部分。有关实现细节,请参阅 example/README.md。

Route::post('tejascaptcha_verify_form','TejasCaptcha_Controller@tejasCaptcha')->middleware('tejascaptcha_verify_captcha');

The tejascaptcha Routing image is not available

Bootstrap - Laravel 安装

打开终端,导航到您的项目根目录并运行

  • composer require laravel/ui
  • php artisan ui bootstrap
    • 如果您还想要认证架构: php artisan ui bootstrap --auth
  • npm install && npm run dev

Tejas Captcha Makefile - 安装后

此步骤是可选的。

要安装包含的 Makefile,请从您的项目根目录运行以下命令。

  • cd vendor/tejas/tejascaptcha/scripts && bash postinstall.sh && cd ../../../../

Makefile 已安装到您项目根目录中的 tejascaptcha 目录中。

安装后运行 tejascaptcha/Makefile;从您的项目根目录运行以下命令,并使用指定的 make 操作之一

  • make -C tejascaptcha [ install update test remove show_version ]

注册 Tejas Captcha 服务提供者

此步骤是可选的 - tejas/tejascaptcha 通过 Composer 包发现自动注册。

config/app.php

config/app.php 文件的 providers 键下注册 tejas/tejascaptcha 服务提供者。

The service providers image is not available

    'providers' => [
        Tejas\TejasCaptcha\TejasCaptchaServiceProvider::class,
    ]

config/app.php 文件的 aliases 键下注册 tejas/tejascaptcha 服务提供者的别名。

The service providers alias image is not available

    'aliases' => [
        'TejasCaptcha' => Tejas\TejasCaptcha\Facades\TejasCaptcha::class,
    ]

配置

发布配置文件

config/tejascaptcha.php

要自定义 tejas/tejascaptcha 的设置,请从您的项目根目录运行 Laravel 的 vendor:publish artisan 命令。

$ php artisan vendor:publish

示例输出

The vendor publish image is not available

输入 tejascaptcha 服务提供者对应的数字并按回车。tejas/tejascaptcha 的配置文件 tejascaptcha.php 的可编辑副本应已复制到您的项目 config 目录。

简化的默认配置文件

<?php
return [
    'config_section_key' => 'standard',

    'standard' => [
        'length' => 5,
        'width' => 230,
        'height' => 50,
        'quality' => 90,
        'sensitive' => false,
    ],
    'flat' => [], 'mini' => [], 'inverse' => [],

    'audio' => [
        'audioFilePrefix' => 'final'
    ]
];

配置文件中有7个键。`config_section_key`可能指向四个预构建的图像表示部分之一,`standard`是默认的`config_section_key`值。您可以通过将其设置为`'flat', 'mini'或'inverse'`来覆盖此值。🔺您还可以通过将`'flat', 'mini'或'inverse'`指定为`tejascaptchaImageType`的后置值来覆盖图像选择。

🔺请参考在`$('#tejas_captcha_refresh_icon')`点击函数中的`tejas/tejascaptcha/example/js/tejascaptcha.js`文件。

`audio`键指定音频文件名称的前缀。

仅示例用法

链接