master
fengyuexingzi 8 years ago
parent 5db80290d4
commit 0e67cd22ef

@ -0,0 +1,31 @@
<?php
/**
* Created by PhpStorm.
* User: Wind
* Date: 2017/11/25
* Time: 13:33
*/
namespace app\admin\controller;
use think\Controller;
use tp5auth\Auth as TAuth;
class Auth extends Controller
{
public function _empty($name)
{
$auth = new TAuth();
$auth = $auth->autoload($name);
if($auth){
if(isset($auth['code'])){
return json($auth);
}elseif(isset($auth['file'])){
return $auth['file'];
}
$this->view->engine->layout(false);
return $this->fetch($auth[0],$auth[1]);
}
return abort(404,'页面不存在');
}
}

@ -5,6 +5,21 @@ class Index
{ {
public function index() public function index()
{ {
return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_bd568ce7058a1091"></thinkad>'; }
public function _empty($name)
{
$auth = new \tp5auth\auth\Auth();
$auth = $auth->autoload($name);
if($auth){
if(isset($auth['code'])){
return json($auth);
}elseif(isset($auth['file'])){
return $auth['file'];
}
$this->view->engine->layout(false);
return $this->fetch($auth[0],$auth[1]);
}
//return abort(404,'页面不存在');
} }
} }

@ -27,9 +27,12 @@ return [
// 入口自动绑定模块 // 入口自动绑定模块
'auto_bind_module' => false, 'auto_bind_module' => false,
// 注册的根命名空间 // 注册的根命名空间
'root_namespace' => [], 'root_namespace' => [ ],
// 扩展函数文件 // 扩展函数文件
'extra_file_list' => [THINK_PATH . 'helper' . EXT], 'extra_file_list' => [
THINK_PATH . 'helper' . EXT,
EXTEND_PATH . "tp5auth/" . 'helper' . EXT,
],
// 默认输出类型 // 默认输出类型
'default_return_type' => 'htmlspecialchars', 'default_return_type' => 'htmlspecialchars',
// 默认AJAX 数据返回格式,可选json xml ... // 默认AJAX 数据返回格式,可选json xml ...

@ -15,7 +15,7 @@ return [
// 服务器地址 // 服务器地址
'hostname' => '127.0.0.1', 'hostname' => '127.0.0.1',
// 数据库名 // 数据库名
'database' => '', 'database' => 'think',
// 用户名 // 用户名
'username' => 'root', 'username' => 'root',
// 密码 // 密码
@ -29,7 +29,7 @@ return [
// 数据库编码默认采用utf8 // 数据库编码默认采用utf8
'charset' => 'utf8', 'charset' => 'utf8',
// 数据库表前缀 // 数据库表前缀
'prefix' => '', 'prefix' => 'tp_',
// 数据库调试模式 // 数据库调试模式
'debug' => true, 'debug' => true,
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)

@ -19,8 +19,7 @@
"php": ">=5.4.0", "php": ">=5.4.0",
"topthink/framework": "~5.0.0", "topthink/framework": "~5.0.0",
"workerman/workerman-for-win": "^3.5", "workerman/workerman-for-win": "^3.5",
"phpunit/phpunit":"5.7.23", "phpunit/phpunit":"5.7.23"
"tekintian/tp5auth":">=2.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

@ -0,0 +1,436 @@
<?php
// +----------------------------------------------------------------------
// | [ Only to facilitate the creation of it]
// +----------------------------------------------------------------------
// | Personal development
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: tekintian <tekintian@gmail.com>
// +----------------------------------------------------------------------
namespace tp5auth;
defined('VIEW_PATH') or define('VIEW_PATH', __DIR__ . DS . "view/");
use think\Cache;
use think\Config;
use think\Loader;
use think\Request;
use think\Session;
use tp5auth\controller\Rbac;
use tp5auth\model\ActionLog;
use tp5auth\model\AuthAccess;
use tp5auth\model\AuthRoleUser;
use tp5auth\model\Menu;
class Auth
{
const PATH = __DIR__;
public $log = true;
public $noNeedCheckRules = []; //不需要检查的路由规则
public function __construct()
{
$this->request = Request::instance();
$this->param = $this->request->param();
$this->module = $this->request->module();
$this->controller = $this->request->controller();
$this->action = $this->request->action();
}
/**
* 加载控制器方法
* @access public
* @param string $name 方法名
* @return mixed
*/
public function autoload($name)
{
$controller = new Rbac($this->request);
if (strtolower($this->controller) == 'auth' && method_exists($controller, $name)) {
return call_user_func([$controller, $name]);
}
return false;
}
/**
* 权限认证
* @access public
* @return mixed
*/
public function auth()
{
$uid = self::sessionGet('user.uid');
$controller = Loader::parseName($this->controller, 1); //字符串命名风格转换
$rule = strtolower("{$this->module}/{$controller}/{$this->action}");
//如果用户角色是1则无需判断
if (empty($uid)) {
return false;
}
if ($uid == 1) {
self::actionLog($rule);
return true;
}
//无需认证
$noNeedCheckRules = array_merge($this->noNeedCheckRules, [$this->module . '/auth/openfile', $this->module . '/auth/cache']);
if (!in_array($rule, $noNeedCheckRules)) {
return self::authCheck($rule, 'or');
} else {
return true;
}
}
/**
* 菜单权限检查
* @access public
* @return array
*/
public static function menuCheck()
{
$uid = self::sessionGet('user.uid');
if (empty($uid)) {
return false;
}
$where['status'] = 1;
if ($uid != 1) {
$authMenu = self::authMenu('', false);
if (array($authMenu)) { //授权菜单ID
$where['id'] = ['in', array_keys($authMenu)];
}
}
$menu = Menu::where($where)->order(["list_order" => "asc", 'id' => 'asc'])->column('*', 'id');
return $menu;
}
/**
* 行为日志检查
* @access public
* @param string $rule 日志规则
* @return array
*/
private function actionLog($rule)
{
//是否需要打开 行为日志检查
if ($this->log === false) {
return true;
}
$logMenu = Cache::get('logMenu');
if (empty($logMenu)) { //缓存日志24小时
$logMenu = Menu::actionLogMenu();
Cache::set('logMenu', $logMenu, 86400);
}
$menu = isset($logMenu[$rule]) ? $logMenu[$rule] : '';
$log = [];
if (empty($menu)) {
return true;
}
//子集行为日志菜单匹配
if (isset($menu['child'])) {
foreach ($menu['child'] as $v) {
if (!empty($v['rule_param'])) {
$condition = '';
$command = preg_replace('/\{(\w*?)\}/', '$this->param[\'\\1\']', $v['rule_param']);
@(eval('$condition=(' . $command . ');'));
if ($condition and $v['request'] == $this->request->method()) {
$log = $v;
}
}
}
}
//父集行为日志菜单匹配
if (empty($log)) {
if ($menu['request'] == $this->request->method()) {
$log = $menu;
}
}
if (!empty($log)) {
return self::createLog($log['log_rule'], $log['name']);
}
return true;
}
/**
* 创建行为日志
* @param string $logrule 行为日志规则
* @param string $title 标题
* @param int $uid 执行者ID
* @return array
*/
public function createLog($logrule, $title)
{
$uid = self::sessionGet('user.uid');
$param = $this->param;
$condition = '';
$command = preg_replace('/\{(\w*?)\}/', '{$param[\'\\1\']}', $logrule);
@(eval('$condition=("' . $command . '");'));
$data = [
'action_ip' => ip2long($this->request->ip()),
'username' => self::sessionGet('user.nickname'),
'create_time' => time(),
'log_url' => '/' . $this->request->pathinfo(),
'log' => $condition,
'user_id' => $uid,
'title' => $title
];
return ActionLog::create($data);
}
/**
* 检查路由权限
* @access public static
* @param string $path 路由
* @param array $param 参数
* @return bool
*/
public static function checkPath($path, $param = [])
{
$uid = self::sessionGet('user.uid');
if ($uid == 1) {
return true;
}
$authMenu = Cache::get('authMenu_' . $uid);
if (!$authMenu) { //存入缓存 授权菜单
$authMenu = self::authMenu();
Cache::set('authMenu_' . $uid, $authMenu, 600);
}
$count = count(explode('/', $path));
if ($count == 2) {
$module = Request::instance()->module();
$path = "$module/$path";
}
$path = strtolower($path);
//是否为超级管理员角色
if ($path === true) {
return true;
} else if ($path === false) {
return false;
}
if ($authMenu === false) {
return false;
}
//验证路由
foreach ($authMenu as $v) {
if ($v['name'] == $path) {
if (empty($v['rule_param'])) { //验证规则为空,表示所有通过
return true;
} else { //如有验证规则,根据规则验证
$condition = false;
$command = preg_replace('/\{(\w*?)\}/', '$param[\'\\1\']', $v['rule_param']);
@(eval('$condition=(' . $command . ');'));
if ($condition) {
return true;
}
}
}
}
return false;
}
/**
* 检查权限
* @access protected
* @param string $url 路由
* @param string $relation
* @return mixed
*/
protected function authCheck($url, $relation = 'or')
{
$rule = array($url);
$list = []; //保存验证通过的规则名)
$param = $this->param;
$rules = self::authMenu(["b.name" => ["in", $rule]]);
//是否为超级管理员角色
if ($rules === true) {
//行为日志
self::actionLog($url);
return true;
} else if ($rules === false) {
return false;
}
foreach ($rules as $rule) {
if (!empty($rule['rule_param'])) { //根据rule_param进行验证
$condition = false;
$command = preg_replace('/\{(\w*?)\}/', '$param[\'\\1\']', $rule['rule_param']);
@(eval('$condition=(' . $command . ');'));
if ($condition) {
$list[] = strtolower($rule['name']);
}
} else {
$list[] = strtolower($rule['name']);
}
}
if ($relation == 'or' and !empty($list)) {
//行为日志
self::actionLog($url);
return true;
}
$diff = array_diff($rule, $list);
if ($relation == 'and' and empty($diff)) {
return true;
}
return false;
}
/**
* 权限访问清单
* @access private
* @param array $where 查询附加条件
* @param bool $default 隐藏的菜单
* @return array
*/
private static function authMenu($where = [], $default = true)
{
$uid = self::sessionGet('user.uid');
$rule = [];
$roleId = AuthRoleUser::hasWhere('authRole', ['`AuthRoleUser`.`user_id`' => $uid, '`AuthRole`.`status`' => 1])
//->fetchSql(1)
->column('role_id');
//echo $roleId;die;
if (in_array(1, $roleId)) {
return true;
}
$roleId = implode(',', $roleId);
//角色权限 or 管理员权限
if ($default === true) {
$rule = AuthAccess::hasWhere('authRole')->where($where)
->where('(AuthAccess.type="admin_url" and AuthAccess.role_id in(:roleId))or(AuthAccess.type="admin" and AuthAccess.role_id =:uid)', ['roleId' => $roleId,
'uid' => $uid]);
} else if ($default === false) {
$rule = AuthAccess::where($where)
->where('(type="admin_url" and role_id in(:roleId))or(type="admin" and role_id =:uid)', ['roleId' => $roleId,
'uid' => $uid]);
}
$rule = $rule->column('*', 'menu_id');
if (empty($rule)) {
return false;
}
return $rule;
}
/**
* 检测用户是否登录
* @return mixed
*/
public static function is_login()
{
$user = self::sessionGet('user');
if (empty($user)) {
return false;
} else {
return self::sessionGet('user_sign') == self::data_auth_sign($user) ? $user : false;
}
}
/**
* 用户登入
* @access private static
* @param int $uid 用户ID
* @param string $nickname 用户昵称
* @return array
*/
public static function login($uid, $nickname)
{
if (empty($uid) && empty($nickname)) {
return false;
}
$session_prefix = Config::get('tp5auth.session_prefix');
$user = [
'uid' => $uid,
'nickname' => $nickname,
'time' => time()
];
Session::set($session_prefix . 'user', $user);
Session::set($session_prefix . 'user_sign', self::data_auth_sign($user));
return true;
}
/**
* 注销
* @access private static
* @return bool
*/
public static function logout()
{
$session_prefix = Config::get('tp5auth.session_prefix');
Session::delete($session_prefix . 'user');
Session::delete($session_prefix . 'user_sign');
return true;
}
/**
* 数据签名认证
* @access private static
* @param array $data 被认证的数据
* @return string 签名
*/
private static function data_auth_sign($data)
{
$code = http_build_query($data); //url编码并生成query字符串
$sign = sha1($code); //生成签名
return $sign;
}
/**
* 读取session
* @access private static
* @param string $path 被认证的数据
* @return mixed
*/
private static function sessionGet($path = '')
{
$session_prefix = Config::get('tp5auth.session_prefix');
$user = Session::get($session_prefix . $path);
return $user;
}
}

@ -0,0 +1,431 @@
# thinkphp5 权限认证 RBAC 加 行为日志
这个插件主要有一整套RBAC 行为日志 视图 只需要 composer安装即可和你的系统融为一体
## 安装
~~~
> composer require tekintian/tp5auth
~~~
## v1.1更新
* 1.加入了行为日志
* 2.加入样式文件路由定义,
## v1.1.1新加入方法
~~~
is_login() 判断是否登录
login($uid 用户ID,$nickname 用户昵称) 用户登录
logout() 用户退出
checkPath($path 路由,$param 参数) 检查路由是否有权限 ,可以做按钮权限判断( 已经加入助手函数可以直接使用)
注 更新废弃函数输入用户ID 和 用户昵称 ,加入 按钮的路由权限判断,
## 配置 v1.1
~~~
'tp5auth' =>[
'style_directory' => '/static/admin/',
'session_prefix' => 'abc_',
]
~~~
可以不配置 配置以后Js css文件需要放到配置的目录里
## 手动加入日志 v1.1
~~~
$auth = new Auth();
$auth->admin = $list['user_name'];
$auth->createLog('管理员<spen style=\'color: #1dd2af;\'>[ {name} ]</spen>偷偷的进入后台了,','后台登录');
~~~
## 视图调用
~~~
public function _empty($name)
{
$auth = new \tp5auth\auth\Auth();
$auth = $auth->autoload($name);
if($auth){
if(isset($auth['code'])){
return json($auth);
}elseif(isset($auth['file'])){
return $auth['file'];
}
$this->view->engine->layout(false);
return $this->fetch($auth[0],$auth[1]);
}
return abort(404,'页面不存在');
}
~~~
在模块中创建一个Auth控制器把_empty方法复制上去这样就可以访问以下视图
* /auth/role.html 角色列表
* /auth/roleAdd.html 角色添加
* /auth/roleEdit.html 角色修改
* /auth/authorize/id/2.html 权限设置
* /auth/menu.html 菜单列表
* /auth/menuAdd.html 菜单增加
* /auth/menuEdit.html 菜单修改
* /auth/log.html 行为日志 新v1.1
* /auth/viewLog.html 查看日志 新v1.1
* /auth/clear.html 清空日志 新v1.1
* /auth/adminAuthorize.html 独立权限 新v1.1.2
## 权限认证
~~~
public function __construct()
{
parent::__construct();
$auth = new Auth();
$auth->noNeedCheckRules = ['index/index/index','index/index/home'];
$auth->log = true; // v1.1版本 日志开关默认true
$user = $auth::is_login();
if($user){//用户登录状态
$this->uid = $user['uid'];
if(!$auth->auth()){
return $this->error("你没有权限访问!");
}
}else{
return $this->error("您还没有登录!",url("publics/login"));
}
}
~~~
这里在公共控制器上加入验证即可
##管理员独立权限
~~~
url('auth/adminAuthorize',['id' => '用户ID','name'=>'用户昵称'])
~~~
## 授权菜单
~~~
Auth::menuCheck();
~~~
这个方法返回授权及非隐藏的所有菜单,这样我们后台的菜单就可以根据管理员的权限来来展示授权的目录
代码案例
public function _empty($name)
{
$auth = new \tp5auth\auth\Auth();
$auth = $auth->autoload($name);
if($auth){
if(isset($auth['code'])){
return json($auth);
}elseif(isset($auth['file'])){
return $auth['file'];
}
$this->view->engine->layout(false);
return $this->fetch($auth[0],$auth[1]);
}
return abort(404,'页面不存在');
}
创建一个控制器把这个_empty方法加进去会渲染rbac视图这个我就不多讲了待会看图
## 手动加入日志
$auth = new Auth();
$auth->admin = $list['user_name'];
$auth->createLog('管理员<spen style=\'color: #1dd2af;\'>[ {name} ]</spen>偷偷的进入后台了,','后台登录');
路由目录
/auth/role.html 角色列表
/auth/roleAdd.html 角色添加
/auth/roleEdit.html 角色修改
/auth/authorize/id/2.html 权限设置
/auth/menu.html 菜单列表
/auth/menuAdd.html 菜单增加
/auth/menuEdit.html 菜单修改
/auth/log.html 行为日志 新v1.1
/auth/viewLog.html 查看日志 新v1.1
/auth/clear.html 清空日志 新v1.1
/auth/adminAuthorize.html 独立权限 新v1.1.2
public function __construct()
{
parent::__construct();
$auth = new Auth();
$auth->noNeedCheckRules = ['index/index/index','index/index/home'];
$auth->log = true; // v1.1版本 日志开关默认true
$user = $auth::is_login();
if($user){//用户登录状态
$this->uid = $user['uid'];
if(!$auth->auth()){
return $this->error("你没有权限访问!");
}
}else{
return $this->error("您还没有登录!",url("publics/login"));
}
}
这个是base控制器
$auth->noNeedCheckRules 为不需要权限认证的Url
$auth->auth 权限认证方法
到了这里你的权限rbac就搞定了
后台账户密码 admin admin
Auth::menuCheck();
复制代码
这个方法返回授权及非隐藏的所有菜单,这样我们后台的菜单就可以根据管理员的权限来来展示授权的目录
权限条件设置
假设我们需要index/extend/edit/id/875.html在这个rul上面设置权限只有角色能打开ID875 的应用编辑,那我们就可以在
[参数] id=875 这里是菜单上的URL使用
[验证规则] {id}==875 这里是权限认证条件判断 {id}<=1 && {id} >=1 || in_array({id},[1,2,4,5] )
## mysql文件
~~~
tp_action_log.sql
tp_auth_access.sql
tp_auth_role.sql
tp_auth_role_user.sql
tp_auth_rule.sql
tp_menu.sql
~~~
## 完整数据库脚本
/*
Navicat MySQL Data Transfer
Source Server : mysql-5.7_x64
Source Server Version : 50715
Source Host : localhost:3306
Source Database : tpauth
Target Server Type : MYSQL
Target Server Version : 50715
File Encoding : 65001
Date: 2017-01-18 22:41:00
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for tp_action_log
-- ----------------------------
DROP TABLE IF EXISTS `tp_action_log`;
CREATE TABLE `tp_action_log` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`user_id` int(10) NOT NULL DEFAULT '0' COMMENT '执行用户id',
`action_ip` bigint(20) NOT NULL COMMENT '执行行为者ip',
`log` longtext NOT NULL COMMENT '日志备注',
`log_url` varchar(255) NOT NULL COMMENT '执行的URL',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '执行行为的时间',
`username` varchar(255) NOT NULL COMMENT '执行者',
`title` varchar(255) NOT NULL COMMENT '标题',
PRIMARY KEY (`id`),
KEY `id` (`id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=124 DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='行为日志表';
-- ----------------------------
-- Records of tp_action_log
-- ----------------------------
INSERT INTO `tp_action_log` VALUES ('109', '1', '2130706433', '5', '/index/auth/menuedit.html', '1484745934', 'admin', '测试5');
INSERT INTO `tp_action_log` VALUES ('110', '27', '2130706433', '管理员<spen style=\'color: #1dd2af;\'>[ tekin ]</spen>偷偷的进入后台了,', '/index/publics/login.html', '1484746112', 'tekin', '后台登录');
INSERT INTO `tp_action_log` VALUES ('111', '1', '2130706433', '管理员<spen style=\'color: #1dd2af;\'>[ admin ]</spen>偷偷的进入后台了,', '/index/publics/login.html', '1484746195', 'admin', '后台登录');
INSERT INTO `tp_action_log` VALUES ('112', '27', '2130706433', '管理员<spen style=\'color: #1dd2af;\'>[ tekin ]</spen>偷偷的进入后台了,', '/index/publics/login.html', '1484746265', 'tekin', '后台登录');
INSERT INTO `tp_action_log` VALUES ('113', '1', '2130706433', '管理员<spen style=\'color: #1dd2af;\'>[ admin ]</spen>偷偷的进入后台了,', '/index/publics/login.html', '1484746296', 'admin', '后台登录');
INSERT INTO `tp_action_log` VALUES ('114', '27', '2130706433', '管理员<spen style=\'color: #1dd2af;\'>[ tekin ]</spen>偷偷的进入后台了,', '/index/publics/login.html', '1484746331', 'tekin', '后台登录');
INSERT INTO `tp_action_log` VALUES ('115', '27', '2130706433', '5', '/index/auth/menuedit.html', '1484746336', 'tekin', '测试5');
INSERT INTO `tp_action_log` VALUES ('116', '27', '2130706433', '5', '/index/auth/menuedit.html', '1484746340', 'tekin', '测试5');
INSERT INTO `tp_action_log` VALUES ('117', '27', '2130706433', '5', '/index/auth/menuedit.html', '1484746342', 'tekin', '测试5');
INSERT INTO `tp_action_log` VALUES ('118', '27', '2130706433', '5', '/index/auth/menuedit.html', '1484746344', 'tekin', '测试5');
INSERT INTO `tp_action_log` VALUES ('119', '27', '2130706433', '5', '/index/auth/menuedit.html', '1484746346', 'tekin', '测试5');
INSERT INTO `tp_action_log` VALUES ('120', '27', '2130706433', '5', '/index/auth/menuedit.html', '1484746351', 'tekin', '测试5');
INSERT INTO `tp_action_log` VALUES ('121', '27', '2130706433', '5', '/index/auth/menuedit.html', '1484746353', 'tekin', '测试5');
INSERT INTO `tp_action_log` VALUES ('122', '27', '2130706433', '5', '/index/auth/menuedit.html', '1484746354', 'tekin', '测试5');
INSERT INTO `tp_action_log` VALUES ('123', '1', '2130706433', '管理员<spen style=\'color: #1dd2af;\'>[ admin ]</spen>偷偷的进入后台了,', '/index/publics/login.html', '1484746396', 'admin', '后台登录');
-- ----------------------------
-- Table structure for tp_admin
-- ----------------------------
DROP TABLE IF EXISTS `tp_admin`;
CREATE TABLE `tp_admin` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '管理员自增ID',
`user_name` varchar(255) DEFAULT NULL COMMENT '用户名',
`user_password` varchar(255) DEFAULT NULL COMMENT '管理员的密码',
`user_nicename` varchar(255) DEFAULT NULL COMMENT '管理员的简称',
`user_status` int(11) DEFAULT '1' COMMENT '用户状态 0禁用 1正常 ',
`user_email` varchar(255) DEFAULT '' COMMENT '邮箱',
`last_login_ip` varchar(16) DEFAULT NULL COMMENT '最后登录ip',
`last_login_time` datetime DEFAULT NULL COMMENT '最后登录时间',
`create_time` datetime DEFAULT NULL COMMENT '注册时间',
`role` varchar(255) DEFAULT NULL COMMENT '角色ID',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=28 DEFAULT CHARSET=utf8 COMMENT='后台管理员表';
-- ----------------------------
-- Records of tp_admin
-- ----------------------------
INSERT INTO `tp_admin` VALUES ('1', 'admin', '21232f297a57a5a743894a0e4a801fc3', null, '1', 'admin@qq.com', '114.88.197.96', '2016-10-26 12:06:43', '2016-06-07 17:04:05', null);
INSERT INTO `tp_admin` VALUES ('16', 'zou', '21232f297a57a5a743894a0e4a801fc3', null, '1', 'zou1@qq.com', '127.0.0.1', '2016-07-17 17:01:36', '2016-07-08 15:29:41', '2');
INSERT INTO `tp_admin` VALUES ('23', 'sdasd', '0aa1ea9a5a04b78d4581dd6d17742627', null, '1', 'asdas@qq.com', null, null, '2016-11-15 16:55:36', '2,3');
INSERT INTO `tp_admin` VALUES ('27', 'tekin', '21232f297a57a5a743894a0e4a801fc3', null, '1', 'tekin@qq.com', null, null, '2017-01-18 21:14:40', '2');
-- ----------------------------
-- Table structure for tp_auth_access
-- ----------------------------
DROP TABLE IF EXISTS `tp_auth_access`;
CREATE TABLE `tp_auth_access` (
`role_id` mediumint(8) unsigned NOT NULL COMMENT '角色',
`rule_name` varchar(255) NOT NULL COMMENT '规则唯一英文标识,全小写',
`type` varchar(30) DEFAULT NULL COMMENT '权限规则分类,请加应用前缀,如admin_',
`menu_id` int(11) DEFAULT NULL COMMENT '后台菜单ID',
KEY `role_id` (`role_id`),
KEY `rule_name` (`rule_name`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='权限授权表';
-- ----------------------------
-- Records of tp_auth_access
-- ----------------------------
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/default', 'admin_url', '1');
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/default', 'admin_url', '2');
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/log', 'admin_url', '20');
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/viewlog', 'admin_url', '21');
INSERT INTO `tp_auth_access` VALUES ('2', 'index/index/sasd', 'admin_url', '15');
INSERT INTO `tp_auth_access` VALUES ('2', 'index/index/asd', 'admin_url', '16');
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/menuedit', 'admin_url', '19');
-- ----------------------------
-- Table structure for tp_auth_role
-- ----------------------------
DROP TABLE IF EXISTS `tp_auth_role`;
CREATE TABLE `tp_auth_role` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL COMMENT '角色名称',
`pid` smallint(6) DEFAULT '0' COMMENT '父角色ID',
`status` tinyint(1) unsigned DEFAULT NULL COMMENT '状态',
`remark` varchar(255) DEFAULT NULL COMMENT '备注',
`create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`listorder` int(3) NOT NULL DEFAULT '0' COMMENT '排序字段',
PRIMARY KEY (`id`),
KEY `parentId` (`pid`),
KEY `status` (`status`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='角色表';
-- ----------------------------
-- Records of tp_auth_role
-- ----------------------------
INSERT INTO `tp_auth_role` VALUES ('1', '超级管理员', '0', '1', '拥有网站最高管理员权限!', '1329633709', '1329633709', '0');
INSERT INTO `tp_auth_role` VALUES ('2', '文章管理', '0', '1', 'SDAS', '0', '0', '0');
INSERT INTO `tp_auth_role` VALUES ('3', 'abc', '0', '1', '', '0', '0', '0');
-- ----------------------------
-- Table structure for tp_auth_role_user
-- ----------------------------
DROP TABLE IF EXISTS `tp_auth_role_user`;
CREATE TABLE `tp_auth_role_user` (
`role_id` int(11) unsigned DEFAULT '0' COMMENT '角色 id',
`user_id` int(11) DEFAULT '0' COMMENT '用户id',
KEY `group_id` (`role_id`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='用户角色对应表';
-- ----------------------------
-- Records of tp_auth_role_user
-- ----------------------------
INSERT INTO `tp_auth_role_user` VALUES ('2', '16');
INSERT INTO `tp_auth_role_user` VALUES ('2', '27');
-- ----------------------------
-- Table structure for tp_auth_rule
-- ----------------------------
DROP TABLE IF EXISTS `tp_auth_rule`;
CREATE TABLE `tp_auth_rule` (
`menu_id` int(11) NOT NULL COMMENT '后台菜单 ID',
`module` varchar(20) NOT NULL COMMENT '规则所属module',
`type` varchar(30) NOT NULL DEFAULT '1' COMMENT '权限规则分类,请加应用前缀,如admin_',
`name` varchar(255) NOT NULL DEFAULT '' COMMENT '规则唯一英文标识,全小写',
`url_param` varchar(255) DEFAULT NULL COMMENT '额外url参数',
`title` varchar(20) NOT NULL DEFAULT '' COMMENT '规则中文描述',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否有效(0:无效,1:有效)',
`rule_param` varchar(300) NOT NULL DEFAULT '' COMMENT '规则附加条件',
`nav_id` int(11) DEFAULT '0' COMMENT 'nav id',
PRIMARY KEY (`menu_id`),
KEY `module` (`module`,`status`,`type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='权限规则表';
-- ----------------------------
-- Records of tp_auth_rule
-- ----------------------------
INSERT INTO `tp_auth_rule` VALUES ('2', 'index', 'admin_url', 'index/auth/default', '', '权限管理', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('3', 'index', 'admin_url', 'index/auth/role', '', '角色管理', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('4', 'index', 'admin_url', 'index/auth/roleadd', '', '角色增加', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('5', 'index', 'admin_url', 'index/auth/roleedit', '', '角色编辑', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('6', 'index', 'admin_url', 'index/auth/roledelete', '', '角色删除', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('7', 'index', 'admin_url', 'index/auth/authorize', '', '角色授权', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('8', 'index', 'admin_url', 'index/auth/menu', '', '菜单管理', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('9', 'index', 'admin_url', 'index/auth/menu', '', '菜单列表', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('10', 'index', 'admin_url', 'index/auth/menuadd', '', '菜单增加', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('11', 'index', 'admin_url', 'index/auth/menuedit', '', '菜单修改', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('12', 'index', 'admin_url', 'index/auth/menudelete', '', '菜单删除', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('13', 'index', 'admin_url', 'index/auth/menuorder', '', '菜单排序', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('14', 'index', 'admin_url', 'index/admin/index', '', '用户管理', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('15', 'index', 'admin_url', 'index/index/sasd', '', '测试', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('16', 'index', 'admin_url', 'index/index/asd', 'asd', '测试', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('17', 'index', 'admin_url', 'index/auth/menuedit', 'dasd', '边缘', '1', 'in_array({id},[1,2,4,5] )', '0');
INSERT INTO `tp_auth_rule` VALUES ('19', 'index', 'admin_url', 'index/auth/menuedit', 'id=5', '测试5', '1', '{id}==5', '0');
INSERT INTO `tp_auth_rule` VALUES ('20', 'index', 'admin_url', 'index/auth/log', '', '行为日志', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('21', 'index', 'admin_url', 'index/auth/viewlog', '', '查看日志', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('22', 'index', 'admin_url', 'index/auth/clear', '', '清空日志', '1', '', '0');
-- ----------------------------
-- Table structure for tp_menu
-- ----------------------------
DROP TABLE IF EXISTS `tp_menu`;
CREATE TABLE `tp_menu` (
`id` smallint(6) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增ID',
`parent_id` smallint(6) unsigned NOT NULL DEFAULT '0' COMMENT '父级ID',
`app` char(20) NOT NULL COMMENT '应用名称app',
`model` char(20) NOT NULL COMMENT '控制器',
`action` char(20) NOT NULL COMMENT '操作名称',
`url_param` char(50) NOT NULL COMMENT 'url参数',
`type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '菜单类型 1权限认证+菜单0只作为菜单',
`status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '状态1显示0不显示',
`name` varchar(50) NOT NULL COMMENT '菜单名称',
`icon` varchar(50) NOT NULL COMMENT '菜单图标',
`remark` varchar(255) NOT NULL COMMENT '备注',
`list_order` smallint(6) unsigned NOT NULL DEFAULT '0' COMMENT '排序ID',
`rule_param` varchar(255) NOT NULL COMMENT '验证规则',
`nav_id` int(11) DEFAULT '0' COMMENT 'nav ID ',
`request` varchar(255) NOT NULL COMMENT '请求方式(日志生成)',
`log_rule` varchar(255) NOT NULL COMMENT '日志规则',
PRIMARY KEY (`id`),
KEY `status` (`status`),
KEY `model` (`model`),
KEY `parent_id` (`parent_id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COMMENT='后台菜单表';
-- ----------------------------
-- Records of tp_menu
-- ----------------------------
INSERT INTO `tp_menu` VALUES ('1', '0', 'index', 'auth', 'default', '', '0', '1', '系统管理', '', '', '10', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('2', '1', 'index', 'auth', 'default', '', '0', '1', '权限管理', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('3', '2', 'index', 'auth', 'role', '', '1', '1', '角色管理', '', '1', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('4', '3', 'index', 'auth', 'roleAdd', '', '1', '0', '角色增加', '', '', '0', '', '0', '', '{id}');
INSERT INTO `tp_menu` VALUES ('5', '3', 'index', 'auth', 'roleEdit', '', '1', '0', '角色编辑', '', 'asdas', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('6', '3', 'index', 'auth', 'roleDelete', '', '1', '0', '角色删除', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('7', '3', 'index', 'auth', 'authorize', '', '1', '0', '角色授权', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('8', '1', 'index', 'auth', 'default', '', '0', '1', '菜单管理', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('9', '8', 'index', 'auth', 'menu', '', '1', '1', '菜单列表', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('10', '9', 'index', 'auth', 'menuAdd', '', '1', '0', '菜单增加', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('11', '9', 'index', 'auth', 'menuEdit', '', '1', '0', '菜单修改', '', '', '0', '', '0', 'POST', '我的ID是{id} <br> 记入的目录{name}');
INSERT INTO `tp_menu` VALUES ('12', '9', 'index', 'auth', 'menuDelete', '', '1', '0', '菜单删除', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('13', '9', 'index', 'auth', 'menuOrder', '', '1', '0', '菜单排序', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('14', '2', 'index', 'admin', 'index', '', '1', '1', '用户管理', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('15', '0', 'index', 'index', 'sasd', '', '0', '1', '测试', '', '', '20', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('16', '15', 'index', 'index', 'asd', 'asd', '1', '1', '测试', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('17', '15', 'index', 'auth', 'menuEdit', 'dasd', '1', '1', '边缘', '', '11q1adas1adsasdfsdfdsd', '0', 'in_array({id},[1,2,4,5] )', '0', '', '');
INSERT INTO `tp_menu` VALUES ('20', '2', 'index', 'auth', 'log', '', '1', '1', '行为日志', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('19', '16', 'index', 'auth', 'menuEdit', 'id=5', '1', '1', '测试5', '', 'dasd', '0', '{id}==5', '0', 'GET', '{id}');
INSERT INTO `tp_menu` VALUES ('21', '20', 'index', 'auth', 'viewLog', '', '1', '0', '查看日志', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('22', '20', 'index', 'auth', 'clear', '', '1', '0', '清空日志', '', '', '0', '', '0', '', '');

@ -0,0 +1,520 @@
<?php
namespace tp5auth\controller;
use think\Cache;
use think\Validate;
use tp5auth\Auth;
use tp5auth\library\Tree;
use tp5auth\model\ActionLog;
use tp5auth\model\AuthAccess;
use tp5auth\model\AuthRole;
use tp5auth\model\AuthRoleUser;
use tp5auth\model\Menu;
class Rbac
{
public $menuValidate = ['name|名称'=>'require' , 'app|应用'=>'require' , 'model|控制器'=>'require' , 'action|方法'=>'require'];
public $roleValidate = ['name|角色名称' => 'require'];
private $id;
public function __construct($request)
{
$this->request = $request;
$this->param = $this->request->param();
$this->post = $this->request->post();
$this->id = isset($this->param['id'])?intval($this->param['id']):'';
$this->data = ['pach'=>VIEW_PATH];
}
/**
* 菜单and权限列表
*/
public function menu(){
$result = Menu::where('')->order(["list_order" => "asc",'id'=>'asc'])->column('*','id');
$tree = new Tree();
$tree->nbsp = '&nbsp;&nbsp;&nbsp;';
foreach ($result as $n=> $r) {
$result[$n]['level'] = $tree->get_level($r['id'], $result);
$result[$n]['parent_id_node'] = ($r['parent_id']) ? ' class="child-of-node-' . $r['parent_id'] . '"' : '';
$result[$n]['str_manage'] = checkPath('auth/menuAdd',["parent_id" => $r['id']]) ? '<a href="'.url("auth/menuAdd",["parent_id" => $r['id']]).'">添加子菜单</a> |':'';
$result[$n]['str_manage'] .= checkPath('auth/menuEdit',["id" => $r['id']]) ?'<a href="'.url("auth/menuEdit",["id" => $r['id']]).'">编辑</a> |':'';
$result[$n]['str_manage'] .= checkPath('auth/menuDelete',["id" => $r['id']]) ?'<a class="a-post" post-msg="你确定要删除吗" post-url="'.url("auth/menuDelete",["id" => $r['id']]).'">删除</a>|':'';
$result[$n]['status'] = $r['status'] ? '开启' : '隐藏';
}
$str = "<tr id='node-\$id' \$parent_id_node>
<td style='padding-left:20px;'>
<input name='listorders[\$id]' type='text' size='3' value='\$list_order' data='\$id' class='listOrder'>
</td>
<td>\$id</td>
<td>\$spacer \$name</td>
<td>\$app</td>
<td>\$model</td>
<td>\$action</td>
<td>\$request</td>
<td>\$status</td>
<td>\$str_manage</td>
</tr>";
$tree->init($result);
$info = $tree->get_tree(0, $str);
return [VIEW_PATH.'menu.php',array_merge($this->data,['info'=>$info])];
}
/**
* 菜单and权限 修改
*/
public function menuEdit(){
$post = $this->post;
$info = Menu::get($this->id);
if(empty($info)){
return false;
}
if($this->request->isPost()){
$validate = new Validate($this->menuValidate);
if (!$validate->check($post)) {
return ['code'=>0,'msg'=>$validate->getError()];
}
if($info->menuEdit($post)){
return ['code'=>1,'msg'=>'修改成功','url'=>url('auth/menu')];
}else{
return ['code'=>0,'msg'=>'修改失败'];
}
}
$info['selectCategorys'] = menu($info['parent_id']);
return [VIEW_PATH.'menuEdit.php',array_merge($this->data,['info'=>$info])];
}
/**
* 菜单and权限 增加
*/
public function menuAdd(){
$parent_id = isset($this->param['parent_id'])?$this->param['parent_id']:'';
if($this->request->isPost()){
$post = $this->post;
$validate = new Validate($this->menuValidate);
if (!$validate->check($post)) {
return ['code'=>0,'msg'=>$validate->getError()];
}
$menu = new Menu();
if($menu->menuAdd($post)){
return ['code'=>1,'msg'=>'增加成功','url'=>url('auth/menu')];
}else{
return ['code'=>0,'msg'=>'增加失败'];
}
}
$info['selectCategorys'] = menu($parent_id);
return [VIEW_PATH.'menuAdd.php',array_merge($this->data,['info'=>$info])];
}
/**
* 菜单and权限 删除
*/
public function menuDelete(){
if($this->request->isPost()){
$result = Menu::get($this->id);
if(empty($result)){
return ['code'=>0,'msg'=>'没有数据'];
}else if(Menu::where(['parent_id'=>$result['id']])->find()){
return ['code'=>0,'msg'=>'有子目录不可删除'];
};
if($result->menuDelete($this->id)){
return ['code'=>1,'msg'=>'删除成功','url'=>url('auth/menu')];
}else{
return ['code'=>0,'msg'=>'删除失败'];
}
}
return ['code'=>0,'msg'=>'请求方式错误'];
}
/**
* 菜单 排序
*/
public function menuOrder(){
if($this->request->isPost()) {
$order = isset($this->param['order'])?intval($this->param['order']):'';
$result = Menu::get($this->id);
if(empty($result)){
return ['code'=>0,'msg'=>'没有数据'];
}else if ($result) {
if ($result->save(['list_order' => $order])) {
return ['code' => 1, 'msg' => '数据已更新'];
}
}
return ['code'=>0,'msg'=>'数据无变化'];
}
return ['code'=>0,'msg'=>'请求方式错误'];
}
/**
* 角色列表
*/
public function role(){
$data = AuthRole::all();
return [VIEW_PATH.'role.php',array_merge($this->data,['list'=>$data])];
}
/**
* 角色修改
*/
public function roleEdit(){
$post = $this->post;
$info = AuthRole::get($this->id);
if(empty($info)){
return false;
}
//post 数据处理
if($this->request->isPost()){
$validate = new Validate($this->roleValidate);
if (!$validate->check($post)) {
return ['code'=>0,'msg'=>$validate->getError()];
}
if($info->save($post)){
return ['code'=>1,'msg'=>'修改成功','url'=>url('auth/role')];
}else{
return ['code'=>0,'msg'=>'修改失败'];
}
}
return [VIEW_PATH.'roleEdit.php',array_merge($this->data,['info'=>$info])];
}
/**
* 角色增加
*/
public function roleAdd(){
//post 数据处理
if($this->request->isPost()){
$post = $this->post;
//现在数据
$validate = new Validate($this->roleValidate);
if (!$validate->check($post)) {
return ['code'=>0,'msg'=>$validate->getError()];
}
if(AuthRole::create($post)){
return ['code'=>1,'msg'=>'增加成功','url'=>url('auth/role')];
}else{
return ['code'=>0,'msg'=>'增加失败'];
}
}
return [VIEW_PATH.'roleAdd.php',$this->data];
}
public function roleDelete(){
if($this->request->isPost()){
$result = AuthRole::get($this->id);
if($this->id==1){
return ['code'=>0,'msg'=>'超级管理员不可删除'];
}else if(empty($result)){
return ['code'=>0,'msg'=>'没有数据'];
}
if($result->authRoleDelete()){
return ['code'=>1,'msg'=>'删除成功','url'=>url('auth/role')];
}else{
return ['code'=>0,'msg'=>'删除失败'];
}
}
return ['code'=>0,'msg'=>'请求方式错误'];
}
/**
* 角色授权
*/
public function authorize(){
$menu = Menu::where('')->order(["list_order" => "asc",'id'=>'asc'])->column('*','id');
if($this->request->isPost()){//表单处理
$post = $this->post;
$menuid = $post['menuid'];
if(empty($this->id)){
return ['code'=>0,'msg'=>'需要授权的角色不存在'];
}
AuthAccess::where(["role_id" => $this->id,'type'=>'admin_url'])->delete();
if (is_array($menuid) && count($menuid)>0) {
foreach ($menuid as $v) {
$menus = isset($menu[$v])?$menu[$v]:'';
if($menus){
$name = strtolower("{$menus['app']}/{$menus['model']}/{$menus['action']}");
$data[] = [
"role_id" => $this->id,
"rule_name" => $name,
'type' => 'admin_url',
'menu_id' => $v
];
}
}
if(!empty($data)){
$AuthAccess = new AuthAccess();
if($AuthAccess->saveAll($data)){
return ['code'=>1,'msg'=>'增加成功','url'=>url('auth/role')];
}else{
return ['code'=>0,'msg'=>'增加失败'];
}
}
}else{
return ['code'=>0,'msg'=>'没有接收到数据,执行清除授权成功!'];
}
}//表单处理结束
if(empty($this->id)){
return false;
}
$info = self::authorizeHtml($menu,'admin_url');
return [VIEW_PATH.'authorize.php',array_merge($this->data,['info'=>$info])];
}
/**
* 管理员授权
*/
public function adminAuthorize(){
$menu = Menu::where('')->order(["list_order" => "asc",'id'=>'asc'])->column('*','id');
if($this->request->isPost()){//表单处理
$post = $this->post;
$menuid = $post['menuid'];
if(empty($this->id)){
return ['code'=>0,'msg'=>'需要授权的角色不存在'];
}
AuthAccess::where(["role_id" => $this->id,'type'=>'admin'])->delete();
if (is_array($menuid) && count($menuid)>0) {
foreach ($menuid as $v) {
$menus = isset($menu[$v])?$menu[$v]:'';
if($menus){
$name = strtolower("{$menus['app']}/{$menus['model']}/{$menus['action']}");
$data[] = [
"role_id" => $this->id,
"rule_name" => $name,
'type' => 'admin',
'menu_id' => $v
];
}
}
if(!empty($data)){
$AuthAccess = new AuthAccess();
if($AuthAccess->saveAll($data)){
return ['code'=>1,'msg'=>'增加成功','url'=>''];
}else{
return ['code'=>0,'msg'=>'增加失败'];
}
}
}else{
return ['code'=>0,'msg'=>'没有接收到数据,执行清除授权成功!'];
}
}//表单处理结束
if(empty($this->id)){
return false;
}
//管理员所有角色权限
$roleId = AuthRoleUser::hasWhere('authRule')->where(['a.user_id'=>$this->id,'b.status'=>1])->column('role_id');
if(in_array(1,$roleId)){
$AuthAccess = true;
}else if(empty($roleId)){
$AuthAccess = [];
}else{
$AuthAccess = AuthAccess::where(["role_id"=>["in",$roleId]])->column('*','menu_id');
}
$info = self::authorizeHtml($menu,'admin',$AuthAccess);
return [VIEW_PATH.'adminAuthorize.php',array_merge($this->data,['info'=>$info])];
}
/**
* 注册样式文件
*/
public function openFile(){
$text = '';
$file = strtr($this->param['file'], '_', DS);
$extension = substr(strrchr($file, '.'), 1);
switch ($extension)
{
case 'css':
$text = 'text/css';
break;
case 'js':
$text = 'text/js';
break;
default:
return false;
}
$pach = VIEW_PATH.'../static/'.$file;
$file = file_get_contents($pach);
return ['file'=>response($file, 200, ['Content-Length' => strlen($file)])->contentType($text)];
}
/**
* 日志列表
*/
public function log(){
$where = [];
$param = $this->param;
if(!empty($param['username'])){
$where['username'] = $param['username'];
}
if(!empty($param['userId'])){
$where['user_id'] = $param['userId'];
}
if(!empty($param['title'])){
$where['title'] = ['like','%'.$param['title'].'%'];
}
$list = ActionLog::where($where)->order('id desc')->paginate(20,'',[
'query'=>$param
]);
$page = $list->render();
return [VIEW_PATH.'log.php',array_merge($this->data,['list'=>$list,'page'=>$page])];
}
/**
* 日志详情
*/
public function viewLog(){
$info = ActionLog::get($this->id);
return [VIEW_PATH.'viewLog.php',array_merge($this->data,['info'=>$info])];
}
/**
* 清空日志
*/
public function clear(){
if(ActionLog::where('1=1')->delete()){
return ['code'=>1,'msg'=>'数据已清空','url'=>url('auth/log')];
}
return ['code'=>0,'msg'=>'操作失败'];
}
/**
* 清除缓存
*/
public function cache(){
Cache::rm('logMenu');
return ['code'=>1,'msg'=>'操作成功','url'=>url('auth/menu')];
}
protected function authorizeHtml($menu,$type,$authMenu=[]){
$priv_data = AuthAccess::where(['role_id'=>$this->id,'type'=>$type])->field("rule_name")->column('menu_id');
$tree = new Tree();
foreach ($menu as $n => $t) {
$menu[$n]['checked'] = (in_array($t['id'], $priv_data)) ? ' checked' : '';
$menu[$n]['level'] = $tree->get_level($t['id'], $menu);
$menu[$n]['width'] = 100-$menu[$n]['level'];
$menu[$n]['disabled'] = isset($authMenu[$t['id']])||$authMenu===true?[0=>"style='display: none;'disabled=''",1=>'★']:[0=>'',
1=>''];
}
$tree->init($menu);
$tree->text =[
'other' => "<label class='checkbox' data-original-title='' data-toggle='' >
<input \$checked \$disabled[0] name='menuid[]' value='\$id' level='\$level'
onclick='javascript:checknode(this);'type='checkbox'>
\$disabled[1] \$name
</label>",
'0' => [
'0' =>"<dl class='checkmod'>
<dt class='hd'>
<label class='checkbox' data-original-title='' data-toggle='tooltip'>
<input \$checked \$disabled[0] name='menuid[]' value='\$id' level='\$level'
onclick='javascript:checknode(this);'
type='checkbox'>
\$disabled[1] \$name
</label>
</dt>
<dd class='bd'>",
'1' => "</dd></dl>",
],
'1' => [
'0' => "
<div class='menu_parent'>
<label class='checkbox' data-original-title='' data-toggle='tooltip'>
<input \$checked \$disabled[0] name='menuid[]' value='\$id' level='\$level'
onclick='javascript:checknode(this);' type='checkbox'>
\$disabled[1] \$name
</label>
</div>
<div class='rule_check' style='width: \$width%;'>",
'1' => "</div><span class='child_row'></span>",
]
];
$info['html'] = $tree->get_authTree(0);
$info['id'] = $this->id;
return $info;
}
}
/**
* 所有后台菜单
* @param int $selected 默认id
* @return mixed
*/
function menu($selected = 1){
$array = '';
$result = Menu::where('')->order(["list_order" => "asc",'id'=>'asc'])->column('*','id');
$tree = new Tree();
foreach ($result as $r) {
$r['selected'] = $r['id'] == $selected ? 'selected' : '';
$array[] = $r;
}
$str = "<option value='\$id' \$selected>\$spacer \$name</option>";
$tree->init($array);
$parentid = isset($where['parentid'])?$where['parentid']:0;
return $tree->get_tree($parentid, $str);
}

@ -0,0 +1,11 @@
<?php
/**
* @param string $path
* @param array $param
* @return bool
*/
function checkPath($path,$param=[]){
$result = \tp5auth\Auth::checkPath($path,$param);
return $result;
}
?>

@ -0,0 +1,154 @@
<?php
namespace tp5auth\library;
/**
* 通用的树型类,可以生成任何树型结构
*/
class Tree
{
public $text,$html;
/**
* 生成树型结构所需要的2维数组
* @var array
*/
public $arr = array();
/**
* 生成树型结构所需修饰符号,可以换成图片
* @var array
*/
public $icon = array('│', '├', '└');
public $nbsp = "&nbsp;";
/**
* @access private
*/
public $ret = '';
/**
* 构造函数,初始化类
* @param array 2维数组例如
* array(
* 1 => array('id'=>'1','parentid'=>0,'name'=>'一级栏目一'),
* 2 => array('id'=>'2','parentid'=>0,'name'=>'一级栏目二'),
* 3 => array('id'=>'3','parentid'=>1,'name'=>'二级栏目一'),
* 4 => array('id'=>'4','parentid'=>1,'name'=>'二级栏目二'),
* 5 => array('id'=>'5','parentid'=>2,'name'=>'二级栏目三'),
* 6 => array('id'=>'6','parentid'=>3,'name'=>'三级栏目一'),
* 7 => array('id'=>'7','parentid'=>3,'name'=>'三级栏目二')
* )
*/
public function init($arr=array()) {
$this->arr = $arr;
$this->ret = '';
return is_array($arr);
}
/**
* 得到树型结构
* @param int ID表示获得这个ID下的所有子级
* @param string 生成树型结构的基本代码,例如:"<option value=\$id \$selected>\$spacer\$name</option>"
* @param int 被选中的ID比如在做树型下拉框的时候需要用到
* @return string
*/
public function get_tree($myid, $str, $sid = 0, $adds = '', $str_group = '') {
$parent_id = '';
$nstr = '';
$number = 1;
//一级栏目
$child = $this->get_child($myid);
if (is_array($child)) {
$total = count($child);
foreach ($child as $id => $value) {
$j = $k = '';
if ($number == $total) {
$j .= $this->icon[2];
} else {
$j .= $this->icon[1];
$k = $adds ? $this->icon[0] : '';
}
$spacer = $adds ? $adds . $j : '';
$selected = $id == $sid ? 'selected' : '';
@extract($value);
$parent_id == 0 && $str_group ? eval("\$nstr = \"$str_group\";") : eval("\$nstr = \"$str\";");
$this->ret .= $nstr;
$nbsp = $this->nbsp;
$this->get_tree($id, $str, $sid, $adds . $k . $nbsp, $str_group);
$number++;
}
}
return $this->ret;
}
public function get_authTree($myid){
$id = '';
$nstr = '';
$child = $this->get_child($myid);
if (is_array($child)) {
$level = current($child);
$text = isset($this->text[$level['level']]) ? $this->text[$level['level']] : end($this->text);
foreach($child as $k=>$v){
@extract($v);
if($this->get_child($id)){
eval("\$nstr = \"$text[0]\";");
$this->html .= $nstr;
self::get_authTree($id);
eval("\$nstr = \"$text[1]\";");
$this->html .= $nstr;
}else{
$a = $this->text['other'];
eval("\$nstr = \"$a\";");
$this->html .= $nstr;
}
}
}
return $this->html;
}
/**
* 得到子级数组
* @param int
* @return array
*/
public function get_child($myid) {
$a = $newarr = array();
if (is_array($this->arr)) {
foreach ($this->arr as $id => $a) {
if ($a['parent_id'] == $myid)
$newarr[$id] = $a;
}
}
return $newarr ? $newarr : false;
}
/**
* 递归获取级别
* @param int $id ID
* @param array $array 所有菜单
* @param int $i 所在级别
* @return array
*/
public function get_level($id, $array = array(), $i = 0) {
if ($array[$id]['parent_id']==0 || empty($array[$array[$id]['parent_id']]) || $array[$id]['parent_id']==$id){
return $i;
}else{
$i++;
return self::get_level($array[$id]['parent_id'],$array,$i);
}
}
}

@ -0,0 +1,22 @@
<?php
namespace tp5auth\model;
class ActionLog extends \think\Model
{
// 设置完整的数据表(包含前缀)
protected $name = 'action_log';
//初始化属性
protected function initialize()
{
}
// 读取器 订单状态
protected function getActionIpAttr($reg='',$data='')
{
return long2ip($data['action_ip']);
}
}
?>

@ -0,0 +1,22 @@
<?php
namespace tp5auth\model;
class AuthAccess extends \think\Model
{
// 设置完整的数据表(包含前缀)
protected $name = 'auth_access';
//初始化属性
protected function initialize()
{
}
//关联一对一 角色
public function authRole()
{
return $this->hasOne('AuthRule','menu_id','menu_id');
}
}
?>

@ -0,0 +1,37 @@
<?php
namespace tp5auth\model;
class AuthRole extends \think\Model
{
// 设置完整的数据表(包含前缀)
protected $name = 'auth_role';
//初始化属性
protected function initialize()
{
}
//一对多 权限授权
public function authAccess()
{
return $this->hasMany('AuthAccess','role_id','id');
}
/**
* 关联删除 AuthAccess
* @return bool
*/
public function authRoleDelete(){
if($this->delete()){
if($this->authAccess){
AuthAccess::where(['role_id'=>$this->id,'type'=>'admin_url'])->delete();
}
return true;
}
return false;
}
}
?>

@ -0,0 +1,63 @@
<?php
namespace tp5auth\model;
class AuthRoleUser extends \think\Model
{
// 设置完整的数据表(包含前缀)
protected $name = 'auth_role_user';
//初始化属性
protected function initialize()
{
}
//关联一对一 角色
public function authRole()
{
return $this->hasOne('authRole','id','role_id');
}
//关联一对一 角色
public function authAccess()
{
return $this->hasOne('authAccess','role_id','role_id');
}
/**
* 加入角色权限
* @param array $role_id 角色ID
* @param int $user_id 用户ID
* @return bool
*/
public function authRoleUserAdd($role_id,$user_id){
$data = [];
if(is_array($role_id)){
self::where(['user_id'=>$user_id])->delete();
foreach($role_id as $v){
$data[] = [
'role_id' => $v,
'user_id' => $user_id
];
}
self::saveAll($data);
return true;
}
return false;
}
/**
* 删除角色权限
* @param int $user_id 用户ID
* @return bool
*/
public function authRoleUserDelete($user_id){
self::where(['user_id'=>$user_id])->delete();
AuthAccess::where(['role_id'=>$user_id,'type'=>'admin'])->delete();
}
}
?>

@ -0,0 +1,52 @@
<?php
namespace tp5auth\model;
class AuthRule extends \think\Model
{
// 设置完整的数据表(包含前缀)
protected $name = 'auth_rule';
//初始化属性
protected function initialize()
{
}
//关联一对多 目录
public function authAccess()
{
return $this->hasMany('AuthAccess','menu_id','menu_id');
}
/**
* 关联 authAccess模型 修改
* @param array $param 参数
* @return bool
*/
public function authRuleEdit($param){
if($this->save($param)){
if($this->authAccess){
AuthAccess::where(['menu_id'=>$param['menu_id']])->update(['rule_name'=>$param['name'],'type'=>$param['type']]);
}
return true;
}
return false;
}
/**
* 删除
* @return bool
*/
public function authRuleDelete(){
if($this->delete()){
if($this->authAccess){
AuthAccess::where(['menu_id'=>$this->menu_id])->delete();
}
return true;
}
return false;
}
}
?>

@ -0,0 +1,128 @@
<?php
namespace tp5auth\model;
class Menu extends \think\Model
{
// 设置完整的数据表(包含前缀)
protected $name = 'menu';
//初始化属性
protected function initialize()
{
}
/**
* 缓存后台菜单数据
*/
public static function actionLogMenu() {
$log = [];
$men = Menu::where('request <> "" ')->column('*');
foreach($men as $v){
$url = strtolower($v['app'].'/'.$v['model'].'/'.$v['action']);
$arr = [
'log_rule' => $v['log_rule'],
'request' => $v['request'],
'rule_param'=> $v['rule_param'],
'name' => $v['name'],
];
if(!isset($log[$url])){
$log[$url] = $arr;
}else{
$log[$url]['child'][] = $arr;
}
}
return $log;
}
//关联一对一 目录
public function authRule()
{
return $this->hasOne('AuthRule','menu_id','id');
}
/**
* 关联 authRule模型 修改
* @param array $param 参数
* @return bool
*/
public function menuEdit($param){
if($this->save($param)){
$authRule = $this->authRule;
if($this->data['action'] == 'default' ||$this->data['type'] == 0) {//判断他们是否需要加入权限
if($authRule){
$this->authRule->authRuleDelete();
}
return true;
}
$name = strtolower("{$this->data['app']}/{$this->data['model']}/{$this->data['action']}");
$authRuledata = [
"name" => $name,
"module" => $this->data['app'],
"type" => "admin_url",
"title" => $this->data['name'],
'menu_id' => $this->data['id'],
'url_param' => $this->data['url_param'],
'rule_param' => $this->data['rule_param'],
];
if($authRule){
$authRule->authRuleEdit($authRuledata);
return true;
}else{
AuthRule::create($authRuledata);
return true;
}
}
return false;
}
/**
* 关联 authRule模型 增加
* @param array $param 参数
* @return bool
*/
public function menuAdd($param){
$auth = $this->create($param);
if($auth){
$name = strtolower("{$auth->data['app']}/{$auth->data['model']}/{$auth->data['action']}");
$authRule = [
"name" => $name,
"module" => $auth->data['app'],
"type" => "admin_url",
"title" => $auth->data['name'],
'menu_id' => $auth->data['id'],
'url_param' => $auth->data['url_param'],
'rule_param' => $auth->data['rule_param'],
];
AuthRule::create($authRule);
return true;
}
return false;
}
/**
* 关联 authRule模型 删除
* @param int $id 参数
* @return bool
*/
public function menuDelete(){
if($this->delete()){
if($this->authRule){
$this->authRule->authRuleDelete();
}
return true;
}
return false;
}
}
?>

@ -0,0 +1,37 @@
/*
Navicat Premium Data Transfer
Source Server : localhost
Source Server Type : MySQL
Source Server Version : 50712
Source Host : localhost
Source Database : rbac
Target Server Type : MySQL
Target Server Version : 50712
File Encoding : utf-8
Date: 11/17/2016 00:01:38 AM
*/
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for `tp_action_log`
-- ----------------------------
DROP TABLE IF EXISTS `tp_action_log`;
CREATE TABLE `tp_action_log` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`user_id` int(10) NOT NULL DEFAULT '0' COMMENT '执行用户id',
`action_ip` bigint(20) NOT NULL COMMENT '执行行为者ip',
`log` longtext NOT NULL COMMENT '日志备注',
`log_url` varchar(255) NOT NULL COMMENT '执行的URL',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '执行行为的时间',
`username` varchar(255) NOT NULL COMMENT '执行者',
`title` varchar(255) NOT NULL COMMENT '标题',
PRIMARY KEY (`id`),
KEY `id` (`id`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='行为日志表';
SET FOREIGN_KEY_CHECKS = 1;

@ -0,0 +1,40 @@
/*
Navicat Premium Data Transfer
Source Server : localhost
Source Server Type : MySQL
Source Server Version : 50712
Source Host : localhost
Source Database : rbac
Target Server Type : MySQL
Target Server Version : 50712
File Encoding : utf-8
Date: 11/12/2016 23:25:30 PM
*/
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for `tp_auth_access`
-- ----------------------------
DROP TABLE IF EXISTS `tp_auth_access`;
CREATE TABLE `tp_auth_access` (
`role_id` mediumint(8) unsigned NOT NULL COMMENT '角色',
`rule_name` varchar(255) NOT NULL COMMENT '规则唯一英文标识,全小写',
`type` varchar(30) DEFAULT NULL COMMENT '权限规则分类,请加应用前缀,如admin_',
`menu_id` int(11) DEFAULT NULL COMMENT '后台菜单ID',
KEY `role_id` (`role_id`),
KEY `rule_name` (`rule_name`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='权限授权表';
-- ----------------------------
-- Records of `tp_auth_access`
-- ----------------------------
BEGIN;
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/default', 'admin_url', '1'), ('2', 'index/auth/default', 'admin_url', '8'), ('2', 'index/auth/menu', 'admin_url', '9'), ('2', 'index/auth/menuadd', 'admin_url', '10'), ('2', 'index/auth/menuedit', 'admin_url', '11'), ('2', 'index/auth/menudelete', 'admin_url', '12'), ('2', 'index/auth/menuorder', 'admin_url', '13');
COMMIT;
SET FOREIGN_KEY_CHECKS = 1;

@ -0,0 +1,45 @@
/*
Navicat Premium Data Transfer
Source Server : localhost
Source Server Type : MySQL
Source Server Version : 50712
Source Host : localhost
Source Database : rbac
Target Server Type : MySQL
Target Server Version : 50712
File Encoding : utf-8
Date: 11/12/2016 23:25:24 PM
*/
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for `tp_auth_role`
-- ----------------------------
DROP TABLE IF EXISTS `tp_auth_role`;
CREATE TABLE `tp_auth_role` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL COMMENT '角色名称',
`pid` smallint(6) DEFAULT '0' COMMENT '父角色ID',
`status` tinyint(1) unsigned DEFAULT NULL COMMENT '状态',
`remark` varchar(255) DEFAULT NULL COMMENT '备注',
`create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`listorder` int(3) NOT NULL DEFAULT '0' COMMENT '排序字段',
PRIMARY KEY (`id`),
KEY `parentId` (`pid`),
KEY `status` (`status`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='角色表';
-- ----------------------------
-- Records of `tp_auth_role`
-- ----------------------------
BEGIN;
INSERT INTO `tp_auth_role` VALUES ('1', '超级管理员', '0', '1', '拥有网站最高管理员权限!', '1329633709', '1329633709', '0'), ('2', '文章管理', '0', '1', '', '0', '0', '0');
COMMIT;
SET FOREIGN_KEY_CHECKS = 1;

@ -0,0 +1,38 @@
/*
Navicat Premium Data Transfer
Source Server : localhost
Source Server Type : MySQL
Source Server Version : 50712
Source Host : localhost
Source Database : rbac
Target Server Type : MySQL
Target Server Version : 50712
File Encoding : utf-8
Date: 11/12/2016 23:25:19 PM
*/
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for `tp_auth_role_user`
-- ----------------------------
DROP TABLE IF EXISTS `tp_auth_role_user`;
CREATE TABLE `tp_auth_role_user` (
`role_id` int(11) unsigned DEFAULT '0' COMMENT '角色 id',
`user_id` int(11) DEFAULT '0' COMMENT '用户id',
KEY `group_id` (`role_id`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='用户角色对应表';
-- ----------------------------
-- Records of `tp_auth_role_user`
-- ----------------------------
BEGIN;
INSERT INTO `tp_auth_role_user` VALUES ('2', '16');
COMMIT;
SET FOREIGN_KEY_CHECKS = 1;

@ -0,0 +1,45 @@
/*
Navicat Premium Data Transfer
Source Server : localhost
Source Server Type : MySQL
Source Server Version : 50712
Source Host : localhost
Source Database : rbac
Target Server Type : MySQL
Target Server Version : 50712
File Encoding : utf-8
Date: 11/12/2016 23:25:13 PM
*/
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for `tp_auth_rule`
-- ----------------------------
DROP TABLE IF EXISTS `tp_auth_rule`;
CREATE TABLE `tp_auth_rule` (
`menu_id` int(11) NOT NULL COMMENT '后台菜单 ID',
`module` varchar(20) NOT NULL COMMENT '规则所属module',
`type` varchar(30) NOT NULL DEFAULT '1' COMMENT '权限规则分类,请加应用前缀,如admin_',
`name` varchar(255) NOT NULL DEFAULT '' COMMENT '规则唯一英文标识,全小写',
`url_param` varchar(255) DEFAULT NULL COMMENT '额外url参数',
`title` varchar(20) NOT NULL DEFAULT '' COMMENT '规则中文描述',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否有效(0:无效,1:有效)',
`rule_param` varchar(300) NOT NULL DEFAULT '' COMMENT '规则附加条件',
`nav_id` int(11) DEFAULT '0' COMMENT 'nav id',
PRIMARY KEY (`menu_id`),
KEY `module` (`module`,`status`,`type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='权限规则表';
-- ----------------------------
-- Records of `tp_auth_rule`
-- ----------------------------
BEGIN;
INSERT INTO `tp_auth_rule` VALUES ('2', 'index', 'admin_url', 'index/auth/default', '', '权限管理', '1', '', '0'), ('3', 'index', 'admin_url', 'index/auth/role', '', '角色管理', '1', '', '0'), ('4', 'index', 'admin_url', 'index/auth/roleadd', '', '角色增加', '1', '', '0'), ('5', 'index', 'admin_url', 'index/auth/roleedit', '', '角色编辑', '1', '', '0'), ('6', 'index', 'admin_url', 'index/auth/roledelete', '', '角色删除', '1', '', '0'), ('7', 'index', 'admin_url', 'index/auth/authorize', '', '角色授权', '1', '', '0'), ('8', 'index', 'admin_url', 'index/auth/menu', '', '菜单管理', '1', '', '0'), ('9', 'index', 'admin_url', 'index/auth/menu', '', '菜单列表', '1', '', '0'), ('10', 'index', 'admin_url', 'index/auth/menuadd', '', '菜单增加', '1', '', '0'), ('11', 'index', 'admin_url', 'index/auth/menuedit', '', '菜单修改', '1', '', '0'), ('12', 'index', 'admin_url', 'index/auth/menudelete', '', '菜单删除', '1', '', '0'), ('13', 'index', 'admin_url', 'index/auth/menuorder', '', '菜单排序', '1', '', '0'), ('14', 'index', 'admin_url', 'index/admin/index', '', '用户管理', '1', '', '0');
COMMIT;
SET FOREIGN_KEY_CHECKS = 1;

@ -0,0 +1,54 @@
/*
Navicat Premium Data Transfer
Source Server : localhost
Source Server Type : MySQL
Source Server Version : 50712
Source Host : localhost
Source Database : rbac
Target Server Type : MySQL
Target Server Version : 50712
File Encoding : utf-8
Date: 11/12/2016 23:25:08 PM
*/
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for `tp_menu`
-- ----------------------------
DROP TABLE IF EXISTS `tp_menu`;
CREATE TABLE `tp_menu` (
`id` smallint(6) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增ID',
`parent_id` smallint(6) unsigned NOT NULL DEFAULT '0' COMMENT '父级ID',
`app` char(20) NOT NULL COMMENT '应用名称app',
`model` char(20) NOT NULL COMMENT '控制器',
`action` char(20) NOT NULL COMMENT '操作名称',
`url_param` char(50) NOT NULL COMMENT 'url参数',
`type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '菜单类型 1权限认证+菜单0只作为菜单',
`status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '状态1显示0不显示',
`name` varchar(50) NOT NULL COMMENT '菜单名称',
`icon` varchar(50) NOT NULL COMMENT '菜单图标',
`remark` varchar(255) NOT NULL COMMENT '备注',
`list_order` smallint(6) unsigned NOT NULL DEFAULT '0' COMMENT '排序ID',
`rule_param` varchar(255) NOT NULL COMMENT '验证规则',
`nav_id` int(11) DEFAULT '0' COMMENT 'nav ID ',
`request` varchar(255) NOT NULL COMMENT '请求方式(日志生成)',
`log_rule` varchar(255) NOT NULL COMMENT '日志规则',
PRIMARY KEY (`id`),
KEY `status` (`status`),
KEY `model` (`model`),
KEY `parent_id` (`parent_id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='后台菜单表';
-- ----------------------------
-- Records of `tp_menu`
-- ----------------------------
BEGIN;
INSERT INTO `tp_menu` VALUES ('1', '0', 'index', 'auth', 'default', '', '0', '1', '系统管理', '', '', '10', '', '0', '', ''), ('2', '1', 'index', 'auth', 'default', '', '0', '1', '权限管理', '', '', '0', '', '0', '', ''), ('3', '2', 'index', 'auth', 'role', '', '1', '1', '角色管理', '', '', '0', '', '0', '', ''), ('4', '3', 'index', 'auth', 'roleAdd', '', '1', '0', '角色增加', '', '', '0', '', '0', '', ''), ('5', '3', 'index', 'auth', 'roleEdit', '', '1', '0', '角色编辑', '', '', '0', '', '0', '', ''), ('6', '3', 'index', 'auth', 'roleDelete', '', '1', '0', '角色删除', '', '', '0', '', '0', '', ''), ('7', '3', 'index', 'auth', 'authorize', '', '1', '0', '角色授权', '', '', '0', '', '0', '', ''), ('8', '1', 'index', 'auth', 'default', '', '0', '1', '菜单管理', '', '', '0', '', '0', '', ''), ('9', '8', 'index', 'auth', 'menu', '', '1', '1', '菜单列表', '', '', '0', '', '0', '', ''), ('10', '9', 'index', 'auth', 'menuAdd', '', '1', '0', '菜单增加', '', '', '0', '', '0', '', ''), ('11', '9', 'index', 'auth', 'menuEdit', '', '1', '0', '菜单修改', '', '', '0', '', '0', '', ''), ('12', '9', 'index', 'auth', 'menuDelete', '', '1', '0', '菜单删除', '', '', '0', '', '0', '', ''), ('13', '9', 'index', 'auth', 'menuOrder', '', '1', '0', '菜单排序', '', '', '0', '', '0', '', ''), ('14', '2', 'index', 'admin', 'index', '', '1', '1', '用户管理', '', '', '0', '', '0', '', '');
COMMIT;
SET FOREIGN_KEY_CHECKS = 1;

File diff suppressed because it is too large Load Diff

@ -0,0 +1,16 @@
html,
.help-block-error{color: #a94442;}
.nav{margin-bottom: 20px;margin-top: 20px;}
.table td {font-size: 12px;}
a{color: #1abc9c;}
.form-actions {padding: 19px 20px 20px;margin-top: 20px;margin-bottom: 20px;background-color: #f5f5f5;border-top: 1px solid #e5e5e5;}
.form-required{float: left;padding-top: 6px;padding-left: 4px;font-size: 18px;color: #e74c3c;}
.text{float: left;width: 300px;}
.width1{width: 100px}
.width2{width: 200px}
.width3{width: 300px}
.listOrder{height: 20px; border: 1px solid rgb(203, 208, 212); text-align: center; width: 40px; background-color: rgb(241, 241, 241);}
.toggle {text-align: center;}
.toggle img{cursor: pointer }
.span-text{float: left;padding-top: 9px;padding-left: 10px;padding-right: 10px;}

File diff suppressed because one or more lines are too long

@ -0,0 +1,148 @@
!function(a) {
//a标签post提交
$('.a-post').click(function(){
var msg =$(this).attr('post-msg');
if(msg){
if (!confirm(msg)){
return false;
}
}
var url =$(this).attr('post-url');
$.ajax(
{
url : url,
type : 'post',
dataType : 'json',
success : function (json)
{
if(json.code == 1){
$('#alert').html(alertSuccess(json.msg));
setTimeout(function() {
window.location.href=json.url;
},1000);
}else if(json.code == 0){
$('#alert').html(alertDanger(json.msg));
}
setTimeout(function() {
$('.close').click();
},3e3);
},
error:function(xhr){ //上传失败
$('#alert').html(alertDanger(xhr.responseText));
}
});
});
//form表达提交
$(".ajax-post").click(function(){
var data,ajaxCallUrl,postUrl;
d = $(this).parents('.form-horizontal');
postUrl = $(this).attr('post-url');
//按钮上的url优先
ajaxCallUrl = postUrl ? postUrl : d.attr('action');
$.ajax({
url : ajaxCallUrl,
type : 'post',
dataType : 'json',
data : d.serialize(),
success: function(json) {
if(json.code == 1){
$('#alert').html(alertSuccess(json.msg));
if (confirm('是否离开此页')){
window.location.href=json.url;
}
}else if(json.code == 0){
$('#alert').html(alertDanger(json.msg));
}
setTimeout(function() {
$('.close').click();
},3e3);
},
error:function(xhr){ //上传失败
$('#alert').html(alertDanger(xhr.responseText));
}
});
});
//按钮禁止
a(".ajax-post").on("click",
function() {
var b = a(this);
b.button("loading"),
setTimeout(function() {
b.button("reset");
},3e3)
});
$(".listOrder").focus(function ()
{
$('#alert').html(alertDanger('输入一个数字来更改排序'));
$(this).css("background-color", "#E93333");
}
);
$(".listOrder").blur(function(){
var url,id,order;
$(this).css("background-color", "#F1F1F1");
url = $('.listOrderUrl').val();
id = $(this).attr('data');
order = $(this).val();
$.ajax(
{
url : url,
type : 'post',
dataType : 'json',
data : 'id=' + id + '&order=' + order,
success : function (json)
{
if(json.code == 1){
$('#alert').html(alertSuccess(json.msg));
}else if(json.code == 0){
$('#alert').html(alertDanger(json.msg));
}
setTimeout(function() {
$('.close').click();
},3e3);
},
error:function(xhr){ //上传失败
$('#alert').html(alertDanger(xhr.responseText));
}
});
});
} (jQuery);
function alertSuccess(data){
return '<div class="alert alert-success" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'+data+'</div>';
}
function alertDanger(data){
return '<div class="alert alert-danger" role="alert" style="overflow-y: auto;max-height: 600px;"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'+data+'</div>';
}

File diff suppressed because one or more lines are too long

@ -0,0 +1,117 @@
<?php require $pach . 'public/top.php';?>
<style>
.checkmod{
margin-bottom:20px;
border: 1px solid #ebebeb;padding-bottom: 5px;
}
.checkmod dt{
padding-left:10px;
height:30px;
line-height:30px;
font-weight:bold;
border-bottom: 1px solid #ebebeb;
background-color:#ECECEC;
}
.checkmod dt{
margin-bottom: 5px;
border-bottom-color:#ebebeb;
background-color:#ECECEC;
}
.checkbox , .radio{
display:inline-block;
height:20px;
line-height:20px;
}
.checkmod dd{
padding-left:10px;
line-height:30px;
}
.checkmod dd .checkbox{
margin:0 10px 0 0;
}
.checkmod dd .divsion{
margin-right:20px;
}
.checkmod dt{
line-height:30px;
font-weight:bold;
}
.rule_check{border: 1px solid #ebebeb;margin: auto;padding: 5px 10px;}
.menu_parent{margin-bottom: 5px;}
</style>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li class="active"><a href="">{:input('name')}权限</a></li>
</ul>
<div class="cf well form-search" style="height: 58px;">
<p>★已选中的角色权限 <input checked="checked" type="checkbox">已选中的管理员权限</p>
</div>
<form class="form-horizontal" action="{:url('auth/adminAuthorize',['id'=>$info['id']])}" method="post">
<div class="table_full">
<table width="100%" cellspacing="0" id="dnd-example">
<tbody>
<?php echo $info['html']?>
</tbody>
</table>
</div>
<div class="form-actions">
<button type="button" class="btn btn-primary ajax-post " autocomplete="off">
保存
</button>
<a class="btn" href="JavaScript:history.go(-1)">返回</a>
</div>
</form>
</div>
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip();
})
</script>
<script type="text/javascript">
function checknode(obj) {
var chk = $("input[type='checkbox']");
var count = chk.length;
var num = chk.index(obj);
var level_top = level_bottom = chk.eq(num).attr('level');
for (var i = num; i >= 0; i--) {
var le = chk.eq(i).attr('level');
if (eval(le) < eval(level_top)) {
chk.eq(i).prop("checked",true);
var level_top = level_top - 1;
}
}
for (var j = num + 1; j < count; j++) {
var le = chk.eq(j).attr('level');
if (chk.eq(num).prop("checked")) {
if (eval(le) > eval(level_bottom)){
chk.eq(j).prop("checked",true);
}
else if (eval(le) == eval(level_bottom)){
break;
}
} else {
if (eval(le) > eval(level_bottom)){
chk.eq(j).prop("checked",false);
}else if(eval(le) == eval(level_bottom)){
break;
}
}
}
}
</script>
<?php require $pach . 'public/foot.php';?>

@ -0,0 +1,119 @@
<?php require $pach . 'public/top.php';?>
<style>
.checkmod{
margin-bottom:20px;
border: 1px solid #ebebeb;padding-bottom: 5px;
}
.checkmod dt{
padding-left:10px;
height:30px;
line-height:30px;
font-weight:bold;
border-bottom: 1px solid #ebebeb;
background-color:#ECECEC;
}
.checkmod dt{
margin-bottom: 5px;
border-bottom-color:#ebebeb;
background-color:#ECECEC;
}
.checkbox , .radio{
display:inline-block;
height:20px;
line-height:20px;
}
.checkmod dd{
padding-left:10px;
line-height:30px;
}
.checkmod dd .checkbox{
margin:0 10px 0 0;
}
.checkmod dd .divsion{
margin-right:20px;
}
.checkmod dt{
line-height:30px;
font-weight:bold;
}
.rule_check{border: 1px solid #ebebeb;margin: auto;padding: 5px 10px;}
.menu_parent{margin-bottom: 5px;}
</style>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
{if condition="checkPath('auth/role')"}
<li><a href="<?php echo url('auth/role')?>">角色管理</a></li>
{/if}
{if condition="checkPath('auth/roleAdd')"}
<li><a href="<?php echo url('auth/roleAdd')?>">增加角色</a></li>
{/if}
<li class="active"><a href="">权限设置</a></li>
</ul>
<form class="form-horizontal" action="{:Url('auth/authorize',['id'=>$info['id']])}" method="post">
<div class="table_full">
<table width="100%" cellspacing="0" id="dnd-example">
<tbody>
<?php echo $info['html']?>
</tbody>
</table>
</div>
<div class="form-actions">
<button type="button" class="btn btn-primary ajax-post " autocomplete="off">
保存
</button>
<a class="btn" href="JavaScript:history.go(-1)">返回</a>
</div>
</form>
</div>
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip();
})
</script>
<script type="text/javascript">
function checknode(obj) {
var chk = $("input[type='checkbox']");
var count = chk.length;
var num = chk.index(obj);
var level_top = level_bottom = chk.eq(num).attr('level');
for (var i = num; i >= 0; i--) {
var le = chk.eq(i).attr('level');
if (eval(le) < eval(level_top)) {
chk.eq(i).prop("checked",true);
var level_top = level_top - 1;
}
}
for (var j = num + 1; j < count; j++) {
var le = chk.eq(j).attr('level');
if (chk.eq(num).prop("checked")) {
if (eval(le) > eval(level_bottom)){
chk.eq(j).prop("checked",true);
}
else if (eval(le) == eval(level_bottom)){
break;
}
} else {
if (eval(le) > eval(level_bottom)){
chk.eq(j).prop("checked",false);
}else if(eval(le) == eval(level_bottom)){
break;
}
}
}
}
</script>
<?php require $pach . 'public/foot.php';?>

@ -0,0 +1,125 @@
<?php
$status = isset($info['status'])?$info['status']:'';
$type = isset($info['type'])?$info['type']:'';
?>
<div class="col-sm-12">
<table class="table table-bordered">
<tbody>
<tr>
<th class="col-sm-2">上级</th>
<th>
<select class="form-control text" name="parent_id">
<option value="0">/</option>
<?php echo isset($info['selectCategorys'])?$info['selectCategorys']:'';?>
</select>
</th>
</tr>
<tr>
<th>状态</th>
<td>
<input type="radio" name="status" <?php echo empty($status)|$status==1?'checked':''?> value="1" checked> 显示
<input type="radio" name="status" <?php echo $status === 0?'checked':''?> value="0"> 隐藏
</td>
</tr>
<tr>
<th>类型</th>
<td>
<input type="radio" name="type" <?php echo empty($type)|$type==1?'checked':''?> value="1" > 权限认证+菜单
<input type="radio" name="type" <?php echo $type === 0?'checked':''?> value="0"> 只作为菜单
</td>
</tr>
<tr>
<th>名称</th>
<td>
<input class="form-control text" type="text" name="name" value="<?php echo isset($info['name'])?$info['name']:'';?>">
<span class="form-required">*</span>
</td>
</tr>
<tr>
<th>应用</th>
<td>
<input class="form-control text" type="text" name="app" value="<?php echo isset($info['app'])?$info['app']:'';?>">
<span class="form-required">*</span>
</td>
</tr>
<tr>
<th>控制器</th>
<td>
<input class="form-control text" type="text" name="model" value="<?php echo isset($info['model'])?$info['model']:'';?>">
<span class="form-required">*</span>
</td>
</tr>
<tr>
<th>方法</th>
<td>
<input class="form-control text" type="text" name="action" value="<?php echo isset($info['action'])?$info['action']:'';?>">
<span class="form-required">*</span>
</td>
</tr>
<tr>
<th>参数</th>
<td>
<input class="form-control text" type="text" name="url_param" value="<?php echo isset($info['url_param'])?$info['url_param']:'';?>">
<span class="span-text">例:id=3&amp;cid=3</span>
</td>
</tr>
<tr>
<th>验证规则</th>
<td>
<input class="form-control text" type="text" name="rule_param" value="<?php echo isset($info['rule_param'])?$info['rule_param']:'';?>">
<span class="span-text">例:{id}==3 and {cid}==3</span>
</td>
</tr>
<tr>
<th>图标</th>
<td>
<input class="form-control text" type="text" name="icon" id="action" value="<?php echo isset($info['icon'])?$info['icon']:'';?>">
<span class="span-text"><a href="http://www.thinkcmf.com/font/icons" target="_blank">选择图标</a> 不带前缀fa-如fa-user => user</span>
</td>
</tr>
<tr>
<th>日志请求类型</th>
<td>
<select class="form-control text" name="request">
<option value="">关闭</option>
<?php
$type = ['GET','POST','PUT','PUT','DELETE','Ajax'];
$request = isset($info['request'])?$info['request']:'';
foreach($type as $v){
$selected = $request == $v ?'selected':'';
echo '<option '.$selected.' value="'.$v.'">'.$v.'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<th>日志请求类型</th>
<td>
<textarea name="log_rule" class="form-control" rows="3" ><?php echo isset($info['log_rule'])?$info['log_rule']:'';?></textarea>
</td>
</tr>
<tr>
<th>备注</th>
<td>
<textarea name="remark" class="form-control" rows="3" ><?php echo isset($info['remark'])?$info['remark']:'';?></textarea>
</td>
</tr>
</tbody>
</table>
</div>
<div class="form-actions col-sm-12">
<button type="button" class="btn btn-primary ajax-post " autocomplete="off">
保存
</button>
<a class="btn btn-default active" href="JavaScript:history.go(-1)">返回</a>
</div>

@ -0,0 +1,37 @@
<div class="form-group ">
<label class="col-lg-2 control-label" for="signupform-username">角色名称</label>
<div class="col-lg-3">
<input type="text" class="form-control" value="<?php echo isset($info['name'])?$info['name']:''?>" name="name" >
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">角色描述</label>
<div class="col-lg-3">
<textarea name="remark" class="form-control" rows="3"><?php echo isset($info['remark'])?$info['remark']:''?></textarea>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">状态 </label>
<div class="col-lg-3">
<?php
$status = isset($info['status'])?$info['status']:'';
?>
<label class="radio-inline">
<input type="radio" <?php echo empty($status)|$status==1?'checked':''?> name="status" value="1"> 开启
</label>
<label class="radio-inline">
<input type="radio" <?php echo $status === 0?'checked':''?> name="status" value="0"> 禁用
</label>
</div>
</div>
<div class="form-actions">
<button type="button" class="btn btn-primary ajax-post " autocomplete="off">
保存
</button>
<a class="btn btn-default active" onclick="history.go(-1)">返回</a>
</div>

@ -0,0 +1,67 @@
<?php require $pach . 'public/top.php';?>
<ul class="nav nav-tabs">
<li class="active"><a href="{:Url('auth/log')}">日志列表</a></li>
</ul>
<div>
<div class="cf well form-search" style="height: 68px;">
<form method="get">
<div class="fl">
<div class="btn-group">
<input name="username" class="form-control" value="{:input('username')}" placeholder="用户昵称" type="text">
</div>
<div class="btn-group">
<input name="userId" class="form-control" value="{:input('userId')}" placeholder="用户ID" type="text">
</div>
<div class="btn-group">
<input name="title" class="form-control" value="{:input('title')}" placeholder="标题" type="text">
</div>
<div class="btn-group">
<button type="submit" class="btn btn-success">查询</button>
</div>
</div>
</form>
<div class="fr">
<div class="btn-group">
{if condition="checkPath('auth/clear')"}
<button type="button" post-url="{:Url('auth/clear')}" class="btn ajax-post
btn-success">清空</button>
{/if}
</div>
</div>
</div>
<table class="table table-hover table-bordered table-list" id="menus-table">
<thead>
<tr>
<th width="100">ID</th>
<th>标题</th>
<th width="">用户</th>
<th width="">执行地址</th>
<th width="100">IP</th>
<th width="150">执行时间</th>
<th width="80">操作</th>
</tr>
</thead>
<tbody>
<?php foreach($list as $v) {?>
<tr>
<td>{$v.id}</td>
<td>{$v.title}</td>
<td>{$v.username}</td>
<td>{$v.log_url}</td>
<td>{$v.action_ip}</td>
<th>{:date('Y-m-d H:i:s',$v['create_time'])}</th>
<td>
{if condition="checkPath('auth/viewlog',['id'=>$v['id']])"}
<a href="{:url('auth/viewlog',['id'=>$v['id']])}">详细</a>
{/if}
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="text-center">
{$page}
</div>
<?php require $pach . 'public/foot.php';?>

@ -0,0 +1,38 @@
<?php require $pach . 'public/top.php';?>
<ul class="nav nav-tabs">
<li class="active"><a href="{:url('auth/menu')}">后台菜单</a></li>
{if condition="checkPath('auth/menuAdd')"}
<li><a href="{:url('auth/menuAdd')}">增加菜单</a></li>
{/if}
</ul>
<div class="cf well form-search" style="height: 68px;">
<div class="fl ">
<div class="btn-group">
<button type="button" post-url="{:url('auth/cache')}" class="btn ajax-post btn-success">清除日志缓存</button>
</div>
</div>
</div>
<table class="table table-hover table-bordered table-list" id="menus-table">
<thead>
<tr>
<th width="80">排序</th>
<th width="50">ID</th>
<th>菜单名称</th>
<th>应用</th>
<th>控制器</th>
<th>方法</th>
<th>日志请求</th>
<th width="80">状态</th>
<th width="180">操作</th>
</tr>
</thead>
<tbody>
<?php echo $info?>
</tbody>
</table>
<input type="hidden" value="{:url('auth/menuOrder')}" class="listOrderUrl">
<?php require $pach . 'public/foot.php';?>

@ -0,0 +1,13 @@
<?php require $pach . 'public/top.php';?>
<ul class="nav nav-tabs">
{if condition="checkPath('auth/menu')"}
<li><a href="{:url('auth/menu')}">后台菜单</a></li>
{/if}
<li class="active"><a href="{:url('auth/menuAdd')}">增加菜单</a></li>
</ul>
<form class="form-horizontal" action="{:url('auth/menuAdd')}" method="post">
<?php require $pach . 'form/form_menu.php';?>
</form>
<?php require $pach . 'public/foot.php';?>

@ -0,0 +1,16 @@
<?php require $pach . 'public/top.php';?>
<ul class="nav nav-tabs">
{if condition="checkPath('auth/menu')"}
<li><a href="{:url('auth/menu')}">后台菜单</a></li>
{/if}
{if condition="checkPath('auth/menuAdd')"}
<li><a href="{:Url('auth/menuAdd')}">增加菜单</a></li>
{/if}
<li class="active"><a href="">编辑菜单</a></li>
</ul>
<form class="form-horizontal" action="{:url('auth/menuEdit',['id'=>$info['id']])}" method="post">
<?php require $pach . 'form/form_menu.php';?>
</form>
<?php require $pach . 'public/foot.php';?>

@ -0,0 +1,6 @@
<script src="<?php echo get_file('js_cmsinfo.js')?>"></script>
</div>
</body>
</html>

@ -0,0 +1,35 @@
<!DOCTYPE html>
<?php
function get_file($file){
$directory = \think\Config::get('tp5auth.style_directory');
if(empty($directory)){
return url('auth/openFile',['file'=>$file]);
}else{
$file = strtr($file, '_', DS);
return $directory.$file;
}
}
?>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>后台操作系统</title>
<link href="<?php echo get_file('css_bootstrap.min.css')?>" rel="stylesheet">
<link href="<?php echo get_file('css_site.css')?>" rel="stylesheet">
<script src="<?php echo get_file('js_jquery.min.js')?>"></script>
<script src="<?php echo get_file('js_bootstrap.min.js')?>"></script>
</head>
<body style="min-width:790px;" >
<style>
.alert{
position: fixed !important;z-index: 1000;width: 98%;top: 2%;
}
</style>
<div class="container-fluid">
<div id="alert"></div>

@ -0,0 +1,61 @@
<?php require $pach . 'public/top.php';?>
<ul class="nav nav-tabs">
<li class="active"><a href="<?php echo Url('auth/role')?>">角色管理</a></li>
{if condition="checkPath('auth/roleAdd')"}
<li><a href="<?php echo Url('auth/roleAdd')?>">增加角色</a></li>
{/if}
</ul>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th width="30">ID</th>
<th align="left">角色名称</th>
<th align="left">角色描述</th>
<th width="50" align="left">状态</th>
<th width="160">操作</th>
</tr>
</thead>
<tbody>
<?php foreach($list as $v){?>
<tr>
<td>{$v.id}</td>
<td>{$v.name}</td>
<td>{$v.remark}</td>
<td>
<?php if($v['status']==1){ ?>
<font color="red"></font>
<?php }else{ ?>
<font color="red"></font>
<?php } ?>
</td>
<td>
<?php if($v['id']==1){ ?>
<font color="#cccccc">权限设置</font> |
<font color="#cccccc">编辑</font> |
<font color="#cccccc">删除</font>
<?php }else{ ?>
{if condition="checkPath('auth/authorize',['id'=>$v['id']])"}
<a href="<?php echo Url('auth/authorize',['id'=>$v['id']])?>">权限设置</a> |
{/if}
{if condition="checkPath('auth/roleEdit',['id'=>$v['id']])"}
<a href="<?php echo Url('auth/roleEdit',['id'=>$v['id']])?>">编辑</a> |
{/if}
{if condition="checkPath('auth/roleDelete',['id'=>$v['id']])"}
<a class="a-post" post-msg="你确定要删除吗" post-url="<?php echo Url('auth/roleDelete',['id'=>$v['id']])?>">删除</a>
{/if}
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php require $pach . 'public/foot.php';?>

@ -0,0 +1,19 @@
<?php require $pach . 'public/top.php';?>
<ul class="nav nav-tabs">
{if condition="checkPath('auth/role')"}
<li><a href="<?php echo Url('auth/role')?>">角色管理</a></li>
{/if}
<li class="active"><a href="<?php echo Url('auth/roleAdd')?>">增加角色</a></li>
</ul>
<div class="site-signup">
<div class="row">
<form class="form-horizontal" action="<?php echo Url('auth/roleAdd')?>" method="post" >
<?php require $pach . 'form/form_role.php';?>
</form>
</div>
</div>
<?php require $pach . 'public/foot.php';?>

@ -0,0 +1,19 @@
<?php include $pach . 'public/top.php';?>
<ul class="nav nav-tabs">
{if condition="checkPath('auth/role')"}
<li><a href="<?php echo Url('auth/role')?>">角色管理</a></li>
{/if}
{if condition="checkPath('auth/roleAdd')"}
<li><a href="<?php echo Url('auth/roleAdd')?>">增加角色</a></li>
{/if}
<li class="active"><a href="">角色修改</a></li>
</ul>
<div class="site-signup">
<div class="row">
<form class="form-horizontal" action="<?php echo Url('auth/roleEdit',['id'=>$info['id']])?>" method="post" >
<?php include $pach.'form/form_role.php';?>
</form>
</div>
</div>
<?php include $pach . 'public/foot.php';?>

@ -0,0 +1,69 @@
<?php require $pach . 'public/top.php';?>
<ul class="nav nav-tabs">
<li><a href="{:Url('auth/log')}">日志列表</a></li>
<li class="active"><a href="">日志详情</a></li>
</ul>
<div class="bs-example">
<table class="table table-bordered">
<tbody>
<tr>
<th>标题</th>
<th>
{$info.title}
</th>
</tr>
<tr>
<th>执行地址</th>
<th>
<a href="{$info.log_url}">{$info.log_url}</a>
</th>
</tr>
<tr>
<th width="150">执行者</th>
<td>
{$info.username}
</td>
</tr>
<tr>
<th width="150">执行IP</th>
<td>
{$info.action_ip}
</td>
</tr>
<tr>
<th>执行时间</th>
<td>
{:date('Y-m-d H:i:s',$info['create_time'])}
</td>
</tr>
<tr>
<th colspan="2" style="text-align: center">日志详情</th>
</tr>
<tr>
<td colspan="2">
{$info.log}
</td>
</tr>
</tbody>
</table>
</div>
<div class="form-actions col-sm-12">
<a class="btn btn-default active" href="JavaScript:history.go(-1)">返回</a>
</div>
<?php require $pach . 'public/foot.php';?>

@ -0,0 +1,208 @@
/*
Navicat MySQL Data Transfer
Source Server : localhost_3306
Source Server Version : 100119
Source Host : localhost:3306
Source Database : think
Target Server Type : MYSQL
Target Server Version : 100119
File Encoding : 65001
Date: 2017-11-25 16:20:30
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for tp_action_log
-- ----------------------------
DROP TABLE IF EXISTS `tp_action_log`;
CREATE TABLE `tp_action_log` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`user_id` int(10) NOT NULL DEFAULT '0' COMMENT '执行用户id',
`action_ip` bigint(20) NOT NULL COMMENT '执行行为者ip',
`log` longtext NOT NULL COMMENT '日志备注',
`log_url` varchar(255) NOT NULL COMMENT '执行的URL',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '执行行为的时间',
`username` varchar(255) NOT NULL COMMENT '执行者',
`title` varchar(255) NOT NULL COMMENT '标题',
PRIMARY KEY (`id`),
KEY `id` (`id`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='行为日志表';
-- ----------------------------
-- Records of tp_action_log
-- ----------------------------
-- ----------------------------
-- Table structure for tp_admin
-- ----------------------------
DROP TABLE IF EXISTS `tp_admin`;
CREATE TABLE `tp_admin` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '管理员自增ID',
`user_name` varchar(255) DEFAULT NULL COMMENT '用户名',
`user_password` varchar(255) DEFAULT NULL COMMENT '管理员的密码',
`user_nicename` varchar(255) DEFAULT NULL COMMENT '管理员的简称',
`user_status` int(11) DEFAULT '1' COMMENT '用户状态 0禁用 1正常 ',
`user_email` varchar(255) DEFAULT '' COMMENT '邮箱',
`last_login_ip` varchar(16) DEFAULT NULL COMMENT '最后登录ip',
`last_login_time` datetime DEFAULT NULL COMMENT '最后登录时间',
`create_time` datetime DEFAULT NULL COMMENT '注册时间',
`role` varchar(255) DEFAULT NULL COMMENT '角色ID',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=28 DEFAULT CHARSET=utf8 COMMENT='后台管理员表';
-- ----------------------------
-- Records of tp_admin
-- ----------------------------
INSERT INTO `tp_admin` VALUES ('1', 'admin', '21232f297a57a5a743894a0e4a801fc3', null, '1', 'admin@qq.com', '114.88.197.96', '2016-10-26 12:06:43', '2016-06-07 17:04:05', null);
INSERT INTO `tp_admin` VALUES ('16', 'zou', '21232f297a57a5a743894a0e4a801fc3', null, '1', 'zou1@qq.com', '127.0.0.1', '2016-07-17 17:01:36', '2016-07-08 15:29:41', '2');
INSERT INTO `tp_admin` VALUES ('23', 'sdasd', '0aa1ea9a5a04b78d4581dd6d17742627', null, '1', 'asdas@qq.com', null, null, '2016-11-15 16:55:36', '2,3');
INSERT INTO `tp_admin` VALUES ('27', 'tekin', '21232f297a57a5a743894a0e4a801fc3', null, '1', 'tekin@qq.com', null, null, '2017-01-18 21:14:40', '2');
-- ----------------------------
-- Table structure for tp_auth_access
-- ----------------------------
DROP TABLE IF EXISTS `tp_auth_access`;
CREATE TABLE `tp_auth_access` (
`role_id` mediumint(8) unsigned NOT NULL COMMENT '角色',
`rule_name` varchar(255) NOT NULL COMMENT '规则唯一英文标识,全小写',
`type` varchar(30) DEFAULT NULL COMMENT '权限规则分类,请加应用前缀,如admin_',
`menu_id` int(11) DEFAULT NULL COMMENT '后台菜单ID',
KEY `role_id` (`role_id`),
KEY `rule_name` (`rule_name`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='权限授权表';
-- ----------------------------
-- Records of tp_auth_access
-- ----------------------------
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/default', 'admin_url', '1');
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/default', 'admin_url', '8');
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/menu', 'admin_url', '9');
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/menuadd', 'admin_url', '10');
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/menuedit', 'admin_url', '11');
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/menudelete', 'admin_url', '12');
INSERT INTO `tp_auth_access` VALUES ('2', 'index/auth/menuorder', 'admin_url', '13');
-- ----------------------------
-- Table structure for tp_auth_role
-- ----------------------------
DROP TABLE IF EXISTS `tp_auth_role`;
CREATE TABLE `tp_auth_role` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL COMMENT '角色名称',
`pid` smallint(6) DEFAULT '0' COMMENT '父角色ID',
`status` tinyint(1) unsigned DEFAULT NULL COMMENT '状态',
`remark` varchar(255) DEFAULT NULL COMMENT '备注',
`create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`listorder` int(3) NOT NULL DEFAULT '0' COMMENT '排序字段',
PRIMARY KEY (`id`),
KEY `parentId` (`pid`),
KEY `status` (`status`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='角色表';
-- ----------------------------
-- Records of tp_auth_role
-- ----------------------------
INSERT INTO `tp_auth_role` VALUES ('1', '超级管理员', '0', '1', '拥有网站最高管理员权限!', '1329633709', '1329633709', '0');
INSERT INTO `tp_auth_role` VALUES ('2', '文章管理', '0', '1', '', '0', '0', '0');
INSERT INTO `tp_auth_role` VALUES ('3', '网管', '0', '1', '来一小时的', '0', '0', '0');
-- ----------------------------
-- Table structure for tp_auth_role_user
-- ----------------------------
DROP TABLE IF EXISTS `tp_auth_role_user`;
CREATE TABLE `tp_auth_role_user` (
`role_id` int(11) unsigned DEFAULT '0' COMMENT '角色 id',
`user_id` int(11) DEFAULT '0' COMMENT '用户id',
KEY `group_id` (`role_id`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='用户角色对应表';
-- ----------------------------
-- Records of tp_auth_role_user
-- ----------------------------
INSERT INTO `tp_auth_role_user` VALUES ('2', '16');
-- ----------------------------
-- Table structure for tp_auth_rule
-- ----------------------------
DROP TABLE IF EXISTS `tp_auth_rule`;
CREATE TABLE `tp_auth_rule` (
`menu_id` int(11) NOT NULL COMMENT '后台菜单 ID',
`module` varchar(20) NOT NULL COMMENT '规则所属module',
`type` varchar(30) NOT NULL DEFAULT '1' COMMENT '权限规则分类,请加应用前缀,如admin_',
`name` varchar(255) NOT NULL DEFAULT '' COMMENT '规则唯一英文标识,全小写',
`url_param` varchar(255) DEFAULT NULL COMMENT '额外url参数',
`title` varchar(20) NOT NULL DEFAULT '' COMMENT '规则中文描述',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否有效(0:无效,1:有效)',
`rule_param` varchar(300) NOT NULL DEFAULT '' COMMENT '规则附加条件',
`nav_id` int(11) DEFAULT '0' COMMENT 'nav id',
PRIMARY KEY (`menu_id`),
KEY `module` (`module`,`status`,`type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='权限规则表';
-- ----------------------------
-- Records of tp_auth_rule
-- ----------------------------
INSERT INTO `tp_auth_rule` VALUES ('2', 'index', 'admin_url', 'index/auth/default', '', '权限管理', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('3', 'index', 'admin_url', 'index/auth/role', '', '角色管理', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('4', 'index', 'admin_url', 'index/auth/roleadd', '', '角色增加', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('5', 'index', 'admin_url', 'index/auth/roleedit', '', '角色编辑', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('6', 'index', 'admin_url', 'index/auth/roledelete', '', '角色删除', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('7', 'index', 'admin_url', 'index/auth/authorize', '', '角色授权', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('8', 'index', 'admin_url', 'index/auth/menu', '', '菜单管理', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('9', 'index', 'admin_url', 'index/auth/menu', '', '菜单列表', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('10', 'index', 'admin_url', 'index/auth/menuadd', '', '菜单增加', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('11', 'index', 'admin_url', 'index/auth/menuedit', '', '菜单修改', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('12', 'index', 'admin_url', 'index/auth/menudelete', '', '菜单删除', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('13', 'index', 'admin_url', 'index/auth/menuorder', '', '菜单排序', '1', '', '0');
INSERT INTO `tp_auth_rule` VALUES ('14', 'index', 'admin_url', 'index/admin/index', '', '用户管理', '1', '', '0');
-- ----------------------------
-- Table structure for tp_menu
-- ----------------------------
DROP TABLE IF EXISTS `tp_menu`;
CREATE TABLE `tp_menu` (
`id` smallint(6) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增ID',
`parent_id` smallint(6) unsigned NOT NULL DEFAULT '0' COMMENT '父级ID',
`app` char(20) NOT NULL COMMENT '应用名称app',
`model` char(20) NOT NULL COMMENT '控制器',
`action` char(20) NOT NULL COMMENT '操作名称',
`url_param` char(50) NOT NULL COMMENT 'url参数',
`type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '菜单类型 1权限认证+菜单0只作为菜单',
`status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '状态1显示0不显示',
`name` varchar(50) NOT NULL COMMENT '菜单名称',
`icon` varchar(50) NOT NULL COMMENT '菜单图标',
`remark` varchar(255) NOT NULL COMMENT '备注',
`list_order` smallint(6) unsigned NOT NULL DEFAULT '0' COMMENT '排序ID',
`rule_param` varchar(255) NOT NULL COMMENT '验证规则',
`nav_id` int(11) DEFAULT '0' COMMENT 'nav ID ',
`request` varchar(255) NOT NULL COMMENT '请求方式(日志生成)',
`log_rule` varchar(255) NOT NULL COMMENT '日志规则',
PRIMARY KEY (`id`),
KEY `status` (`status`),
KEY `model` (`model`),
KEY `parent_id` (`parent_id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='后台菜单表';
-- ----------------------------
-- Records of tp_menu
-- ----------------------------
INSERT INTO `tp_menu` VALUES ('1', '0', 'index', 'auth', 'default', '', '0', '1', '系统管理', '', '', '10', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('2', '1', 'index', 'auth', 'default', '', '0', '1', '权限管理', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('3', '2', 'index', 'auth', 'role', '', '1', '1', '角色管理', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('4', '3', 'index', 'auth', 'roleAdd', '', '1', '0', '角色增加', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('5', '3', 'index', 'auth', 'roleEdit', '', '1', '0', '角色编辑', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('6', '3', 'index', 'auth', 'roleDelete', '', '1', '0', '角色删除', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('7', '3', 'index', 'auth', 'authorize', '', '1', '0', '角色授权', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('8', '1', 'index', 'auth', 'default', '', '0', '1', '菜单管理', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('9', '8', 'index', 'auth', 'menu', '', '1', '1', '菜单列表', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('10', '9', 'index', 'auth', 'menuAdd', '', '1', '0', '菜单增加', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('11', '9', 'index', 'auth', 'menuEdit', '', '1', '0', '菜单修改', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('12', '9', 'index', 'auth', 'menuDelete', '', '1', '0', '菜单删除', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('13', '9', 'index', 'auth', 'menuOrder', '', '1', '0', '菜单排序', '', '', '0', '', '0', '', '');
INSERT INTO `tp_menu` VALUES ('14', '2', 'index', 'admin', 'index', '', '1', '1', '用户管理', '', '', '0', '', '0', '', '');
Loading…
Cancel
Save