使用RBAC,若用户表名不是user怎么办?

浏览:924 发布日期:2013/09/22 分类:求助交流
下面是TP官方给出的登录例子,默认用户表名是 前缀_user,而我有2个用户表名,分别是:前缀_user_student,前缀_user_parents,都要用到RBAC控制权限,该怎么办呢?     public function login()
    {

        if(empty($_POST['account'])) {
            $this->error('帐号错误!');
        }elseif (empty($_POST['password'])){
            $this->error('密码必须!');
        }elseif (empty($_POST['verify'])){
            $this->error('验证码必须!');
        }
        //生成认证条件
        $map            =   array();
        // 支持使用绑定帐号登录
        $map['account']    = $_POST['account'];
        $map["status"]    =    array('gt',0);
        if($_SESSION['verify'] != md5($_POST['verify'])) {
            $this->error('验证码错误!');
        }
        import ( '@.ORG.Util.RBAC' );
        $authInfo = RBAC::authenticate($map);
        //使用用户名、密码和状态的方式进行认证
        if(false === $authInfo) {
            $this->error('帐号不存在或已禁用!');
        }else {
            if($authInfo['password'] != md5($_POST['password'])) {
                $this->error('帐号或密码错误!');
            }
            $_SESSION[C('USER_AUTH_KEY')]    =    $authInfo['id'];
            $_SESSION['email']                =    $authInfo['email'];
            $_SESSION['loginUserName']        =    $authInfo['nickname'];
            $_SESSION['lastLoginTime']        =    $authInfo['last_login_time'];
            $_SESSION['login_count']        =    $authInfo['login_count'];
            if($authInfo['account']=='sysadmin') {
                $_SESSION['administrator']    =    true;
            }
            //保存登录信息
            $User    =    M('User');
            $ip        =    get_client_ip();
            $time    =    time();
            $data = array();
            $data['id']                        =    $authInfo['id'];
            $data['last_login_time']        =    $time;
            $data['login_count']            =    array('exp','login_count+1');
            $data['last_login_ip']            =    $ip;
            $User->save($data);

            // 缓存访问权限
            RBAC::saveAccessList();
            //dump($_SESSION);
            //die();
            $this->success('登录成功!');
        }
    }
学生家长
最佳答案
评论( 相关
后面还有条评论,点击查看>>