viezel / otp
为 Laravel 的一次性密码
1.0.0
2020-10-23 13:44 UTC
Requires
- php: ^7.4
- illuminate/contracts: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3
- vimeo/psalm: ^3.11
This package is auto-updated.
Last update: 2024-08-29 05:43:32 UTC
README
此包在用户访问您的 Laravel 应用中的路由时,会通过电子邮件发送一个 6 位验证码。默认情况下,用户身份验证的有效期为 30 分钟。
安装
- 通过 composer 安装包
composer require viezel/otp php artisan vendor:publish --provider="Viezel\OTP\OTPServiceProvider" --tag="migrations" php artisan migrate
- 将中间件
check_otp
添加到需要验证用户身份的路由中。
Route::get('some/protected/route', MyController::class)->middleware(['auth', 'check_otp']); Route::get('other/route', MyOtherController::class)->middleware(['auth', 'check_otp']);
配置
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Viezel\OTP\OTPServiceProvider" --tag="otp-config"
return [ /* * How long time in minutes should the verification code be valid for */ 'link_expires_in_minutes' => 300, /* * How long time in minutes should the user be verified for the certain route */ 'validation_expires_after_minutes' => 30, /* * Should be use the queue to sent out the verification email */ 'use_queue' => false, /* * Route Prefix */ 'route_prefix' => '', /* * Route Middleware */ 'route_middleware' => ['web', 'auth'], ];
自定义
您可以根据需要构建自己的验证视图。只需发布视图并更改所需的内容。
该包提供了一个可重用的 blade 组件。它基于 Alpine.js 和 Tailwind CSS。
<x-otp::pincode url="{{ $url }}"></x-otp::pincode>
测试
composer test
致谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。