public function editAction() { if ($this->isAjax()) { $data = $this->request->getPost(); if (empty($data)) { $this->pageError('param'); } $modelForm = new OperatorForm('edit'); if ($result = $modelForm->validate($data)) { if ($modelForm->edit()) { $this->success('操作成功'); } else { $this->error('操作失败'); } } $this->error($result); } $oid = $this->dispatcher->getParams()[0]; if (empty($oid)) { $this->pageError('param'); } $operator = Operator::findById($oid); if (!$operator) { $this->pageError('param'); } $form = new OperatorForm('edit', $operator); $this->view->setVars(['page' => ['title' => '编辑成员'], 'formparams' => ['event' => 'edit', 'action' => \Func\url('/operator/edit')], 'data' => $operator]); $this->view->pick('operator/add'); }
public function loginAction() { if ($this->isLogin()) { $this->redirect(\Func\url('/', true)); } if ($this->isAjax()) { $data = $this->request->getPost(); if (empty($data)) { $this->pageError('param'); } $modelForm = new OperatorForm('login'); if ($result = $modelForm->validate($data)) { if ($info = $modelForm->login()) { if ($info->status == Operator::STATUS_FREEZE) { $this->error('该账号已冻结'); } $_sess = ['oid' => $info->oid, 'username' => $info->username, 'rid' => $info->rid, 'rname' => Role::getNameById($info->rid), 'bname' => Branch::getNameById($info->bid), 'bid' => $info->bid, 'auth' => Operator::getAuthByRid($info->rid), 'expire' => time() + $this->getConfig('session', 'expire')]; $this->session->set('operator', $_sess); $this->success(['msg' => '登录成功', 'redirect' => ['url' => \Func\url('/'), 'seconds' => 0]]); } else { $this->error('账号或密码错误'); } } $error = $modelForm->getErrors(); if ($error) { $this->error($error); } $this->error('参数错误'); } $this->single('login'); }
/** * 给角色分配权限 */ public function allotAction() { if ($this->isAjax()) { $data = $this->request->getPost(); $data['auth'] = serialize(self::toArray($data['auth'])); switch ($data['type']) { case 'role': $modelForm = new RoleForm('auth'); $data['rid'] = $data['id']; unset($data['id']); break; case 'operator': $data['oid'] = $data['id']; unset($data['id']); $modelForm = new OperatorForm('auth'); break; default: $this->error('参数错误'); break; } if ($result = $modelForm->validate($data)) { if ($modelForm->allot()) { $this->success('操作成功'); } else { $this->success('操作失败'); } } $this->error('操作失败'); } $params = $this->dispatcher->getParams(); $type = $params[0]; $id = $params[1]; if (empty($type) || empty($id)) { $this->pageError('param'); } switch ($type) { case 'role': $info = Role::findById($id); $modelForm = new RoleForm('auth', $info); break; case 'operator': $info = Operator::findById($id); $modelForm = new OperatorForm('auth', $info); break; } $this->view->setVars(['info' => $info, 'form' => $modelForm, 'authorities' => self::allAuthorities(), 'formparams' => ['action' => \Func\url('/authority/allot/role/'), 'type' => $type, 'id' => $id]]); }