示例#1
0
 public function _initialize()
 {
     C('FRAME_ACTIVE', 'access');
     C('FRAME_CURRENT', U('control/user/list'));
     $this->acl = new Acl();
     $this->roles = $this->acl->getRoles(true);
     $this->assign('roles', $this->roles);
 }
 public function rolesAction()
 {
     $roles = $this->acl->getRoles(true);
     $roles = coll_key($roles, 'id');
     $id = I('get.id');
     if (!empty($id)) {
         $id = intval($id);
         if ($id > 0) {
             $role = $roles[$id];
             $this->assign('entity', $role);
             if (!empty($role)) {
                 if (I('get.do') == 'delete') {
                     if ($this->acl->removeRole($id)) {
                         $this->success('成功删除用户组', U('control/acl/roles'));
                         exit;
                     } else {
                         $this->error('操作失败, 请稍后重试');
                     }
                 }
             }
         }
         if (IS_POST) {
             $input = coll_elements(array('title', 'status', 'remark'), I('post.'));
             $input['title'] = trim($input['title']);
             if (empty($input['title'])) {
                 $this->error('请输入用户组名称');
             }
             $input['status'] = $input['status'] == '-1' ? '-1' : '0';
             $input['parent'] = '0';
             if (!empty($role)) {
                 //编辑组
                 $ret = $this->acl->table('__USR_ROLES__')->data($input)->where("`id`={$id}")->save();
                 if (empty($ret)) {
                     $this->error('保存用户组失败, 请稍后重试');
                 } else {
                     $this->success('成功保存用户组', U('control/acl/roles'));
                     exit;
                 }
             } else {
                 //新增组
                 $ret = $this->acl->table('__USR_ROLES__')->data($input)->add();
                 if (empty($ret)) {
                     $this->error('保存新增用户组失败, 请稍后重试');
                 } else {
                     $this->success('成功新增用户组', U('control/acl/roles'));
                     exit;
                 }
             }
         }
     }
     $this->assign('roles', $roles);
     $this->display();
 }
 public function run(&$params)
 {
     $module = MODULE_NAME;
     $controller = CONTROLLER_NAME;
     $action = ACTION_NAME;
     if (in_array($module, array('Wander', 'Api'))) {
         return;
     }
     session_start();
     $user = session('user');
     if (!empty($user)) {
         $session = array();
         $session['USER'] = array_change_key_case($user, CASE_UPPER);
         $acl = new Acl();
         $roles = $acl->getRoles();
         $roles = coll_key($roles, 'id');
         $role = $roles[$user['role']];
         if (empty($role)) {
             $role = $roles[0];
         }
         $role = coll_elements(array('id', 'title'), $role);
         $session['ROLE'] = array_change_key_case($role, CASE_UPPER);
         $session['ACL'] = array();
         C('SESSION', $session);
     }
     //无用户身份, 只能访问Wander
     if ((empty($session) || empty($session['USER'])) && !in_array($module, array('Wander', 'Api'))) {
         redirect(U('/wander/account/login?forward=' . base64_encode($_SERVER['REQUEST_URI'])));
         exit;
     }
 }