Пример #1
0
 /**
  * Logs in a user.
  *
  * @return mixed
  */
 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]);
     }
 }
Пример #2
0
 /**
  **显示登陆页面(get),登陆(post).
  * @return string|\yii\web\Response
  */
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         if (Yii::$app->request->isAjax) {
             AjaxResponse::fail();
         } else {
             return $this->redirect('https://find.forfreedomandlove.com');
         }
     }
     if (Yii::$app->request->isGet) {
         $csrf = Yii::$app->request->csrfToken;
         return $this->render('login', ['csrf' => $csrf]);
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post(), '') && $model->login()) {
         AjaxResponse::success();
     } else {
         AjaxResponse::fail(null, $model->errors);
     }
 }