[更新]权限节点刷新机制

This commit is contained in:
邹景立 2017-03-17 14:59:24 +08:00
parent 5a41a72611
commit 5cb2fa8058
3 changed files with 18 additions and 5 deletions

View File

@ -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', '后台管理');

View File

@ -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');
}
}

View File

@ -17,7 +17,7 @@ namespace app\admin\model;
use think\Db;
/**
* 系统用户管理控制
* 系统权限节点读取
* Class Node
* @package app\admin\model
* @author Anyon <zoujingli@qq.com>
@ -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