Commit ba6e1fdf by lixinming

no message

parent 9af33140
...@@ -33,7 +33,8 @@ export async function login({loginStr, pwd}) { ...@@ -33,7 +33,8 @@ export async function login({loginStr, pwd}) {
isAdmin:userInfo.isAdmin == STATE., isAdmin:userInfo.isAdmin == STATE.,
name:userInfo.name, name:userInfo.name,
userId:userInfo.userId, userId:userInfo.userId,
token:token token:token,
adminLv:userInfo.adminLv
}; };
return {dataInfo} return {dataInfo}
......
import { nextTick } from "process";
import { ERRORENUM } from "../config/errorEnum"; import { ERRORENUM } from "../config/errorEnum";
import { TABLEENUM } from "../data/models/model"; import { TABLEENUM } from "../data/models/model";
import { findOnce } from "../data/select"; import { findOnce } from "../data/select";
...@@ -18,30 +19,34 @@ export async function checkUser(req, res, next) { ...@@ -18,30 +19,34 @@ export async function checkUser(req, res, next) {
const reqToken = req.headers.token; const reqToken = req.headers.token;
const userId = req.headers.userid || ""; const userId = req.headers.userid || "";
if (!reqToken || !userId ) return next(new BizError(ERRORENUM.身份验证失败, `userId:${userId} token:${reqToken}`)); // if (!reqToken || !userId ) return next(new BizError(ERRORENUM.身份验证失败, `userId:${userId} token:${reqToken}`));
let userInfo = await findOnce(TABLEENUM.用户表, {userId}); // let userInfo = await findOnce(TABLEENUM.用户表, {userId});
if (!userInfo || !userInfo.userId) return next(new BizError(ERRORENUM.身份验证失败)); // if (!userInfo || !userInfo.userId) return next(new BizError(ERRORENUM.身份验证失败));
if (userInfo.token != reqToken) return next(new BizError(ERRORENUM.身份验证过期)); // if (userInfo.token != reqToken) return next(new BizError(ERRORENUM.身份验证过期));
let checkToken = ''; // let checkToken = '';
//30分钟更新token // //30分钟更新token
if ( (userInfo.tokenMs - new Date().valueOf()) >= (30 * 60 * 1000) ) { // if ( (userInfo.tokenMs - new Date().valueOf()) >= (30 * 60 * 1000) ) {
return next(new BizError(ERRORENUM.身份验证过期)); // return next(new BizError(ERRORENUM.身份验证过期));
} else { // } else {
checkToken = reqToken; // checkToken = reqToken;
await updateOneData(TABLEENUM.用户表, {userId:userInfo.userId}, { tokenMs:new Date().valueOf()}); // await updateOneData(TABLEENUM.用户表, {userId:userInfo.userId}, { tokenMs:new Date().valueOf()});
} // }
req.headers.userId = userId; req.headers.userId = userId;
req.headers.userInfo = { req.headers.userInfo = {
userId, userId,
isAdmin:userInfo.isAdmin // isAdmin:userInfo.isAdmin
} }
next(); next();
} }
export async function notCheck(req, res, next) {
next();
}
/** /**
* 中间件 数据维护接口 * 中间件 数据维护接口
......
...@@ -174,7 +174,7 @@ export const Config = { ...@@ -174,7 +174,7 @@ export const Config = {
subUrl:'/login', subUrl:'/login',
notMiddleware:true, notMiddleware:true,
param:[ param:[
{key:"lolginId", type:"String", desc:"账号"}, {key:"loginId", type:"String", desc:"账号"},
{key:"pwd", type:"String", desc:"密码"} {key:"pwd", type:"String", desc:"密码"}
], ],
bindBiz:userBiz.login bindBiz:userBiz.login
...@@ -630,9 +630,7 @@ export const Config = { ...@@ -630,9 +630,7 @@ export const Config = {
{ {
apiName:"会员信息展示", apiName:"会员信息展示",
subUrl:'/homepage/list', subUrl:'/homepage/list',
param:[ param:[],
{key:"userId", type:"String", desc:"用户id"}
],
bindBiz:homePageBiz.getMemberData bindBiz:homePageBiz.getMemberData
}, },
{ {
......
...@@ -16,7 +16,7 @@ import * as officalWebsiteRouter from "./officalWebsite/router"; ...@@ -16,7 +16,7 @@ import * as officalWebsiteRouter from "./officalWebsite/router";
import * as orderRouter from "./order/router"; import * as orderRouter from "./order/router";
import * as asyncHandler from 'express-async-handler'; import * as asyncHandler from 'express-async-handler';
import { payCallback } from "../biz/member/cost"; import { payCallback } from "../biz/member/cost";
import { checkUser } from "../middleware/user"; import { checkUser, notCheck } from "../middleware/user";
const Look = false;//true更新文档 const Look = false;//true更新文档
...@@ -30,9 +30,9 @@ export async function setRouter(httpServer){ ...@@ -30,9 +30,9 @@ export async function setRouter(httpServer){
await initDoc(orderRouter.FirstName, orderRouter.Config, orderRouter.FirstRouter);//会费相关 await initDoc(orderRouter.FirstName, orderRouter.Config, orderRouter.FirstRouter);//会费相关
await initDoc(costRouter.FirstName, costRouter.Config, costRouter.FirstRouter);//支付 await initDoc(costRouter.FirstName, costRouter.Config, costRouter.FirstRouter);//支付
} }
await analysisRouter(httpServer, portalRouter.Config, portalRouter.FirstRouter, true);//网站编辑 await analysisRouter(httpServer, portalRouter.Config, portalRouter.FirstRouter, false);//网站编辑
await analysisRouter(httpServer, publicRouter.Config, publicRouter.FirstRouter, false);//公用组件 await analysisRouter(httpServer, publicRouter.Config, publicRouter.FirstRouter, false);//公用组件
await analysisRouter(httpServer, memberRouter.Config, memberRouter.FirstRouter, false);//用户路由 await analysisRouter(httpServer, memberRouter.Config, memberRouter.FirstRouter, true);//用户路由
await analysisRouter(httpServer, officalWebsiteRouter.Config, officalWebsiteRouter.FirstRouter, false);//官网路由 await analysisRouter(httpServer, officalWebsiteRouter.Config, officalWebsiteRouter.FirstRouter, false);//官网路由
await analysisRouter(httpServer, orderRouter.Config, orderRouter.FirstRouter, true);//会费相关 await analysisRouter(httpServer, orderRouter.Config, orderRouter.FirstRouter, true);//会费相关
await analysisRouter(httpServer, costRouter.Config, costRouter.FirstRouter, true);//支付 await analysisRouter(httpServer, costRouter.Config, costRouter.FirstRouter, true);//支付
...@@ -42,55 +42,50 @@ async function analysisRouter(httpServer, config, firstRouter, haveMiddleware) { ...@@ -42,55 +42,50 @@ async function analysisRouter(httpServer, config, firstRouter, haveMiddleware) {
for (let modelKey in config) { for (let modelKey in config) {
config[modelKey].forEach(info => { config[modelKey].forEach(info => {
let {apiName, defaultParam, subUrl, param, bindBiz, notMiddleware} = info; let {apiName, defaultParam, subUrl, param, bindBiz, notMiddleware} = info;
if (haveMiddleware) { httpServer.post(firstRouter+subUrl , haveMiddleware? checkUser : notCheck, async function (req, res) {
if (notMiddleware) { let chackObjectList = [];
httpServer.post(firstRouter+subUrl , allRouter(apiName, defaultParam, subUrl, param, bindBiz)); let checkStringMap = {};
} else httpServer.post(firstRouter+subUrl, checkUser , allRouter(apiName, defaultParam, subUrl, param, bindBiz)); let stringNotMustHaveKeys = [];
}
else httpServer.post(firstRouter+subUrl , allRouter(apiName, defaultParam, subUrl, param, bindBiz)); let funcParam:any = {};
funcParam.userId = req.headers.userId;
for (let i = 0; i < param.length; i++) {
let info:any = param[i];
let {key, type} = param[i];
if (info.isNull) stringNotMustHaveKeys.push(key);
if (type == 'Object') {
chackObjectList.push(param[i]);
checkStringMap[key] = type;
}
else checkStringMap[key] = type;
}
/**校验参数 */
if (chackObjectList.length) {
chackObjectList.forEach(item => {
if (!req.body[item.key]) throw new BizError(ERRORENUM.参数错误, `缺少参数${item.key}`);
eccFormParam(apiName, item.sub, req.body[item.key]);
funcParam[item.key] = req.body[item.key];
});
}
if (Object.keys(checkStringMap).length) {
let eccResult = eccReqParamater(apiName, checkStringMap, req.body, stringNotMustHaveKeys);
for (let key in eccResult) {
funcParam[key] = eccResult[key];
}
}
if (defaultParam) funcParam["defaultParam"] = defaultParam;
let result = await bindBiz(funcParam);
res.success(result);
});
}); });
} }
} }
function allRouter(apiName, defaultParam, subUrl, param, bindBiz) { async function allRouter(apiName, defaultParam, subUrl, param, bindBiz) {
return async function (req, res) {
let chackObjectList = [];
let checkStringMap = {};
let stringNotMustHaveKeys = [];
let funcParam:any = {};
funcParam.userId = req.headers.userId;
for (let i = 0; i < param.length; i++) {
let info:any = param[i];
let {key, type} = param[i];
if (info.isNull) stringNotMustHaveKeys.push(key);
if (type == 'Object') {
chackObjectList.push(param[i]);
checkStringMap[key] = type;
}
else checkStringMap[key] = type;
}
/**校验参数 */
if (chackObjectList.length) {
chackObjectList.forEach(item => {
if (!req.body[item.key]) throw new BizError(ERRORENUM.参数错误, `缺少参数${item.key}`);
eccFormParam(apiName, item.sub, req.body[item.key]);
funcParam[item.key] = req.body[item.key];
});
}
if (Object.keys(checkStringMap).length) {
let eccResult = eccReqParamater(apiName, checkStringMap, req.body, stringNotMustHaveKeys);
for (let key in eccResult) {
funcParam[key] = eccResult[key];
}
}
if (defaultParam) funcParam["defaultParam"] = defaultParam;
let result = await bindBiz(funcParam);
res.success(result);
}
} }
export async function setAdditionalRouter(httpServer) { export async function setAdditionalRouter(httpServer) {
......
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