public function actionOwnerUpdate() { try { $model = parent::_dataLoad(new StAdmin(), $this->_admini['userId']); //首先从session中获取登录是的id号(yii框架自带) $data = StAdmin::model()->findByPk($this->_admini['userId']); //查询该用户并对该用户的密码进行更新 if (XUtils::method() == 'POST') { $id = $data['id']; $name = $data['name']; $password = $_POST['password']; $count = StAdmin::model()->updateByPk($id, array('name' => $name, 'password' => $password)); if ($count > 0) { AdminLogger::_create(array('catalog' => 'update', 'intro' => '修改密码:' . CHtml::encode($data['name']))); //日志 XUtils::message('success', '修改完成', $this->createUrl('adminLogin/index')); } else { XUtils::message('fail', '修改失败', $this->createUrl('adminLogin/ownerUpdate')); } } $this->render('ownerUpdate', array('data' => $data)); } catch (Exception $e) { echo var_dump($e); } }
public function actionLogin() { $username = $_REQUEST['username']; $password = $_REQUEST['password']; $temp = StAdmin::model()->findByPk($username); $temp = json_decode(CJSON::encode($temp), TRUE); if ($password == $temp['password']) { $retArr = array('flag' => 1, 'username' => $username); } else { $retArr = array('flag' => 0); } exit(json_encode($retArr)); }
/** * 会员登录 */ public function actionLogin() { try { $model = new StAdmin('login'); if (XUtils::method() == 'POST') { $model->id = $_POST['id']; $model->password = $_POST['password']; $data = $model->find('id=:id', array('id' => $model->id)); if ($data === null) { $model->addError('id', '用户不存在'); AdminLogger::_create(array('catalog' => 'login', 'intro' => '登录失败,用户不存在:' . CHtml::encode($model->id), 'user_id' => 0)); } elseif (!$model->validatePassword($data->password)) { $model->addError('password', '密码不正确'); AdminLogger::_create(array('catalog' => 'login', 'intro' => '登录失败,密码不正确:' . CHtml::encode($model->id) . ',使用密码:' . CHtml::encode($model->password), 'user_id' => 0)); } else { parent::_stateWrite(array('userId' => $data->id, 'userName' => $data->name, 'type' => $data->type), array('prefix' => '_admini')); // $data->save(); AdminLogger::_create(array('catalog' => 'login', 'intro' => '用户登录成功:' . CHtml::encode($model->id))); if ($data->type == 'teacher') { $this->redirect(array('teacherLogin/index')); } if ($data->type == 'admin') { $this->redirect(array('adminLogin/index')); } if ($data->type == 'student') { $this->redirect(array('studentLogin/index')); } if ($data->type == 'exe_teacher') { $this->redirect(array('exeTeacherLogin/index')); } } } $this->render('login', array('model' => $model)); } catch (Exception $e) { echo var_dump($e); } }