From 401ce4724ee7fe7a8c996f4c6e86bf66bd9b4d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=B4=E6=8E=8C?= Date: Wed, 10 Oct 2018 17:01:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9D=83=E9=99=90=E5=92=8C?= =?UTF-8?q?=E6=9D=83=E9=99=90=E8=A1=A8=E6=A0=BC=E7=9A=84=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/controller/Base.php | 31 ++++++++++++- application/index/controller/Index.php | 9 +++- composer.json | 3 +- composer.lock | 45 ++++++++++++++++++- config/auth/app.php | 13 ++++++ .../migrations/20181010035225_system_base.php | 13 +++--- .../migrations/20181010075304_auth_group.php | 42 +++++++++++++++++ .../20181010075517_auth_group_access.php | 41 +++++++++++++++++ .../migrations/20181010075553_auth_rule.php | 45 +++++++++++++++++++ 9 files changed, 231 insertions(+), 11 deletions(-) create mode 100644 config/auth/app.php create mode 100644 database/migrations/20181010075304_auth_group.php create mode 100644 database/migrations/20181010075517_auth_group_access.php create mode 100644 database/migrations/20181010075553_auth_rule.php diff --git a/application/common/controller/Base.php b/application/common/controller/Base.php index d08c6a82..b95ba892 100644 --- a/application/common/controller/Base.php +++ b/application/common/controller/Base.php @@ -2,13 +2,40 @@ namespace app\common\controller; +// 引用控制器类 use think\Controller; +// 引用权限验证类 +use think\auth\Auth; +// 引用软删除类 +use think\model\concern\SoftDelete; + + class Base extends Controller { - //初始化 + // 开启全局自动时间戳 + protected $autoWriteTimestamp = true; + + // 开启软删除 + use SoftDelete; + protected $deleteTime = 'delete_time'; + + // 当前类初始化 protected function initialize() { - + $this->quanxianyanzheng(); + } + + protected function quanxianyanzheng() + { + // 实例化权限验证Auth类 + $auth = new Auth(); + + // 检测权限 + // if($auth->check('show_button',1)){// 第一个参数是规则名称,第二个参数是用户UID + // //有显示操作按钮的权限 + // }else{ + // //没有显示操作按钮的权限 + // } } } diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index 57323b89..75f29cf6 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -6,8 +6,13 @@ use app\common\controller\Base; // 引用与此控制器同名的数据模型 use app\system\model\SystemBase as sysbasemod; +use think\auth\Auth; + class Index extends Base { + //关闭自动时间 + protected $autoWriteTimestamp = false; + // 主页 public function index() { @@ -52,10 +57,10 @@ class Index extends Base // 模版赋值 $this->assign('list',$list); - // $url = url('welcome'); - // halt($url); // 渲染输出 return $this->fetch(); } + + } diff --git a/composer.json b/composer.json index b9646184..1c0d1348 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "require": { "php": ">=5.6.0", "topthink/framework": "5.1.*", - "topthink/think-migration": "^2.0" + "topthink/think-migration": "^2.0", + "5ini99/think-auth": "^1.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 1b49a1f0..3173eead 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,51 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b3374c528fb4105b6d3f53e5e315910c", + "content-hash": "dfaa67043ae3567809e303948dbcdfb6", "packages": [ + { + "name": "5ini99/think-auth", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/5ini99/think-auth.git", + "reference": "f9f20d18b5e400d67312a7ca75e4dc35be630a4c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/5ini99/think-auth/zipball/f9f20d18b5e400d67312a7ca75e4dc35be630a4c", + "reference": "f9f20d18b5e400d67312a7ca75e4dc35be630a4c", + "shasum": "", + "mirrors": [ + { + "url": "https://dl.laravel-china.org/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "think\\auth\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "xiaobo.sun", + "email": "xiaobo.sun@qq.com" + } + ], + "description": "auth package for thinkphp5", + "homepage": "https://github.com/5ini99/think-auth", + "time": "2016-11-02T06:26:09+00:00" + }, { "name": "topthink/framework", "version": "v5.1.25", diff --git a/config/auth/app.php b/config/auth/app.php new file mode 100644 index 00000000..b58470cf --- /dev/null +++ b/config/auth/app.php @@ -0,0 +1,13 @@ + [ + 'auth_on' => 1, // 权限开关 + 'auth_type' => 1, // 认证方式,1为实时认证;2为登录认证。 + 'auth_group' => 'auth_group', // 用户组数据不带前缀表名 + 'auth_group_access' => 'auth_group_access', // 用户-用户组关系不带前缀表 + 'auth_rule' => 'auth_rule', // 权限规则不带前缀表 + 'auth_user' => 'member', // 用户信息不带前缀表 + ], +]; \ No newline at end of file diff --git a/database/migrations/20181010035225_system_base.php b/database/migrations/20181010035225_system_base.php index 9d5147c1..50903c07 100644 --- a/database/migrations/20181010035225_system_base.php +++ b/database/migrations/20181010035225_system_base.php @@ -32,11 +32,14 @@ class SystemBase extends Migrator $table = $this->table('system_base'); // 给当前表添加字段 - $table->addColumn('title','string',['limit'=>50,'default'=>'学生成绩统计系统','null'=>'false','comment'=>'网站名称']) - ->addColumn('keywords','string',['limit'=>100,'default'=>'成绩统计,成绩管理','null'=>'false','comment'=>'关键词']) - ->addColumn('description','string',['limit'=>100,'default'=>'这是我们自己开发的系统','null'=>'false','comment'=>'网站说明']) - ->addColumn('copyright','string',['limit'=>15,'default'=>'2018-'.date('Y'),'null'=>'false','comment'=>'版权']) - ->addColumn('thinks','string',['limit'=>200,'default'=>'H-ui前端框架、ThinkPhp框架','null'=>'false','comment'=>'网站感谢']) + $table + ->addColumn('create_time','integer',['limit'=>11,'default'=>'1539158918','null'=>'','comment'=>'创建时间']) + ->addColumn('update_time','integer',['limit'=>11,'default'=>'1539158918','null'=>'false','comment'=>'更新时间']) + ->addColumn('title','string',['limit'=>50,'default'=>'学生成绩统计系统','null'=>'true','comment'=>'网站名称']) + ->addColumn('keywords','string',['limit'=>100,'default'=>'成绩统计,成绩管理','null'=>'true','comment'=>'关键词']) + ->addColumn('description','string',['limit'=>100,'default'=>'这是我们自己开发的系统','null'=>'true','comment'=>'网站说明']) + ->addColumn('copyright','string',['limit'=>15,'default'=>'2018-'.date('Y'),'null'=>'true','comment'=>'版权']) + ->addColumn('thinks','string',['limit'=>200,'default'=>'H-ui前端框架、ThinkPhp框架','null'=>'true','comment'=>'网站感谢']) // ->addIndex(array('username'), array('unique' => true)) ->create(); } diff --git a/database/migrations/20181010075304_auth_group.php b/database/migrations/20181010075304_auth_group.php new file mode 100644 index 00000000..0d70cb5e --- /dev/null +++ b/database/migrations/20181010075304_auth_group.php @@ -0,0 +1,42 @@ +table('auth_rule_group'); + + // 添加当前表字段 + $table + ->addColumn('title','string',['limit'=>100,'default'=>'','null'=>true,'comment'=>'用户组中文名称']) + ->addColumn('rules','string',['limit'=>300,'default'=>'','null'=>true,'comment'=>'用户组拥有的规则id']) + ->addColumn('status','boolean',['default'=>true,'null'=>true,'comment'=>'用户组状态']) + ->addColumn('delete_time','integer',['limit'=>11,'null'=>false,'comment'=>'删除时间']) + ->create(); + } +} diff --git a/database/migrations/20181010075517_auth_group_access.php b/database/migrations/20181010075517_auth_group_access.php new file mode 100644 index 00000000..913e9264 --- /dev/null +++ b/database/migrations/20181010075517_auth_group_access.php @@ -0,0 +1,41 @@ +table('auth_group_access'); + + // 添加当前表字段 + $table + ->addColumn('uid','integer',['limit'=>11,'default'=>'','null'=>true,'comment'=>'用户id']) + ->addColumn('group_id','integer',['limit'=>11,'default'=>'','null'=>true,'comment'=>'用户组id']) + ->addColumn('delete_time','integer',['limit'=>11,'null'=>false,'comment'=>'删除时间']) + ->create(); + } +} diff --git a/database/migrations/20181010075553_auth_rule.php b/database/migrations/20181010075553_auth_rule.php new file mode 100644 index 00000000..c8368486 --- /dev/null +++ b/database/migrations/20181010075553_auth_rule.php @@ -0,0 +1,45 @@ +table('auth_rule'); + + // 添加当前表字段 + $table + ->addColumn('name','string',['limit'=>80,'default'=>'','null'=>true,'comment'=>'规则唯一标识']) + ->addColumn('title','string',['limit'=>80,'default'=>'','null'=>true,'comment'=>'规则中文名']) + ->addColumn('type','boolean',['default'=>false,'null'=>false,'comment'=>'是否是菜单']) + ->addColumn('status','boolean',['default'=>true,'null'=>true,'comment'=>'规则状态']) + ->addColumn('condition','string',['limit'=>100,'default'=>'','null'=>false,'comment'=>'规则表达式']) + ->addColumn('delete_time','integer',['limit'=>11,'default'=>'','null'=>false,'comment'=>'删除时间']) + ->addIndex(array('name'), array('unique' => true)) + ->create(); + } +}