From 5cb2fa8058a03c072f8a0400d6582a39a8593e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Fri, 17 Mar 2017 14:59:24 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E6=9D=83=E9=99=90=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=88=B7=E6=96=B0=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Index.php | 2 ++ application/admin/controller/Login.php | 6 ++---- application/admin/model/Node.php | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index 10370558f..e23e4b1fe 100644 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -14,6 +14,7 @@ namespace app\admin\controller; +use app\admin\model\Node; use controller\BasicAdmin; use library\Data; use library\Tools; @@ -34,6 +35,7 @@ class Index extends BasicAdmin { * @return View */ public function index() { + Node::applyAuthNode(); $list = Db::name('SystemMenu')->field('title,id,pid,url,icon')->order('sort asc,id asc')->where('status', '1')->select(); $menus = $this->_filter_menu(Tools::arr2tree($list)); $this->assign('title', '后台管理'); diff --git a/application/admin/controller/Login.php b/application/admin/controller/Login.php index 293896137..70a716352 100644 --- a/application/admin/controller/Login.php +++ b/application/admin/controller/Login.php @@ -14,6 +14,7 @@ namespace app\admin\controller; +use app\admin\model\Node; use controller\BasicAdmin; use think\Db; @@ -51,12 +52,9 @@ class Login extends BasicAdmin { $user = Db::name('SystemUser')->where('username', $username)->find(); empty($user) && $this->error('登录账号不存在,请重新输入!'); ($user['password'] !== md5($password)) && $this->error('登录密码与账号不匹配,请重新输入!'); - if (!empty($user['authorize'])) { - $authorizeids = explode(',', $user['authorize']); - $user['nodes'] = Db::name('SystemAuthNode')->where('auth', 'in', $authorizeids)->column('node'); - } Db::name('SystemUser')->where('id', $user['id'])->update(['login_at' => ['exp', 'now()'], 'login_num' => ['exp', 'login_num+1']]); session('user', $user); + !empty($user['authorize']) && Node::applyAuthNode(); $this->success('登录成功,正在进入系统...', '@admin'); } } diff --git a/application/admin/model/Node.php b/application/admin/model/Node.php index 56bfc7370..c07960e47 100644 --- a/application/admin/model/Node.php +++ b/application/admin/model/Node.php @@ -17,7 +17,7 @@ namespace app\admin\model; use think\Db; /** - * 系统用户管理控制器 + * 系统权限节点读取器 * Class Node * @package app\admin\model * @author Anyon @@ -25,6 +25,19 @@ use think\Db; */ class Node { + /** + * 应用用户权限节点 + * @param type $authid + * @return bool + */ + public static function applyAuthNode() { + if (($authorize = session('user.authorize'))) { + $nodes = (array) Db::name('SystemAuthNode')->where('auth', 'in', explode(',', $authorize))->column('node'); + return session('user.nodes', $nodes); + } + return false; + } + /** * 获取系统代码节点 * @return array