rpsimao/lockscreen

在 Laravel 中添加锁屏功能

1.0.2 2019-10-02 09:09 UTC

This package is auto-updated.

Last update: 2024-09-29 05:22:09 UTC


README

Donate Latest Stable Version Total Downloads License

rangoo/lockscreen 是 Laravel 的 Laravel 包,在 Packagist

入门指南

以下说明将帮助您在本地机器上安装并运行项目副本,以便进行开发和测试。有关如何将项目部署到生产系统的说明,请参阅部署部分。

安装

composer require rangoo/lockscreen

帮助

锁屏中间件 auth.lockedauth.unlocked 扩展到 auth 中间件

auth.lock 中间件意味着用户必须被 锁定

auth.unlocked 中间件意味着用户必须被 解锁

两者都意味着用户必须 登录

示例

Rangoo\Lockscreen\Traits\LockscreenMethods

// Controller

use Illuminate\Routing\Controller;
use Rangoo\Lockscreen\Traits\LockscreenMethods;

class LockscreenController extends Controller {
	use LockscreenMethods;
}
// Routes

// Init routes for lockscreen methods
Route::get('/lockscreen', 'LockscreenController@lockscreen')->middleware('auth.locked');
Route::post('/lockscreen', 'LockscreenController@lock')->middleware('auth.unlocked');
Route::delete('/lockscreen', 'LockscreenController@unlock')->middleware('auth.locked');

// If any guard: 'auth.unlocked:guard1,guard2,guard3'
Route::middleware('auth.unlocked')->group(function(){
  // Routes goes here
  // Where must be logged in and unlocked
});

auth.lock blade

<form action="{{ url('/lockscreen') }}" method="post">
   {{ csrf_field() }}
   <h3>{{ auth()->user()->name }}, are you here?</h3>
   <input type="password" name="password"/>
   <input type="submit" value="Unlock" />
</form>

layout blade

<html>
  <head>
    <script>
      window.Lockscreen = {
        locked: {{ session()->get('lockscreen', false) }},
        route: '{{ url('/lockscreen') }}',
      };
    </script>
  </head>
  <body>
    
    <!-- include javascript -->
  </body>
</html>

webpack

在这个例子中使用了以下包: SensorAFKaxios

const SensorAFK = require('sensor-afk');
const axios = require('axios');

if(!window.Lockscreen.locked){
  new SensorAFK({
    callback: () => {
      axios.post(window.Lockscreen.route)
        .then(() => {
          location.reload();
        })
        .catch(() => {
          alert('something went wrong');
        });
    }
  });
}

版本控制

我们使用 SemVer 进行版本控制。有关可用的版本,请参阅此存储库上的 标签

作者

还可以查看参与此项目的 贡献者列表

许可证

本项目采用 MIT 许可证 - 详细信息请参阅 LICENSE 文件