rhmdnj / laravel-impersonate
快速登录为其他用户
v2.0.6
2021-07-08 14:00 UTC
Requires
- php: ^7.4|^8.0
- laravel/framework: ^v7|^v8
Requires (Dev)
- orchestra/testbench: 6.17.
Conflicts
README
Lara Personate
是Laravel框架的用户 impersonate 功能。此包让具有超级管理员等访问权限的用户更容易接管其他用户账号。
安装
要安装此包,请按照以下步骤操作。
使用 Composer 安装包
$ composer require octopyid/laravel-impersonate:^2
$ artisan vendor:publish --provider="Octopy\LaraPersonate\ImpersonateServiceProvider"
有时一些用户在升级包后可能会遇到布局问题,这可以通过删除
public/vendor/octopyid/impersonate
文件夹然后重新发布资源来解决。
将特性 Octopy\LaraPersonate\Models\Impersonate
添加到您的 User 模型中。
<?php namespace App\Models; use Octopy\LaraPersonate\Models\Impersonate; use Illuminate\Foundation\Auth\User as Authenticatable; /** * Class User * @package App\Models */ class User extends Authenticatable { use Impersonate; }
用法
默认情况下,用户可以 impersonate,但这也可能导致安全问题。
定义授权
要限制可以 impersonate 的用户,请将 canImpersonate()
添加到 User 模型中。
/** * @return bool */ public function canImpersonate() : bool { // example return $this->is_admin === 1; }
要限制哪些用户可以被其他用户 impersonated,例如,超级管理员权限不能被其他用户 impersonated,请将 canBeImpersonated()
添加到 User 模型中。
/** * @return bool */ public function canBeImpersonated() : bool { // example return $this->can_be_impersonated === 1; }
免责声明
如果使用不当,此包可能引起严重的安全问题,因为任何人都可以接管任何用户的账号。
使用此包表示您同意,Octopy ID 和此包的贡献者不对使用此包造成的任何损害承担责任。
安全性
如果您发现任何与安全相关的问题,请通过电子邮件 supianidz@gmail.com 或 me@octopy.id 反馈,而不是使用问题追踪器。
鸣谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。