auth = Auth::instance(); $routePath = $this->app->request->controllerPath . '/' . $this->request->action(true); $token = $this->request->server('HTTP_BA_USER_TOKEN', $this->request->request('ba-user-token', Cookie::get('ba-user-token') ?: false)); if (!action_in_arr($this->noNeedLogin)) { $this->auth->init($token); if (!$this->auth->isLogin()) { $this->error(__('Please login first'), [ 'type' => $this->auth::NEED_LOGIN ], $this->auth::LOGIN_RESPONSE_CODE); } if (!action_in_arr($this->noNeedPermission)) { if (!$this->auth->check($routePath)) { $this->error(__('You have no permission'), [], 401); } } } elseif ($token) { try { $this->auth->init($token); } catch (HttpResponseException) { } } // 会员验权和登录标签位 Event::trigger('frontendInit', $this->auth); } }