Commit 29df0a1f by sxy

fix: 去掉 appkey验证 修改 sysytem getObject

parent 854d8b12
......@@ -30,57 +30,57 @@ class CtlBase {
return system.getResult(rs);
}
async refQuery(pobj, qobj, req) {
pobj.refwhere.app_id=pobj.app_id;
pobj.refwhere.company_id=pobj.company_id;
let rtn=await this.service.refQuery(pobj);
pobj.refwhere.app_id = pobj.app_id;
pobj.refwhere.company_id = pobj.company_id;
let rtn = await this.service.refQuery(pobj);
return rtn
}
async setContextParams(pobj, qobj, req) {
let custtags = req.headers["x-consumetag"]?req.headers["x-consumetag"].split("|"):null;
let lastindex=custtags?custtags.length-1:0;
let custtags = req.headers["x-consumetag"] ? req.headers["x-consumetag"].split("|") : null;
let lastindex = custtags ? custtags.length - 1 : 0;
//当自由用户注册时,需要根据前端传来的companykey,查询出公司,给companyid赋值
req.xctx = {
appkey: req.headers["xappkey"],//用于系统管理区分应用,比如角色
fromappkey:req.headers["xfromappkey"],//来源APP,如果没有来源与appkey相同
companyid: custtags?custtags[0].split("_")[1]:null,
fromcompanykey:req.headers["xfromcompanykey"],//专用于自由用户注册,自由用户用于一定属于某个存在的公司
password: custtags?custtags[lastindex].split("_")[1]:null,
fromappkey: req.headers["xfromappkey"],//来源APP,如果没有来源与appkey相同
companyid: custtags ? custtags[0].split("_")[1] : null,
fromcompanykey: req.headers["xfromcompanykey"],//专用于自由用户注册,自由用户用于一定属于某个存在的公司
password: custtags ? custtags[lastindex].split("_")[1] : null,
username: req.headers["x-consumer-username"],
userid:req.headers["x-consumer-custom-id"],
userid: req.headers["x-consumer-custom-id"],
credid: req.headers["x-credential-identifier"],
regrole:req.headers["xregrole"],
bizpath:req.headers["xbizpath"],
}
if(!req.xctx.appkey){
return [-200,"请求头缺少应用x-app-key"]
}else{
let app=await this.cacheManager["AppCache"].cache(req.xctx.fromappkey);
req.xctx.appid=app.id;
if(!pobj.app_id){
pobj.app_id=app.id;//传递参数对象里注入app_id
}
regrole: req.headers["xregrole"],
bizpath: req.headers["xbizpath"],
}
if (!req.xctx.appkey) {
return [-200, "请求头缺少应用x-app-key"]
} else {
// let app=await this.cacheManager["AppCache"].cache(req.xctx.fromappkey);
// req.xctx.appid=app.id;
// if(!pobj.app_id){
// pobj.app_id=app.id;//传递参数对象里注入app_id
// }
}
//平台注册时,companyid,companykey都为空
//自由注册时,companykey不能为空
// if(!req.xctx.companyid && !req.xctx.companykey){
// return [-200,"请求头缺少应用x-app-key"]
// }
if(!req.xctx.companyid && req.xctx.fromcompanykey && req.xctx.fromcompanykey!="null"){
let comptmp=await this.cacheManager["CompanyCache"].cache(req.xctx.fromcompanykey);
req.xctx.companyid=comptmp.id;
if (!req.xctx.companyid && req.xctx.fromcompanykey && req.xctx.fromcompanykey != "null") {
let comptmp = await this.cacheManager["CompanyCache"].cache(req.xctx.fromcompanykey);
req.xctx.companyid = comptmp.id;
}
if(req.xctx.companyid){//在请求传递数据对象注入公司id
pobj.company_id=req.xctx.companyid;
if (req.xctx.companyid) {//在请求传递数据对象注入公司id
pobj.company_id = req.xctx.companyid;
}
if(req.xctx.userid){//在请求传递数据对象注入公司id
pobj.userid=req.xctx.userid;
if (req.xctx.userid) {//在请求传递数据对象注入公司id
pobj.userid = req.xctx.userid;
}
pobj.bizpath=req.xctx.bizpath;
pobj.bizpath = req.xctx.bizpath;
}
async doexec(methodname, pobj, query, req) {
try {
let xarg=await this.setContextParams(pobj, query, req);
if(xarg && xarg[0]<0){
let xarg = await this.setContextParams(pobj, query, req);
if (xarg && xarg[0] < 0) {
return system.getResultFail(...xarg);
}
//从请求头里面取appkey_consumename
......
var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
class BizOptCtl extends CtlBase {
constructor() {
super("bizchance", CtlBase.getServiceName(BizOptCtl));
}
}
module.exports = BizOptCtl;
......@@ -64,8 +64,8 @@ class DbFactory {
this.db.models.plugin.belongsTo(this.db.models.app, { constraints: false, });
// 商机表 1:1 方案表
this.db.models.scheme.belongsTo(this.db.models.bussiness_opportunity, { constraints: false, });
this.db.models.bussiness_opportunity.hasOne(this.db.models.scheme, { constraints: false, });
this.db.models.scheme.belongsTo(this.db.models.bizopt, { constraints: false, });
this.db.models.bizopt.hasOne(this.db.models.scheme, { constraints: false, });
}
//async getCon(){,用于使用替换table模型内字段数据使用
......
......@@ -5,7 +5,7 @@ const appconfig = system.getSysConfig();
* 商机表
*/
module.exports = (db, DataTypes) => {
return db.define("bussiness_opportunity", {
return db.define("bizopt", {
demand_code: { // 需求编码
allowNull: false,
type: DataTypes.STRING
......
......@@ -16,55 +16,55 @@ class System {
}
}
}
static async delReq(url,qdata){
let rtn={}
let promise=new Promise(function(resv,rej){
static async delReq(url, qdata) {
let rtn = {}
let promise = new Promise(function (resv, rej) {
request.del({
url: url,
qs: qdata
}, function(error, response, body) {
rtn.statusCode=response.statusCode
}, function (error, response, body) {
rtn.statusCode = response.statusCode
if (!error) {
if(body){
let data=JSON.parse(body)
rtn.data=data
}else{
rtn.data=null
if (body) {
let data = JSON.parse(body)
rtn.data = data
} else {
rtn.data = null
}
resv(rtn);
}else{
} else {
rej(error)
}
});
})
return promise;
}
static async getReq(url,qdata){
let rtn={}
let promise=new Promise(function(resv,rej){
static async getReq(url, qdata) {
let rtn = {}
let promise = new Promise(function (resv, rej) {
request.get({
url: url,
json: true,
qs: qdata
}, function(error, response, body) {
rtn.statusCode=response.statusCode;
}, function (error, response, body) {
rtn.statusCode = response.statusCode;
if (!error) {
if(body){
rtn.data=body
}else{
rtn.data=null
if (body) {
rtn.data = body
} else {
rtn.data = null
}
resv(rtn);
}else{
} else {
rej(error);
}
});
})
return promise;
}
static async postJsonTypeReq(url,data,md="POST"){
let rtn={}
let promise=new Promise(function(resv,rej){
static async postJsonTypeReq(url, data, md = "POST") {
let rtn = {}
let promise = new Promise(function (resv, rej) {
request({
url: url,
method: md,
......@@ -73,51 +73,51 @@ class System {
"content-type": "application/json",
},
body: data
}, function(error, response, body) {
}, function (error, response, body) {
console.log(error)
rtn.statusCode=response.statusCode
rtn.statusCode = response.statusCode
if (!error) {
if(body){
rtn.data=body
}else{
rtn.data=null
if (body) {
rtn.data = body
} else {
rtn.data = null
}
resv(rtn);
}else{
} else {
rej(error)
}
});
})
return promise;
}
static async post3wFormTypeReq(url,data){
let rtn={}
let promise=new Promise(function(resv,rej){
static async post3wFormTypeReq(url, data) {
let rtn = {}
let promise = new Promise(function (resv, rej) {
request.post({
url: url,
form: data
}, function(error, response, body) {
rtn.statusCode=response.statusCode
}, function (error, response, body) {
rtn.statusCode = response.statusCode
if (!error) {
let data=JSON.parse(body)
rtn.data=data
let data = JSON.parse(body)
rtn.data = data
resv(rtn);
}else{
} else {
rej(error)
}
});
})
return promise;
}
static async postMpFormTypeReq(url,formdata){
let promise=new Promise(function(resv,rej){
static async postMpFormTypeReq(url, formdata) {
let promise = new Promise(function (resv, rej) {
request.post({
url: url,
formData: formdata
}, function(error, response, body) {
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
resv(body);
}else{
} else {
rej(error)
}
});
......@@ -176,11 +176,16 @@ class System {
data: data,
};
}
static register(key, ClassObj,groupName,filename) {
static register(key, ClassObj, groupName, filename) {
if (System.objTable[key] != null) {
throw new Error("相同key的对象已经存在");
} else {
let obj = new ClassObj(groupName,filename);
let obj;
if (ClassObj.name === "ServiceBase") {
obj = new ClassObj(groupName, filename.replace("Sve", "Dao"));
} else {
obj = new ClassObj(groupName, filename);
}
System.objTable[key] = obj;
}
......@@ -208,22 +213,22 @@ class System {
if (System.objTable[objabspath] != null) {
return System.objTable[objabspath];
} else {
var ClassObj =null;
try{
var ClassObj = null;
try {
ClassObj = require(objabspath);
}catch(e){
} catch (e) {
// console.log(e)
let fname=objsettings[packageName+"base"];
let fname = objsettings[packageName + "base"];
ClassObj = require(fname);
}
if(ClassObj.name=="Dao"){
let modelname=filename.substring(0,filename.lastIndexOf("Dao"))
return System.register(objabspath, ClassObj,modelname);
if (ClassObj.name == "Dao") {
let modelname = filename.substring(0, filename.lastIndexOf("Dao"))
return System.register(objabspath, ClassObj, modelname);
}
if(ClassObj.name.indexOf("Ctl")>=0){
if (ClassObj.name.indexOf("Ctl") >= 0) {
console.log(ClassObj.name);
}
return System.register(objabspath, ClassObj,groupName,filename);
return System.register(objabspath, ClassObj, groupName, filename);
}
}
......
var settings = {
redis: {
host: "192.168.4.119",
port: 6379,
host: "43.247.184.32",
port: 8967,
password: "Gongsibao2018",
db: 9,
},
......
......@@ -4,6 +4,7 @@
"description": "h5framework",
"main": "main.js",
"scripts": {
"dev": "nodemon main.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "jy",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment