增强了auth功能与auth结构化,具体详细功能代码tper手动实现吧
// 角色表
create table `task_auth_group` (
`id` mediumint(8) unsigned not null auto_increment,// 角色id
`title` char(100) not null default '', // 角色名称
`status` tinyint(1) not null default '1', // 角色状态 1:开启 2:关闭
`rules` char(80) not null default '', // 角色拥有的权限规则id 多权限规则id用 , 连接
primary key (`id`) //设定为主键
) engine=myisam auto_increment=1 default charset=utf8
// 用户权限表
create table `task_auth_group_access` (
`uid` mediumint(8) unsigned not null, // 对应用户id
`group_id` mediumint(8) unsigned not null, // 对应角色id
unique key `uid_group_id` (`uid`,`group_id`), // 唯一索引组
key `uid` (`uid`), // 普通索引
key `group_id` (`group_id`) // 普通索引
) engine=myisam default charset=utf8
// 权限规则表 支持条件规则
create table `task_auth_rule` (
`id` mediumint(8) unsigned not null auto_increment, // 规则id 自增
`name` char(80) not null default '', // 权限规则标识
`title` char(20) not null default '', // 权限规则名称
`type` tinyint(1) not null default '1', // 权限规则类型 1:url 2:菜单(不知道这个干啥用的)
`status` tinyint(1) not null default '1', // 权限规则状态 1:开启 2:关闭
`condition` char(100) not null default '', // 权限规则条件
`mid` int(10) unsigned not null default '1', // 权限所属模块id
`level` tinyint(1) unsigned not null default '0', // 菜单等级 0:不为菜单 1:左侧菜单 2:顶部菜单 3:底部菜单
primary key (`id`), // 设定主键为id
unique key `name` (`name`) // 唯一索引
) engine=myisam auto_increment=7 default charset=utf8
// 模块表
create table `task_modules` (
`id` int(10) unsigned not null auto_increment, // 模块id 自增
`name` varchar(20) not null, // 模块标识
`title` varchar(20) not null, // 模块名称
`level` tinyint(1) unsigned not null default '1', // 模块等级 1:应用 2:控制器
`pid` tinyint(1) unsigned not null default '0', // 模块上级id 0:应用 1:控制器
primary key (`id`) // 设定主键id
) engine=myisam auto_increment=8 default charset=utf8
//用户表
create table `task_user` (
`id` int(10) unsigned not null auto_increment comment '用户id',
`username` varchar(20) not null comment '用户登录名',
`password` varchar(32) not null comment '用户登录密码',
`name` varchar(20) not null default '0' comment '用户昵称',
`qq` varchar(15) not null default '0' comment '用户qq',
`tel` varchar(11) not null default '0' comment '用户电话',
`logindate` int(10) unsigned not null default '0' comment '登录时间',
`createdate` int(10) unsigned not null default '0' comment '创建用户时间',
`loginnums` int(10) unsigned not null default '0' comment '用户登录次数',
primary key (`id`),
unique key `username` (`username`)
) engine=myisam auto_increment=3 default charset=utf8
thinkphp公用控制器代码
error('对不起,你还未登陆!',u('login/index'));
}
//获取左侧菜单
$this->assign(menu,menu(1));
//超级管理员免验证
if($sess_auth['id'] == c(administrator)){
return true;
}
$auth = new auth();
//检查普通用户权限
if(!$auth->check(module_name.'/'.controller_name.'/'.action_name,$sess_auth['id'])){
$this->error(没有权限);
}
}
}
thinkphp 公用函数文件
getgroups(session(auth)['id']);
$rules = explode(,,$tmp_rules[0]['rules']);
foreach($rules as $k){
$rule = m(auth_rule)->find($rules[$k]);
if($rule['level'] == $level){
$menu[] = $rule;
}
}
} else {
$rules = m(auth_rule)->where(array('level'=>$level))->field(id,level)->select();
foreach($rules as $k => $v){
$rule = m(auth_rule)->find($v['id']);
if($rule['level'] == $level){
$menu[] = $rule;
}
}
}
return $menu;
}
ad:真正免费,域名+虚机+企业邮箱=0元