cleaniquecoders/laravel-single-session

此包已被废弃且不再维护。未建议替代包。

仅允许单个用户在您的 Laravel 应用程序中登录。

v1.0.0 2018-11-30 04:23 UTC

This package is auto-updated.

Last update: 2023-12-03 07:06:09 UTC


README

Build Status Latest Stable Version Total Downloads License

关于您的包

此包允许一次只有一个用户登录。如果用户尝试从多个设备/浏览器登录,它将阻止用户从其他来源登录。

安装

  1. 为了在您的 Laravel 项目中安装 cleaniquecoders/laravel-single-session,只需在终端运行 composer require 命令
$ composer require cleaniquecoders/laravel-single-session
  1. 然后在您的 config/app.php 中将以下内容添加到 providers 数组中
CleaniqueCoders\LaravelSingleSession\LaravelSingleSessionServiceProvider::class,
  1. 在相同的 config/app.php 中将以下内容添加到 aliases 数组中
'LaravelSingleSession' => CleaniqueCoders\LaravelSingleSession\LaravelSingleSessionFacade::class,
  1. 发布资产和配置
$ php artisan vendor:publish --provider=CleaniqueCoders\LaravelSingleSession\LaravelSingleSessionServiceProvider
  1. 在您的 app/Exception/Handler.php 中的 render 方法上添加以下内容
use CleaniqueCoders\LaravelSingleSession\Exceptions\SingleSessionException;
...
public function render($request, Exception $exception)
{
	if ($exception instanceof SingleSessionException) {
	    return response()->view('single-session::errors.single-session', [], 401);
	}
...

用法

默认情况下,Laravel 单一登录是禁用的。您可以在 .env 中将其启用

SINGLE_SESSION_ENABLED=true

默认情况下,Laravel 单一登录使用登录表单中的 email 字段。您可以在 config/single-session.php 中的 credential 键中覆盖它。

测试

运行以下命令

$ vendor/bin/phpunit  --testdox --verbose

贡献

感谢您考虑为 cleaniquecoders/laravel-single-session 做出贡献!

错误报告

为了鼓励积极的协作,强烈建议提交拉取请求,而不仅仅是错误报告。“错误报告”也可以以包含失败测试的拉取请求的形式发送。

但是,如果您提交错误报告,您的问题应该包含标题和对问题的清晰描述。您还应该尽可能多地包含相关信息和一个演示问题的代码示例。错误报告的目标是让您自己和他人能够轻松地复制错误并开发修复方案。

请记住,错误报告是在希望有相同问题的其他人能够与您合作解决该问题的希望下创建的。不要期望错误报告会自动看到任何活动或其他人会立即修复它。创建错误报告是为了帮助您自己和他人开始解决问题的道路。

编码风格

cleaniquecoders/laravel-single-session 遵循 PSR-2 编码标准和 PSR-4 自动加载标准。

您可以使用 PHP CS Fixer 来保持标准。PHP CS Fixer 的配置可以在 .php_cs 中找到。

许可证

此包是开源软件,许可协议为MIT 许可证