itsmeabde/easy-otp 问题修复 & 功能扩展

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

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

itsmeabde/easy-otp

Composer 安装命令:

composer require itsmeabde/easy-otp

包简介

Easy OTP (Onetime Password) for Laravel 7|8

关键字:

README 文档

README

Easy OTP is laravel package for create simple onetime password system

Latest Version on Packagist Software License Total Downloads

Support Laravel Version 7|8

Install

Via composer

$ composer require itsmeabde/easy-otp

Finally, you will want to publish the config using the following command:

$ php artisan vendor:publish --tag=otp
$ php artisan migrate

Usage

use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Itsmeabde\EasyOtp\Exceptions\OtpException;
use Itsmeabde\EasyOtp\Otp;

class OtpController extends Controller
{
    public $otp;

    public function __construct(Otp $otp)
    {
        $this->otp = $otp;
    }

    public function create(Request $request): JsonResponse
    {
        $request->validate([
            'name' => 'required|string|min:3|max:100',
            'email' => 'required|email'
        ]);

        $identifier = sha1($request->input('email'));

        [$identifier, $pin, $expiresIn] = $this->otp->generate(
            $identifier,
            function ($identifier, $pin, $expiresIn) {
                // Send notification to users
            });

        return response()->json(
            compact('identifier', 'expiresIn')
        );
    }

    public function verify(Request $request): JsonResponse
    {
        $request->validate([
            'identifier' => 'required|string',
            'pin' => 'required|numeric'
        ]);

        try {
            $this->otp->validate(
                $request->input('identifier'),
                $request->input('pin'),
                function ($identifier) {
                    // Send notification to users
                });
        } catch (OtpException $e) {
            throw ValidationException::withMessages(
                $e->getMessageBag()
            );
        }

        return response()->json([
            'message' => 'Successfully verified.'
        ]);
    }

    public function resend(Request $request): JsonResponse
    {
        $request->validate(['identifier' => 'required|string']);

        try {
            [$identifier, $pin, $expiresIn] = $this->otp->generate(
                $request->input('identifier'),
                function ($identifier, $pin, $expiresIn) {
                    // Resend notification to users
                }, $requestExtraTime = true);
        } catch (OtpException $e) {
            throw ValidationException::withMessages(
                $e->getMessageBag()
            );
        }

        return response()->json([
            'message' => 'Successfully resend.',
        ]);
    }
}

License

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固