Commit e458a165 by lixinming

no message

parent 1369bc00
......@@ -11,12 +11,16 @@ export enum ERRORENUM {
该报表需要填写本月内容后提交,
密码错误,
密码不允许有特殊字符,
不能重复修改密码
不能重复修改密码,
身份验证失败,
非法登录,
身份验证过期,
}
export enum ERRORCODEENUM {
省份验证失败 = 401,
身份验证失败 = 401,
非法登录 = 402,
身份验证过期 = 403
}
let bizErrorMsgMap = {};
......
......@@ -10,7 +10,6 @@ import { baseDB } from '../../db/dbInit';
const fuHuaQiSchema = new Schema({
name: {type:String,index: true},//名称
pwd:String,//登录密码
firstLoginIsChangePwd:{type:Boolean, default:false},//首次登录是否修改密码
operationName:String,//运营机构名称 不可修改
uscc:{type:String, index: true},//统一信用代码 也是登录账号 不可修改
......@@ -29,7 +28,11 @@ const fuHuaQiSchema = new Schema({
personInChargePhone:String,//负责人联系电话
personInChargeAdd:String,//孵化场地地址
siteAcreage:Number,//孵化场地面积(㎡)
leasePrice:Number//孵化场地出租单价
leasePrice:Number,//孵化场地出租单价
/**登录相关 */
pwd:String,//登录密码
token:{type:String, index:true},
tokenMs:Number
});
var fuHuaQiModel;
......@@ -79,4 +82,15 @@ export async function findFuHuaQiByName(name:string) {
*/
export async function findFuHuaQiByUscc(uscc:string) {
return await fuHuaQiModel.findOne({uscc}).exec();
}
/**
* 通过token获取孵化器信息 弃用
* 中间件使用
* @param token token
* @returns 孵化器信息
*/
export async function findFuHuaQiByToken(token:string) {
return await fuHuaQiModel.findOne({token}).exec();
}
\ No newline at end of file
import { ERRORCODEENUM } from "../config/errorEnum";
/**
* 中间件 错误返回
......@@ -11,8 +12,8 @@ export function httpErrorHandler(err, req, res, next) {
console.log(err);
//todo 自定义错误编码
if (err) {
if (err.message == "身份验证失败" || err.message == "身份验证过期") {
res.success({success:false, msg:err.message, code:501});
if ( ERRORCODEENUM[err.message] ) {
res.success({success:false, msg:err.message, code:ERRORCODEENUM[err.message]});
next();
}
else {
......@@ -20,4 +21,4 @@ export function httpErrorHandler(err, req, res, next) {
next();
}
}
}
\ No newline at end of file
}
\ No newline at end of file
import { ERRORENUM } from "../config/errorEnum";
import { findFuHuaQiByUSCC } from "../data/fuHuaQi/fuhuaqi";
import { BizError } from "../util/bizError";
/**
* 中间件 校验token
* 中间件 校验孵化器token
* @param req
* @param res
* @param next
* @returns
*/
export async function checkToken(req, res, next) {
export async function checkFuHuaQiToken(req, res, next) {
if (!req.headers) req.headers = {};
const reqToken = req.headers.token;
const userId = req.headers.userid || "";
let isErr = false;
if (!userId) return next(new BizError(ERRORENUM.身份验证失败, `userId:${userId} token:${reqToken}`));
// if (userInfo.token != reqToken) {
// isErr = true;
// return next(new BizError(SYSTEMERRORENUM.身份验证过期, userId, reqToken, req.url));
// }
let userInfo = await findFuHuaQiByUSCC(userId);
if (!userInfo) return next(new BizError(ERRORENUM.非法登录, `userId:${userId} token:${reqToken}`));
if (userInfo.token != reqToken || (new Date().valueOf() - userInfo.tokenMs) > (3600*100*24*7) ) return next(new BizError(ERRORENUM.身份验证过期, `userId:${userId} token:${reqToken}`));
req.headers.userId = userId;
//todo
req.headers.uscc = userInfo.uscc;
if (!isErr) next();
next();
}
\ No newline at end of file
......@@ -4,13 +4,13 @@
import * as asyncHandler from 'express-async-handler';
import { FUHUAQILV, INSTITUTIONALNATURE, FUHUAINDUSTRY, INDUSTRY } from '../config/enum';
import { checkToken } from '../middleware/user';
import { checkFuHuaQiToken } from '../middleware/user';
export function setRouter(httpServer) {
httpServer.post('/public/fuhuaqilv', checkToken, asyncHandler(getFuHuaQiLv));
httpServer.post('/public/institutionalnature', checkToken, asyncHandler(getInstitutionalNature));
httpServer.post('/public/fuhuaqiindustry', checkToken, asyncHandler(getFuHuaQiIndustry));
httpServer.post('/public/industry', checkToken, asyncHandler(getIndustry));
httpServer.post('/public/fuhuaqilv', checkFuHuaQiToken, asyncHandler(getFuHuaQiLv));
httpServer.post('/public/institutionalnature', checkFuHuaQiToken, asyncHandler(getInstitutionalNature));
httpServer.post('/public/fuhuaqiindustry', checkFuHuaQiToken, asyncHandler(getFuHuaQiIndustry));
httpServer.post('/public/industry', checkFuHuaQiToken, asyncHandler(getIndustry));
}
/**
......
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