/** * 管理员添加 */ public function actionAdd() { if (Yii::app()->request->isPostRequest) { $oldadmin = IMAdmin::model()->find(array('order' => 'id DESC', 'limit' => 1)); $data = Yii::app()->request->getPost('data'); if ($oldadmin->pwd == md5($data['oldpwd'])) { if ($data['newpwd1'] == $data['newpwd2']) { $oldadmin->uname = $data['uname']; $oldadmin->pwd = md5($data['newpwd1']); $oldadmin->updated = time(); if ($oldadmin->update()) { $this->showAlert('success', '操作成功'); $this->getAdminCache(); } else { $this->showAlert('fail', '操作失败'); echo $admin->getErrors(); } } else { $this->showAlert('fail', '2次密码不一致'); } } else { $this->showAlert('fail', '原始密码错误'); } } $this->render('add', array()); }
/** * 获取管理员缓存 */ public function getAdminCache() { $adminInfo = IMAdmin::model()->findAll(array('condition' => 'status = 0')); if (empty($adminInfo)) { $adminInfo = new IMAdmin(); $adminInfo->uname = Yii::app()->params['defaultAdminUname']; $adminInfo->pwd = md5(Yii::app()->params['defaultAdminPwd']); $adminInfo->status = 0; $adminInfo->created = time(); if ($adminInfo->save()) { $cache['id'] = $adminInfo->id; $cache['uname'] = $adminInfo->uname; $cache['pwd'] = $adminInfo->pwd; if (!empty($cache)) { Yii::app()->cache->set('cache_admininfo', $cache); } return $cache; } } foreach ($adminInfo as $k => $v) { $cache[$k]['id'] = $v->id; $cache[$k]['uname'] = $v->uname; $cache[$k]['pwd'] = $v->pwd; } if (!empty($cache)) { Yii::app()->cache->set('cache_admininfo', $cache); } return $cache; }