larakeeps/authguard-otp 问题修复 & 功能扩展

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

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

larakeeps/authguard-otp

Composer 安装命令:

composer require larakeeps/authguard-otp

包简介

AuthGuard OTP is a package intended for random code generation, validation and confirmation (OTP).

README 文档

README

AuthGuard OTP

AuthGuard OTP is a package intended for random code generation, validation and confirmation (OTP). Normally the OTP is used with a validator code or token that is sent by email or SMS to authenticate or authorize a certain action in the project.

This repository is only compatible with laravel: 7.* to 11.*

Installation

First Step, execute the command.

composer require larakeeps/authguard-otp

Second step, run the migration to create the tables: auth_guard_otp_codes

php artisan migrate

Third step, publish the authguard configuration, to publish the configurations run the command below:

php artisan vendor:publish --tag=authguard-otp-config 

Generating otp code

use Larakeeps\AuthGuard\Facades\OTP;

/** 
 * 
 * The create method has 3 parameters, 1 mandatory and 2 optional.
 * 
 * The $reference parameter is used with the assertive condition function in code validation.
 * The $email parameter is used in the same way as the $reference parameter
 * 
 * @param string $phone : required
 * @param string $email : optional
 * @param string $reference : optional
 * 
 * @method static OTP create(string $phone, string|null $email, string|null $reference)
 * 
 * */

$createOTP = OTP::create('phone number', 'email', 'reference');

// To retrieve the method return, call the following methods below.

/** 
 * 
 * The then method returns 2 parameters, $data of type AuthGuard, and $response of type Collection.
 * 
 * @method then(Closure $destination)
 * 
 * */
 
$createOTP->then(function (AuthGuard|null $data, Collection $response){
       
       /*
        * the $data parameter returns the null or Authguard model containing the table columns.
        */
       
       /*
        * The $response parameter returns a collection containing the following data: 
        * number_digits, code, message, status, user.access_token, user.ip_address
        */
        
        return $data->expires_at; // returns a value of type Carbon::class;
        
        if($response->status){
            return $response->message;
        }
       
});

// OR through the get() method that returns a Collection

return $createOTP->get();

// OR like this

return OTP::get();


// OR through the getResponse() method that returns a Collection

return $createOTP->getResponse();

// OR like this

return OTP::getResponse();


// OR can be called individually using methods

return OTP::getData()->expires_at; // returns a value of type Carbon::class;

if(OTP::getStatus()){
    return OTP::getMessage();
}

return OTP::getAccessToken();
return OTP::getIpAddress();

Checking for the existence of generated code and viewing the generated data.

use Larakeeps\AuthGuard\Facades\OTP;



/** 
 * 
 * Method to check if the generated code exists.
 * $phone parameter is used for better code verification assertiveness.
 * 
 * @method static bool hasCode(string $code, string|null $phone)
 * 
 * */

$hasCode = OTP::hasCode('154896');

if($hasCode){
    return "The code exist."
}


/** 
 * 
 * Method for finding and returning data.
 * $phone parameter is used for better code verification assertiveness.
 * 
 * @method static OTP getByCode(string $code, string|null $phone)
 * 
 * */

$authGuardFounded = OTP::getByCode('154896', '5521985642205');

if($authGuardFounded){
    return $authGuardFounded
}

Confirm whether the code entered is valid and whether it was actually confirmed.

use Larakeeps\AuthGuard\Facades\OTP;


/** 
 * 
 * The create method has 3 parameters, 2 mandatory and 1 optional.
 * 
 * The $reference parameter is used with the assertive condition function in code validation.
 * 
 * @param string $code : required
 * @param string $phone : required
 * @param string $reference : optional
 * 
 * @method static OTP confirm(string $code, string $phone, string|null $reference)
 * 
 * */
 
$validateCode = OTP::confirm('154896', '5521985642205'); 

// To retrieve the method return, call the following methods below.

/** 
 * 
 * The then method returns 2 parameters, $data of type AuthGuard, and $response of type Collection.
 * 
 * @method then(Closure $destination)
 * 
 * */
 
$validateCode->then(function (null $data, Collection $response){
       
       /*
        * 
        * Within the confirm() method, the $data parameter will always return a null value.
        * 
        * The $response parameter returns a collection containing the following data: 
        * number_digits, code, message, status, user.access_token, user.ip_address
        */
        
        if($response->status && OTP::isConfirmed()){
            return $response->message;
        }
        
        return $response->message;
       
});

// OR through the getResponse() method that returns a Collection

return $createOTP->getResponse();

// OR like this

return OTP::getResponse();

// OR can be called individually using methods

if(OTP::getStatus()){
    return OTP::getMessage();
}

return OTP::getAccessToken();
return OTP::getIpAddress();

Deleting an OTP code.

use Larakeeps\AuthGuard\Facades\OTP;

/** 
 * 
 * @method OTP deleteCode(string $code)
 * 
 * */
 
$deletedCode = OTP::deleteCode();

// To retrieve the method return, call the following methods below.

/** 
 * 
 * The then method returns 2 parameters, $data of type AuthGuard, and $response of type Collection.
 * 
 * @method then(Closure $destination)
 * 
 * */
 
$validateCode->then(function (null $data, Collection $response){
       
       /*
        * 
        * Within the deleteCode() method, the $data parameter will always return a null value.
        * 
        * The $response parameter returns a collection containing the following data: 
        * number_digits, code, message, status, user.access_token, user.ip_address
        */
        
        if($response->status){
            return $response->message;
        }
       
});

// OR through the getResponse() method that returns a Collection

return $createOTP->getResponse();

// OR like this

return OTP::getResponse();

// OR can be called individually using methods

if(OTP::getStatus()){
    return OTP::getMessage();
}

return OTP::getAccessToken();
return OTP::getIpAddress();

Don't forget to follow me on github and star the project.


My contacts

E-mail: douglassantos2127@gmail.com

Linkedin: Acessa Perfil  

larakeeps/authguard-otp 适用场景与选型建议

larakeeps/authguard-otp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 70 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「security」 「sms」 「code」 「validation」 「acl」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 larakeeps/authguard-otp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 larakeeps/authguard-otp 我们能提供哪些服务?
定制开发 / 二次开发

基于 larakeeps/authguard-otp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-03