sanjabteam/verify
最新稳定版本:v5.0.0
Composer 安装命令:
composer require sanjabteam/verify
包简介
Verify users mobile number by one time password.
关键字:
README 文档
README
Verify your user mobile/email with a one-time password.
Installation
You can install the package via composer:
composer require sanjabteam/verify
Publish config file using:
php artisan vendor:publish --provider=SanjabVerify\VerifyServiceProvider
Configuration
code: Unique code generator configs.
resend_delay : Resend delay between code sends in seconds.
expire_in: Expire sent code after minutes.
max_attemps: Max code check attempts.
max_resends: Maximum resends in one hour.
per_session: Maximum resends in one hour based on the user session. (Limitation: if user clear cookie)per_ip: Maximum resends in one hour based on user IP. (Limitation: If two different user use one proxy)
Usage
Send code to the user
use Verify; use App\Helpers\SmsVerifyMethod; $result = Verify::request($request->input('mobile'), SmsVerifyMethod::class); if ($result['success'] == false) { // If user exceed limitation return redirect()->back()->with('error', $result['message']); // Show error message }
App\Helpers\SmsVerifyMethod is your send method class and you need to create that like this.
namespace App\Helpers; use SanjabVerify\Contracts\VerifyMethod; class SmsVerifyMethod implements VerifyMethod { public function send(string $receiver, string $code) { // Send code to receiver if (send_sms($receiver, 'Your code is :'.$code) == 'success') { return true; // If code sent successfuly then return true } return false; // If send code failed return false } }
Verify
You can verify code with request validation.
$request->validate([ 'code' => 'required|sanjab_verify:mobile' ]);
mobileis your receiver which in this case is mobile.
You can also verify it manually.
use Verify; $result = Verify::verify($request->input('mobile'), $request->input('code')); if ($result['success'] == false) { // Show error $result['message'] }
Note: You can verify a code just once. so if you need to check code in two different requests then you should use something like the session to handle that.
Contributing
Contributions are welcome!
- Fork the Project
- Clone your project (git clone https://github.com/your_username/verify.git)
- Create new branch (git checkout -b your_feature)
- Commit your Changes (git commit -m 'new feature')
- Push to the Branch (git push origin your_feature)
- Open a Pull Request
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 4.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-24