Example #1
0
 /**
  * UserModel::userLogin()
  * 用户登录走开放系统
  * add by 管拥军 2013-08-21
  * @return  bool
  */
 public static function userLogin($username, $password, $version)
 {
     if (strpos($username, 'sailvan.com') === false) {
         return "fail";
         exit;
     }
     $paramArr = array('method' => 'power.user.login.get', 'format' => 'json', 'v' => '1.0', 'username' => C('OPEN_SYS_USER'), 'user_name' => $username, 'pwd' => rawurlencode($password), 'version' => $version, 'sysName' => C('AUTH_SYSNAME'), 'sysToken' => C('AUTH_SYSTOKEN'));
     $loginInfo = callOpenSystem($paramArr);
     unset($paramArr);
     //如果开放系统登录超时,走本地登录
     if (empty($loginInfo)) {
         self::initDB();
         $pwd = md5(md5(rawurldecode(rawurlencode($password))));
         $sql = "SELECT a.user_company,a.user_id,a.user_token,b.global_user_company,b.global_user_id,b.global_user_name FROM power_user AS a\n\t\t\t\t\t\tLEFT JOIN power_global_user AS b ON a.user_email = b.global_user_email\n\t\t\t\t\t\tWHERE a.user_pwd = '{$pwd}' AND a.user_email = '{$username}' AND a.user_system_id = 8 AND b.global_user_is_delete = 0\n\t\t\t\t\t\tLIMIT 1";
         $query = self::$dbConn->query($sql);
         if (!$query) {
             return false;
         }
         $res = self::$dbConn->fetch_array($query);
         $_SESSION['userToken'] = $res['user_token'];
         $_SESSION['sysUserId'] = $res['global_user_id'];
         //统一用户系统ID
         $_SESSION['userId'] = $res['user_id'];
         //分系统用户ID
         $_SESSION['userName'] = $res['global_user_name'];
         $_SESSION['companyId'] = $res['global_user_company'];
         //读取用户细颗粒权限
         $competences = UserCompetenceModel::getCompetenceById($_SESSION['sysUserId']);
         $_SESSION['competences'] = json_decode($competences['competence'], true);
         return "ok";
     } else {
         $loginInfo = json_decode($loginInfo);
         if (isset($loginInfo->errCode)) {
             echo $loginInfo->errMsg;
             self::$errCode = $loginInfo->errCode;
             self::$errMsg = $loginInfo->errMsg;
             return false;
         }
         $_SESSION['userToken'] = $loginInfo->userToken;
         $_SESSION['sysUserId'] = $loginInfo->globalUserId;
         //统一用户系统ID
         $_SESSION['userId'] = $loginInfo->userId;
         //分系统用户ID
         $_SESSION['userName'] = $loginInfo->userCnName;
         $_SESSION['companyId'] = $loginInfo->company;
         //读取用户细颗粒权限
         $competences = UserCompetenceModel::getCompetenceById($_SESSION['sysUserId']);
         $_SESSION['competences'] = json_decode($competences['competence'], true);
         return "ok";
     }
 }