Ejemplo n.º 1
0
 public function actionLogin()
 {
     $this->layout = false;
     if (!$this->user->isGuest) {
         $this->redirect(Yii::$app->getHomeUrl());
     }
     $model = new LoginForm();
     if ($this->isPost) {
         $model->attributes = $this->request->post();
         if ($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 = Url::home(true);
                 }
                 $this->redirect($backUrl);
             }
         }
     }
     if ($this->isAjax && $this->isPost) {
         throw new UserError($model->getErrors());
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
Ejemplo n.º 2
0
 public function actionLogin()
 {
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->redirect(['site/index']);
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }