LoginAction.class.php public function doLogin(){
if(!empty($_GET['username']) && !empty($_GET['password'])){
$username=$_GET['username'];
$password=$_GET['password'];
//实例化 user 模型类
$user=M('User');
$condition['username']=$username;
$condition['password']=md5($password);
//执行查询操作
$arr=$user->where($condition)->find();
if($arr)
{
if($arr['status'] == -1) $this->error('该用户已被管理员禁止,请联系管理员~');
else
{
session('username',$username);
session('uid',$arr['id']);
session(C('USER_AUTH_KEY'),$arr['id']);
if($_SESSION['username']==C('RBAC_SUPERADMIN')){
session(C('ADMIN_AUTH_KEY'),true);
}
//RBAC
import('ORG.Util.RBAC');
RBAC::saveAccessList();
$counter = $arr['counter']+1;
$user->where('id='.$arr['id'])->setField('counter',$counter);
//设置成功后跳转页面的地址,默认的返回页面是$_SERVER['HTTP_REFERER']
$this->success("<script>alert('登录成功');window.location = \"".U('Admin/index/main')."\";</script>",'',60);
}
}
else $this->error('密码错误',U('Admin/Login/index'));
}
else
$this->show("<script>alert('用户名和密码不能为空');window.location = \"".U('Admin/Login/index')."\";</script>");
}
<?php
class CommonAction extends Action{
public function _initialize(){
/*import('ORG.Util.Auth');
$auth = new Auth();
if(!$auth->check(GROUP_NAME.'/'.MODULE_NAME.'/'.ACTION_NAME,session('uid'))){
$this->error('你没有权限');
}*/
if(!isset($_SESSION[C('USER_AUTH_KEY')])){
$this->redirect('login/index');
}
// RBAC认证
$notAuth=in_array(MODULE_NAME, explode(',', C('NOT_AUTH_MODULE')))||in_array(ACTION_NAME, explode(',', C('NOT_AUTH_ACTION')));
if(C('USER_AUTH_ON')&&!$notAuth){
import('ORG.Util.RBAC');
if(!RBAC::AccessDecision()){
$this->error('没有权限');
}else{
echo MODULE_NAME.'-'.ACTION_NAME.'有权限';
}
}
}
}
//RBAC认证配置信息
'RBAC_SUPERADMIN' =>'admin',//超级管理员名称,对应用户表中某一个用户名
'ADMIN_AUTH_KEY' =>'superadmin',//超级管理员识别标识
'USER_AUTH_ON' => true,//是否需要认证
'USER_AUTH_TYPE'=> 1,//认证类型 1登录后才认证 2实时认证
'USER_AUTH_KEY'=>'authid', //认证识别号,此名称可以自己取
// 'REQUIRE_AUTH_MODULE'=> //需要认证模块
'NOT_AUTH_MODULE'=>'Index,Login', //无需认证模块 和上面重复
'NOT_AUTH_ACTION'=>'addRoleHandle', //无需认证操作
// 'USER_AUTH_GATEWAY'=>'Login/doLogin', //认证网关,此处可以不用
// 'RBAC_DB_DSN'=>'mysql', //数据库连接DSN
'RBAC_ROLE_TABLE'=>'think_role', //角色表名称
'RBAC_USER_TABLE'=>'think_role_user', //用户表名称
'RBAC_ACCESS_TABLE'=>'think_access', //权限表名称
'RBAC_NODE_TABLE'=>'think_node', //节点表名称
最佳答案