[ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => ['login', 'error', 'logout'], 'allow' => true, ], [ 'actions' => ['logout', 'index', 'logout-yii'], 'allow' => true, 'roles' => ['@'], ], ], ], ]; } /** * @inheritdoc */ public function actions() { return [ // 'error' => [ // 'class' => 'yii\web\ErrorAction', // 'view' => '@backend/views/site/error.php' // ], ]; } /** * Displays homepage. * * @return string */ public function actionIndex() { return $this->goHome(); } /** * Login action. * * @return string */ public function actionLogin() { $uri = explode('.', $_SERVER['HTTP_HOST']); $sub_domain = $uri[0]; if ($sub_domain !== 'hotel') { //域名不是酒店,都跳转到cs登录 return $this->redirect('http://' . CS_DOMAIN); } else { $this->layout = 'full'; if (!Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { $cookies = Yii::$app->response->cookies; $cookies->add(new \yii\web\Cookie([ 'name' => 'home_page_show', 'value' => 'hide', ])); $cookies->add(new \yii\web\Cookie([ 'name' => 'user_id', 'value' => Yii::$app->user->id, ])); return $this->goHome(); } else { if(Yii::$app->request->isPost) Yii::$app->session->setFlash('error', $model->getFirstErrors()); return $this->render('login', [ 'model' => $model, ]); } } } /** * Logout action. * 退出后,全部跳转到cs的登录页 * * @return string|null */ public function actionLogout($cs = '') { if(Yii::$app->user->identity != null) Yii::$app->user->logout(); $session = Yii::$app->session; $session->destroy(); if($cs === '') return $this->redirect('http://' . CS_DOMAIN); else{ return null; } } public function actionLogoutYii() { Yii::$app->user->logout(); $session = Yii::$app->session; $session->destroy(); return $this->goHome(); } /** * @return string */ public function actionError() { $this->layout = "@backend/modules/motorcade/views/layouts/iframe"; $exception = Yii::$app->errorHandler->exception; if ($exception !== null) { //无权限的页面,其他错误不显示 /* @var $exception HttpException */ $code = $exception->statusCode; if ($code == 403) { $viewFile = 'error403'; } else { $viewFile = 'error'; } if (Yii::$app->request->isPjax || Yii::$app->request->isAjax) { return $this->renderPartial($viewFile . 'Pjax', ['exception' => $exception]); } else return $this->render($viewFile, ['exception' => $exception]); } return ''; } }