/** * 会员登录 */ 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); } }