colbeh / auth
laravel 包用于 Auth 系统
1.0.12
2021-06-26 15:26 UTC
README
1- 使用 Composer 安装 colbeh/auth
2- 添加配置文件
php artisan vendor:publish --provider="Colbeh\Auth\ServiceProvider" --tag=config
3- 前往 config/auth_colbeh 并进行修改
升级
composer require colbeh/auth:x.x.x
指南
提供者
可以为不同的登录和注册方法设置多个提供者。每个提供者包含
"providers"=>[
...
"user"=>[
"model"=>\App\Models\User::class,
"type"=>"otp", // "otp" or "password"
"need_validation"=>"1", // 0 or 1 - determines that send sms or email for COL_PHONE_NUMBER_OR_EMAIL column
],
...
],
并调用它
$auth=new AuthController('user')
注意:默认提供者使用 'user',无需确定
验证
您可以通过电子邮件或电话验证用户。1- 在 auth_colbeh 中引入您的短信发送类作为 SMSSenderClass,注意 SMSSenderClass 类应从 SmsSenderInterface 接口扩展
2- 在 auth_colbeh 中引入您的电子邮件发送类作为 EmailSenderClass,注意 EmailSenderClass 类应从 EmailSenderInterface 接口扩展
注意:此包仅发送电子邮件或短信,并不验证两者
用法
初始化
$auth=new AuthController()
登录
使用用户名和密码登录
$auth->login($username, $password)
注册
使用用户名和密码注册
$auth->signUp($username, $password, $phoneOrEmail)
验证
为用户发送验证电子邮件或短信
$auth->validate($username, $code)
重新发送验证码
重新发送验证码
$auth->resendCode($username)
忘记密码
此方法发送用于密码恢复的电子邮件或短信
$auth->forgetPass($username)
密码恢复
此方法用于获取用户代码后恢复(更改)密码。用户可以设置新的密码
$auth->recoveryPass($username,$code,$newPass)
如果用户未设置密码,系统将创建新的密码
$newPass=$auth->recoveryPass($username,$code)
登录或注册
使用电话号码或电子邮件登录或注册用户。在此方法中,系统将发送验证码,您应使用验证方法验证用户
$auth->loginOrSignUp($phonenumberOrEmail)