codulab / restricted
当用户的输入(例如:用户名)与限制词列表匹配时,限制注册
v1.0.4
2018-02-11 15:24 UTC
Requires
- php: ~5.6|~7.0
This package is not auto-updated.
Last update: 2024-09-14 20:55:57 UTC
README
Restricted 允许您限制用户使用保留词进行注册。
保留词可以是
- 您的路由段 - 示例,您有这个路由: www.mywebsite.com/login 并且您的应用程序允许像这样查看用户资料:www.mywebsite.com/username 此软件包可以爬取所有您的路由,并在用户尝试使用如 "login" 这样的词注册时返回验证消息
- 您想要保留的词 - 示例:购物车、产品、管理员等。这些词可以手动添加到 reserved.txt 文件中。在运行 "restricted:index" 命令后。
安装
要安装Restricted,请使用composer
下载
composer require codulab/restricted
添加服务提供者
将以下服务提供者添加到 config/app.php
中的数组中:
Codulab\Restricted\RestrictedServiceProvider::class,
发布配置
php artisan vendor:publish --tag=restricted_config
用法
首先,我们需要通过运行命令爬取和索引应用程序路由
php artisan restricted:index
现在,您可以将 restricted 添加到验证中,如下所示
$this->validate($request, [ 'name' => 'required|string|min:5', 'username' => 'required|restricted' ]);
您还可以添加新的验证消息
$this->validate($request, [ 'name' => 'required|string|min:5', 'username' => 'required|restricted' ],[ 'username.restricted' => 'A user exists with that username. Please try another or add more characters' ]);
设置
- file_path: (string) 保存索引词的文件名和路径
- index_level: (int) 您希望我们爬取您的路由多深?示例 => www.mywebsite.com/segment1/segmen2/segment3。将此值设置为 '2',将允许索引 segment1 和 segment2,并排除 segment3
- merge: (bool) 是否应将新结果与旧结果合并
许可证
MIT许可证 - 免费使用和滥用!