petnetwebapps / user-authentication
宠物网应用的自定义身份验证
2.9
2019-12-03 02:03 UTC
Requires
- laravel/passport: ^7.5
- predis/predis: ^1.1.1
- spatie/laravel-webhook-client: ^2.2
This package is not auto-updated.
Last update: 2024-09-18 02:13:48 UTC
README
- Laravel 5.8
- PHP 7.2
说明
$ composer require petnetwebapps/user-authentication
在 config/app.php 中添加提供者
'providers' => [
Petnet\Auth\PetnetServiceProvider::class
在以下位置发布配置文件
php artisan vendor:publish --provider="Petnet\Auth\PetnetServiceProvider"
在 database/migrations 目录下删除您的用户迁移
然后运行以下命令
$ php artisan migrate
$ php artisan passport:install
在您的 app/Http/Middleware/VerifyCsrfToken.php 中,通过输入以下内容来排除 webhook 路由
protected $except = [
'webhooks/*'
];
在 routes/web.php 中注册这些路由
Route::webhooks('/webhooks/user', '/webhooks/user');
Route::webhooks('/webhooks/update-user', '/webhooks/update-user');
Route::webhooks('/webhooks/delete-user', '/webhooks/delete-user');
然后在 app/User.php 中添加 Petnet\Auth\Concerns\CanVerifyUser.php
修改 app/User.php
<?php
namespace App;
use Petnet\Auth\Models\User as Authenticatable;
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
现在您可以通过钩子访问构建的身份验证路由
路由 | 方法 | 描述 |
---|---|---|
/api/login | POST | 登录用户 |
/api/logout | POST | 注销用户 |
/api/email/verify/{id}/{hash} | GET | 获取电子邮件和验证电子邮件令牌 |
/api/password/email | POST | 发送重置密码链接 |
/api/email/resend | POST | 重新发送电子邮件验证 |
/api/password/reset/{token} | GET | 返回忘记密码令牌 |
/api/password/reset | POST | 重置密码 |
/api/email/verify | GET | 检查账户是否已验证 |
您可以通过输入以下内容来通过工厂生成虚拟用户
$ php artisan tinker
>> factory(Petnet\Auth\Models\Role::class, 10)->create();
>> factory(Petnet\Auth\Models\User::class, 10)->create();
您还可以通过 config/user-auth.php 修改登录的默认用户名
'username' => 'employee_id',