Example #1
0
 public function actionLogin()
 {
     $request = Yii::$app->request;
     if ($request->isGet) {
         return $this->renderJSON([], "请使用POST提交", -1);
     }
     $mobile = trim($this->post("mobile"));
     $passwd = trim($this->post("passwd"));
     if (!preg_match("/^[1-9]\\d{10}\$/", $mobile)) {
         return $this->renderJSON([], "请输入符合规范的手机号码!", -1);
     }
     $user_info = Admin::findOne(['mobile' => $mobile]);
     $params = ['target_type' => 1, 'target_id' => 0, 'act_type' => 1, 'status' => 0, 'login_name' => $mobile];
     if (!$user_info) {
         AccessLogService::recordAccess_log($params);
         return $this->renderJSON([], "请输入正确的手机号码和密码!", -1);
     }
     if (!$user_info->ckeckPassword($passwd)) {
         AccessLogService::recordAccess_log($params);
         return $this->renderJSON([], "请输入正确的手机号码和密码!", -1);
     }
     $params['status'] = 1;
     AccessLogService::recordAccess_log($params);
     $this->createLoginStatus($user_info);
     return $this->renderJSON(['url' => "/"]);
 }
Example #2
0
 public function beforeAction($action)
 {
     $login_status = $this->checkLoginStatus();
     if (!$login_status && !in_array($action->getUniqueId(), $this->allowAllAction)) {
         if (Yii::$app->request->isAjax) {
             $this->renderJSON([], "未登录,请返回用户中心", -302);
         } else {
             $this->redirect(AdminUrlService::buildUrl("/auth/index"));
         }
         return false;
     }
     $view = Yii::$app->view;
     $view->params['current_user'] = $this->current_user;
     $params = ['target_type' => 1, 'target_id' => $this->current_user ? $this->current_user['uid'] : 0, 'act_type' => 2, 'status' => 1];
     AccessLogService::recordAccess_log($params);
     return true;
 }