/** * Авторизация * @return array|string|Response */ public function actionLogin() { if (!Yii::$app->user->isGuest) { $this->goHome(); } $model = new models\LoginForm(['scenario' => 'admin']); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { if ($model->login()) { return $this->goHome(); } } else { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } } } return $this->render('login', ['model' => $model]); }