rikless / laravel-caffeine
保持您的Laravel表单处于活跃状态
此包的官方仓库似乎已消失,因此该包已被冻结。
Requires
- php: >=5.6.0
- illuminate/routing: 5.1.* || 5.3.*
- illuminate/support: 5.1.* || 5.3.*
README
目标
防止在屏幕上停留一段时间后提交表单时表单超时。(Laravel默认为120分钟,但这是可配置的,并且可能因网站而异。)
实现
为了实现这一点,我们定期发送咖啡因滴(请求)以防止会话超时。这仅在包含_token
字段的页面上实现,因此所有其他页面将正常超时。
理由
我选择这种方法来保持网站安全性的完整性,通过避免以下情况
- 在未加密的端点上暴露CSRF令牌。
- 在特定路由上消除CSRF令牌验证,甚至完全消除。
- 在所有页面上删除会话超时。
注意事项
路由
此包在genealabs/laravel-caffeine
下添加路由。请确认这些路由与您现有的路由不冲突。
依赖项
- 您的项目必须运行Laravel 5.1(LTS)或5.3(当前)。
- PHP 7.0.0或更高版本。
安装
-
Laravel LTS(5.1)或当前(5.3)的安装
composer require genealabs/laravel-caffeine
对于Laravel 5.2,请按照以下说明进行操作:https://github.com/GeneaLabs/laravel-caffeine/tree/166e2ca08af7cc62a59360f33e03d1cb8478df6a
-
在
config\app.php
中添加服务提供者条目GeneaLabs\LaravelCaffeine\Providers\LaravelCaffeineService::class,
-
您现在无需手动注册中间件。如果您之前已经这样做,请从
/app/Http/Kernel.php
中删除以下中间件
// protected $middleware = [ \GeneaLabs\LaravelCaffeine\Http\Middleware\LaravelCaffeineDripMiddleware::class, // ];;
## Configuration
The following elements are configurable:
- **domain:** (default: `url('/')`) Change to point to a different domain than
your app. This is useful if you are behind a proxy or load-balancer. ___Do not use
the `url()` helper in the config file.___
- **route:** (default: `genealabs/laravel-caffeine/drip`) Change to customize
the drip URL in the browser. This is just cosmetic.
- **dripIntervalInMilliSeconds:** (default: 5 mins) Change to configure the drip
interval.
___Only publish the config file it you need to customize it___:
```sh
php artisan vendor:publish --tag=genealabs-laravel-caffeine
您现在可以根据需要更改/app/config/genealabs-laravel-caffeine.php
中的默认值。删除/app/config/genealabs-laravel-caffeine.php
文件将恢复到默认设置。
用法
就是这样!它将自动应用于找到带有_token
字段的表单或名为"csrf-token"的元标签,同时浏览器中打开的页面处于打开状态。