/** * Авторизация пользователя * @return string|\yii\web\Response */ public function actionLogin() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { return $this->render('login', ['model' => $model]); } }
/** * Login user. */ public function actionIndex() { if (!Yii::$app->user->isGuest) { $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { if ($model->login()) { return $this->goHome(); } } elseif (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } } return $this->render('index', ['model' => $model]); }
/** * Авторизируем пользователя */ public function actionLogin() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $this->layout = '@backend/modules/user/views/layouts/main'; $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { return $this->render('login', ['model' => $model]); } }