/** * 保存管理员用户 */ public function saveAction() { $id = $this->dispatcher->getParam('id'); $isNew = true; if (!empty($id)) { $isNew = false; } // update if ($this->request->isPost()) { $postData = array('username' => $this->request->getPost('username'), 'password' => $this->request->getPost('password'), 'email' => $this->request->getPost('email'), 'phone' => $this->request->getPost('phone'), 'createTime' => time(), 'status' => $this->request->getPost('status', 'int'), 'groupId' => $this->request->getPost('groupId', 'int'), 'truename' => $this->request->getPost('truename')); if (empty($postData['groupId'])) { $this->displayAjax(false, '请选择用户所属用户角色分组'); } elseif (is_null($postData['password']) && $isNew) { // 新增无密码 $this->displayAjax(false, '新增用户必须填入密码'); } if (!empty($postData['password'])) { $postData['salt'] = rand(100000, 999999); $postData['password'] = md5(md5($postData['password']) . $postData['salt']); } if ($isNew) { // 新增 // 判断账户是否存在 $hasUser = Users::count(array("username = :username: ", 'bind' => array('username' => $username))); if ($hasUser) { $this->displayAjax(false, '用户已存在无法新增!'); } $user = new Users(); } else { // 更新 $user = Users::findFirst($id); if (!$user) { $this->displayAjax(false, '您要更新的账户不存在!'); } } if ($user->save($postData) == false) { $this->displayAjax(false, join($user->getMessages(), '<br>')); } $this->displayAjax(true); } $this->assign('id', $id); if (!$isNew) { $this->assign('model', Users::findFirst($id)); } $this->assign('groups', Groups::find()); }
public function saveAction($gid = null) { if ($this->request->isPost()) { $postData = array('parent_id' => $this->request->getPost('parent_id'), 'gname' => $this->request->getPost('gname'), 'rightList' => join(',', array_unique($this->request->getPost('rights')))); if ($gid) { $group = Groups::findFirst(array('gid = :gid:', 'bind' => array('gid' => $gid))); if (!$group) { $this->displayAjax(false, '未找到您要修改的信息'); } } else { $group = new Groups(); } if ($group->save($postData) == false) { $this->displayAjax(false, join($group->getMessages(), '<br>')); } $this->displayAjax(true, '', array('redirect_url' => $this->url->get('Admin/Roles/index'))); } if ($gid) { $group = Groups::findFirst(array('gid = :gid:', 'bind' => array('gid' => $gid))); $this->assign('groupRight', explode(',', $group->rightList)); $this->assign('data', $group); } // 加载所有分组 $this->assign('groupList', Groups::find()); // 加载所有权限资源 $rightData = Rights::find(); $rightArray = array(); $rightUndefined = array(); foreach ($rightData as $key => $item) { preg_match('/\\[.*?\\]/', $item->name, $localPre); if (isset($localPre[0])) { $arrayKey = trim($localPre[0], '[]'); $rightArray[$arrayKey][] = $item; } else { $rightUndefined[] = $item; } } $this->assign('rightArray', $rightArray); // []中匹配正确的权限资源 $this->assign('rightUndefined', $rightUndefined); // 未被定义的权限资源 }