Ejemplo n.º 1
0
 /**
  * 编辑角色
  */
 public function actionEdit()
 {
     $funcData = $this->getFuncsData();
     $role_id = $this->helpGquery('role_id');
     $role = Roles::getById($role_id);
     $role_func_list = Role_Purview::getByRoleId($role_id);
     $role_func_data = [];
     foreach ($role_func_list as $k => $v) {
         $func_id = $v['func_id'];
         $role_func_data[$func_id] = $v;
     }
     $data = array('role' => $role, 'funcData' => $funcData, 'role_func_data' => $role_func_data);
     return $this->render('edit', $data);
 }
Ejemplo n.º 2
0
 /**
  * 保存
  */
 public function actionSave()
 {
     $data = $this->helpGpost('users');
     extract($data);
     if (empty($login_name)) {
         $this->helpJsRedirect('请输入登录名');
     }
     $role_id = $this->helpGpost('role_id', 0);
     $user_id = 0;
     if (($id = intval($id)) > 0) {
         $ret = Users::updateUser($id, $login_name, $real_name, $email, $this->user_group_id, $phone);
         $user_id = $id;
     } else {
         if (empty($password)) {
             $this->helpJsRedirect('请输入初始密码');
         }
         $password2 = $this->helpGpost('password2');
         if ($password != $password2) {
             $this->helpJsRedirect('两次密码输入不一致');
         }
         //新增
         $ret = Users::addUser($login_name, $password, $real_name, $email, $this->user_group_id, $phone);
         $user_id = $ret;
     }
     if (empty($ret)) {
         $this->helpJsRedirect('操作失败');
     }
     if ($role_id && $user_id) {
         //保存用户角色关联
         User_Role_Relate::delByUid($user_id);
         User_Role_Relate::addRelate($role_id, $user_id);
         //删除用户所有权限
         User_Purview::delByUid($user_id);
         $role_purview = Role_Purview::getByRoleId($role_id);
         if (count($role_purview) > 0) {
             $rows = [];
             foreach ($role_purview as $k => $v) {
                 $func_id = $v['func_id'];
                 $rows[] = [$user_id, $func_id];
             }
             User_Purview::batchAddPurview(['user_id', 'func_id'], $rows);
         }
     }
     $url = Url::toRoute('user/index');
     $this->redirect($url);
 }
Ejemplo n.º 3
0
 public function getMyFunc()
 {
     $user_id = $this->getId();
     $myFunc = array();
     //获取角色权限
     $func_ids = [];
     $myRoles = User_Role_Relate::getByUid($user_id);
     if (!empty($myRoles)) {
         foreach ($myRoles as $role) {
             $rolePurviews = Role_Purview::getByRoleId($role['role_id']);
             foreach ($rolePurviews as $rolePurview) {
                 $func_ids[] = $rolePurview['func_id'];
             }
         }
     }
     //获取用户权限
     $userPurviews = User_Purview::getByUid($user_id);
     if (!empty($userPurviews)) {
         foreach ($userPurviews as $purview) {
             $func_ids[] = $purview['func_id'];
         }
     }
     $condition = ['id' => $func_ids];
     $myFunc = Func::search($condition, 0, 0, array('id' => SORT_ASC), false, 'id');
     return $myFunc['list'];
 }