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