/** * 权限组列表 */ public function action_default() { $this->quick_menu = array('administrator/group/add' => '添加权限组', 'administrator/' => '管理员列表', 'administrator/add' => '添加管理员'); if (!$this->session()->member()->perm()->is_own('administrator.view_group_info')) { if ($this->session()->member()->perm()->is_own('administrator.can_edit_group')) { $groups = $this->session()->member()->groups(); } else { $this->message('抱歉,您无此权限'); } } $view = new View('admin/administrator/group_list'); if (isset($groups)) { $view->list = $groups; $view->group_manager = true; } else { if ($this->session()->member()->perm()->is_super_perm()) { # 超级管理员列出所有组 $project = null; } else { $project = Core::$project; } $model_administrator = new Model_Admin_Administrator(); $count = $model_administrator->total_group_count($project); if ($count) { $pageconfig = Core::config('admin/pagination'); $pageconfig['total_items'] = $count; $pagination = new Pagination($pageconfig); $list = $model_administrator->get_group_list($project, $pagination->get_offset(), $pagination->get_items_per_page()); $view->list = $list; $view->pagehtml = $pagination->render(); } } $view->render(); }
protected function save(ORM_Admin_Member_Data $member) { try { if (!$member->id > 0) { # 创建新用户 if (!$_POST['username']) { throw new Exception('用户名不能空', -1); } if (!$_POST['new_password']) { throw new Exception('密码不能空', -1); } if ($_POST['new_password'] != $_POST['new_password_2']) { throw new Exception('两次输入的密码不一致,请重新确认', -1); } $model_admin = new Model_Admin_Administrator(); if ($model_admin->get_by_username($_POST['username'])) { throw new Exception('此用户名已存在,请换一个', -1); } } $member->nickname = $_POST['nickname']; $setting = HttpIO::POST('setting'); # 修改权限模式 if ($this->show_edit_perm) { # _group_admin 保留项 if (isset($setting['_group_admin'])) { unset($setting['_group_admin']); } # 修改权限 $this->change_member_perm($member); } elseif (!$member->id > 0) { $member->perm_setting = null; } if ($setting) { if ($member->setting) { $member->setting = array_merge($member->setting, $setting); } else { $member->setting = $setting; } } # 修改用户其它信息 $this->change_member_other_info($member); $tr = $member->orm()->db()->transaction(); $tr->start(); try { # 保存数据 if ($member->id > 0) { $is_add = false; # 修改用户 $member->update(); } else { $is_add = true; # 设置用户名 $member->username = $_POST['username']; # 密码,在更新数据时会由ORM进行加密处理 $member->password = $_POST['new_password']; # 所属项目 $member->project = Core::$project; # 锁定=否 $member->shielded = 0; # 插入用户数据 $member->insert(); } if ($this->show_edit_perm) { # 保存组权限设置 $this->save_member_group_perm($member, $is_add); } $tr->commit(); $msg = '操作成功'; $code = 1; } catch (Exception $e) { $tr->rollback(); throw $e; } } catch (Exception $e) { $code = $e->getCode(); $msg = $e->getMessage(); } $this->message($msg, $code); }