getApp(); $controller = request()->getController(); $action = request()->getAction(); // 控制器是否存在 $className = '\app' . $app . '\\controller\\' . $controller; $className = str_replace('/', '\\', $className); if (class_exists($className)) { $refClass = new \ReflectionClass($className); $property = $refClass->getDefaultProperties(); $this->needLogin = $property['needLogin'] ?? false; $this->noNeedAuth = $property['noNeedAuth'] ?? []; $this->repeatLogin = $property['repeatLogin'] ?? ['login', 'register']; $this->JumpUrl = $property['JumpUrl'] ?? '/user/index'; } // 是否验证登录器 $auth = Auth::instance(); if ($auth->isLogin()) { $request->user_id = $auth->userData['id']; $request->userData = $auth->userData; // 禁止重复登录 if (in_array($action, $this->repeatLogin)) { return redirect($this->JumpUrl); } View::assign('user', $auth->userData); } else { if ($this->needLogin && !in_array($action, $this->noNeedAuth)) { if (\request()->isAjax()) { return json(ResultCode::PLEASELOGININ); } else { return redirect('/user/login'); } } } return $handler($request); } }