Ejemplo n.º 1
0
 /**
  * 用户登陆控制器
  * @return string|\yii\web\Response
  */
 public function actionLogin()
 {
     if (!wanhunet::$app->user->isGuest) {
         return !wanhunet::$app->user->isGuest;
     }
     $model = new LoginForm(wanhunet::$app->request->post());
     if ($model->login()) {
         return true;
     } else {
         return current($model->getFirstErrors());
     }
 }
Ejemplo n.º 2
0
 public function actionLoginAjax()
 {
     if (!\Yii::$app->user->isGuest) {
         return true;
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->login()) {
             $arr = ['status' => true];
         } else {
             $arr = ['status' => false, 'message' => current($model->getFirstErrors())];
         }
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         return $arr;
     } else {
         return $this->renderAjax('loginAjax', ['model' => $model]);
     }
 }