/** * 初始化函数 */ public function init() { //$_SESSION['brandid']=192; //Yii::app()->cache->flush(); $this->login_type = Yii::app()->request->getParam('login_type'); //C# 软件登录 //此Cookie在每个Controller 里必须加载 用于域名的绑定 $cookie = new CHttpCookie('img_server_host', Yii::app()->params['img_server_host']); $cookie->expire = time() + 3600 * 24; //有限期1天 Yii::app()->request->cookies['img_server_host'] = $cookie; $cookie = new CHttpCookie('web_server_host', Yii::app()->params['web_server_host']); $cookie->expire = time() + 3600 * 24; //有限期1天 Yii::app()->request->cookies['web_server_host'] = $cookie; /**************************获取 设置 网站模版类型 start *************************************/ $http_cookie = Yii::app()->request->getCookies(); if (!empty($http_cookie['Website_template']->value)) { $this->Website_template = $http_cookie['Website_template']->value; } $http_cookie = new CHttpCookie('Website_template', $this->Website_template); //定义cookie的有效期 $http_cookie->expire = time() + 60 * 60; //有限期1小时 //把cookie写入cookies使其生效 Yii::app()->request->cookies['Website_template'] = $http_cookie; /**************************获取 设置 网站模版类型 end *************************************/ $status = 0; //0表示登录错误,1 表示 权限错误 $REDIRECT_URL = isset($_SERVER['REDIRECT_URL']) ? $_SERVER['REDIRECT_URL'] : $_SERVER['REQUEST_URI']; //当前URL规范 if (!empty($REDIRECT_URL)) { $REDIRECT_URL = str_replace('?', '/', $REDIRECT_URL); $REDIRECT_URL = explode('/', $REDIRECT_URL); if (!isset($REDIRECT_URL[2]) || empty($REDIRECT_URL[2])) { $this->renderPartial('/erp/login'); exit; } if (count($REDIRECT_URL) > 1) { $REDIRECT_URL = '/' . $REDIRECT_URL[1] . '/' . $REDIRECT_URL[2]; } } try { if (!isset($_SESSION)) { session_start(); } //验证账号登录状态,不需要修改账户登录时间 也不需要记录日志 if ($REDIRECT_URL == '/erp/GetUserType' && isset($_SESSION['user_id'])) { throw new Exception('验证账号登录状态,不需要修改账户登录时间'); } usercookie::userCheckCookie(); //获取登录状态 //echo session_id();//exit(); $_SESSION['touchid_new'] = isset($_SESSION['touchid_new']) ? $_SESSION['touchid_new'] : 0; $_SESSION['Disable'] = false; //是否禁用权限管理 //判断用户是否登陆 if (!isset($_SESSION['user_id']) || empty($_SESSION['user_id'])) { $user = Yii::app()->request->getParam('upwo'); if (!$user) { throw new Exception('对不起,您尚未登录系统!'); } else { throw new Exception('自动登录失败!'); } } //获取用户访问权限 $user = WebUser::getusersById($_SESSION['user_id']); if ($user['status'] == 0) { throw new Exception($user['msg']); } if (empty($user['data']->touchid)) { throw new Exception('帐号未绑定搭配屏'); } $touch_arr = json_decode($user['data']->touchid, true); //用户绑定的搭配屏 $touch_ret = Touch::touchSelectById($touch_arr[0]); //根据搭配屏获取品牌 if ($touch_ret['status'] == 0) { throw new Exception($touch_ret['msg']); } $_SESSION['brandid'] = $touch_ret['data']['brandid']; if (empty($_SESSION['brandid'])) { throw new Exception('帐号未绑定品牌'); } $_SESSION['type'] = $user['data']->type; //判断用户的访问权限是否可以访问系统 $user_type = isset($_SESSION['type']) ? $_SESSION['type'] : 0; $user_type = permission::userTypeChange($user_type, $user['data']->ERP3_status); //权限转换 if (empty($user_type) || $user_type > 70 || $user_type <= 50) { //只有ERP3.0账户可访问 throw new Exception('对不起,您的权限不能访问系统!'); } Yii::app()->params['user_type'] = $user_type; $cookie = new CHttpCookie('user_type', $user_type); $cookie->expire = time() + 60 * 60 * 2; //有限期2分钟 Yii::app()->request->cookies['user_type'] = $cookie; if ($user_type > 1) { //将获取到的品牌存入cookie,以供前台js读取 $cookie = new CHttpCookie('brand', $_SESSION['brandid']); $cookie->expire = time() + 60 * 2; //有限期2分钟 Yii::app()->request->cookies['brand'] = $cookie; $arr = explode(':', $_SERVER['HTTP_HOST']); if (isset($_SESSION['Disable']) && $_SESSION['Disable']) { $status = 1; throw new Exception('权限被禁用或域名不正确'); } //echo "wb1";exit(); $ret = Beu_Power::getPowerAll(); //获取用户可访问的页面 if ($ret['status'] == 0) { throw new Exception($ret['msg']); } Yii::app()->params['power_action'] = isset($ret['data']) ? $ret['data'] : array(); //将权限列表存入全局 //print_r(Yii::app()->params['power_action']); if (!Beu_Power::selectAction($REDIRECT_URL)) { //查询当前路径是否可访问 $status = 1; throw new Exception('对不起,本账号无此权限'); } } $this->setHistory(); //设置日志 } catch (Exception $e) { if ($REDIRECT_URL != '/erp/GetUserType') { $arr = explode(':', $_SERVER['HTTP_HOST']); $this->ret_msg = $e->getMessage(); $ret_a = Beu_Power::getActionInfoByPower(2, 1, 2); //获取不登陆可访问的链接 $gc_ret = Beu_Power::getActionInfoByPower(2, 45, 2); //工厂软件使用 工厂软件不验证登陆 $action_path = array(); if ($ret_a['status'] == 1) { foreach ($ret_a['data'] as $value) { $action_path[] = $value['path']; } foreach ($gc_ret['data'] as $value) { $action_path[] = $value['path']; } foreach ($this->interface_arr as $value) { $action_path[] = $value; } } else { $this->ret_msg = $ret_a['msg']; } if ((!isset($_SESSION['Disable']) || !$_SESSION['Disable']) && $REDIRECT_URL != '' && !in_array($REDIRECT_URL, $action_path)) { //判断当前用户是有有权限访问 当前链接 Yii::app()->params['power_action'] = array(); $this->__errorview($status, $this->ret_msg); } } } }