public function actionLogin()
 {
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->redirect(['/site/index']);
     }
     return $this->render('login', ['model' => $model]);
 }
Пример #2
0
 /**
  * @return \yii\web\Response
  */
 public function actionLogin()
 {
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goBack();
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
Пример #3
0
 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();
     }
     return $this->render('login', ['model' => $model]);
 }
Пример #4
0
 /**
  * Handle user login. if you already login and rediect to home page.
  * @throws \app\helpers\UserError
  * @return \yii\web\Response|string
  */
 public function actionLogin()
 {
     if (!Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $this->layout = false;
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post(), '') && $model->login()) {
         if (!$this->isAjax) {
             $cookies = $this->request->cookies;
             if (isset($cookies[$this->user->returnUrlParam])) {
                 $backUrl = $cookies[$this->user->returnUrlParam]->value;
                 Yii::$app->response->cookies->remove($this->user->returnUrlParam);
             } else {
                 $backUrl = \yii\helpers\Url::home(true);
             }
             $this->redirect($backUrl);
         }
     } else {
         if ($this->isAjax && $this->isPost) {
             throw new \app\helpers\UserError($model->getErrors());
         } else {
             return $this->render('login', ['model' => $model]);
         }
     }
 }