watson / autologin
Laravel 的自动登录软件包
Requires
- php: >=5.5.0
- illuminate/contracts: 5.*
- illuminate/support: 5.*
- nesbot/carbon: 1.*
Requires (Dev)
- phpunit/phpunit: 4.5.*
This package is not auto-updated.
Last update: 2019-09-05 07:22:32 UTC
README
Autologin 是为 Laravel 4/5 定制的软件包,允许您生成将提供应用程序自动登录并重定向到相应位置的 URL。默认情况下,它支持 Laravel Auth 功能,但我希望将来也能扩展到其他(Sentry、Entrust)以及自定义支持。
安装
将以下内容添加到您的 composer.json 文件中,然后运行 composer update(这可能会根据您安装 Composer 的方式或位置而有所不同)。
composer require watson/autologin
现在,将 Autologin 服务提供者添加到您的 app/config/app.php 文件中。
Watson\Autologin\AutologinServiceProvider::class
如果您想调整默认设置,可以发布配置文件。
php artisan vendor:publish --provider="Watson\Autologin\AutologinServiceProvider" --tag="config"
要获取迁移,请发布它们。
php artisan vendor:publish --provider="Watson\Autologin\AutologinServiceProvider" --tag="migrations"
当然,如果您想使用 Facade 而不是注入类本身,请将其添加到别名数组中。
'Autologin' => Watson\Autologin\Facades\Autologin::class
然后,将路由添加到您的 routes.php 文件中,命名为 autologin。如果您想命名为其他名称,请确保也在配置文件中更改。您可以使用提供的 AutologinController 或将路由指向您自己的控制器。
Route::get('autologin/{token}', ['as' => 'autologin', 'uses' => '\Watson\Autologin\AutologinController@autologin']);
请注意,该软件包的早期版本会自动添加此路由。我删除了这一功能,以便您更好地控制应用程序中的路由中间件组,例如开始会话等。
生成自动登录链接
为用户生成自动登录链接
// User class implements UserInterface
$user = User::find(1);
// http://example.com/autologin/Mx7B1fsUin
$link = Autologin::user($user);
为具有路径的用户生成自动登录链接
// User class implements UserInterface
$user = User::find(1);
// http://example.com/autologin/RvcNoAcH0X
$link = Autologin::to($user, '/profile');
为具有路由的用户生成自动登录链接
// User class implements UserInterface
$user = User::find(1);
// http://example.com/autologin/3eQOsRnvPE
$link = Autologin::route($user, 'posts.index');
验证令牌
如果您查看 Watson\Autologin\AutologinController,您将了解该软件包如何验证令牌、登录并将用户重定向。如果您想使用不同的方法,请将控制器复制到您的应用程序中,替换掉您想更改的部分,然后在 Autologin 配置文件中设置控制器。
身份验证
默认情况下,Autologin 与 Laravel 的 Auth 库一起工作。您可以通过发布配置文件切换到内置的 Sentry 提供者。实现自己的提供者非常简单:将其替换并实现 Watson\Autologin\Interfaces\AuthenticationInterface。如果您想支持其他身份验证库,请随时提交 PR。