Commit a02214b6 by lixinming

no message

parent e458a165
......@@ -7,7 +7,7 @@
import { ERRORENUM } from "../../config/errorEnum";
import * as fuhuaqiData from "../../data/fuHuaQi/fuhuaqi"
import { BizError } from "../../util/bizError";
import { getPwdMd5 } from "../../util/tools";
import { getPwdMd5, getToken } from "../../util/tools";
/**
* 登录
......@@ -16,15 +16,25 @@ import { getPwdMd5 } from "../../util/tools";
* @returns fuhuaqiUserInfo:{uscc, name} 登录后的信息
*/
export async function login(uscc:string, pwd:string) {
let fuhuaqiInfo = await fuhuaqiData.findFuHuaQiByUscc(uscc);
let fuhuaqiInfo = await fuhuaqiData.findFuHuaQiByUSCC(uscc);
if(!fuhuaqiInfo) throw new BizError(ERRORENUM.未找到数据);
let checkPwd = getPwdMd5(fuhuaqiInfo.uscc, pwd);
if (fuhuaqiInfo.pwd != checkPwd) throw new BizError(ERRORENUM.密码错误);
const Token = getToken(uscc);
let fuhuaqiUserInfo = {
uscc: fuhuaqiInfo.uscc,
name: fuhuaqiInfo.name
name: fuhuaqiInfo.name,
firstLogin : !fuhuaqiInfo.firstLoginIsChangePwd,
token:Token
};
fuhuaqiInfo.token = Token;
fuhuaqiInfo.tokenMs = new Date().valueOf();
await fuhuaqiInfo.save();
return fuhuaqiUserInfo;
}
......
......@@ -20,7 +20,9 @@ export async function checkFuHuaQiToken(req, res, next) {
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}`));
/**2023-2-8日需求 登录一次一直有效 */
// if (userInfo.token != reqToken || (new Date().valueOf() - userInfo.tokenMs) > (3600*100*24*7) ) return next(new BizError(ERRORENUM.身份验证过期, `userId:${userId} token:${reqToken}`));
if (userInfo.token != reqToken ) return next(new BizError(ERRORENUM.身份验证过期, `userId:${userId} token:${reqToken}`));
//todo
req.headers.uscc = userInfo.uscc;
......
......@@ -129,4 +129,13 @@ export function checkReqParam(conf, param) {
if (!conf[key]) throw new BizError(ERRORENUM.表单校验失败, name, `多余${key}字段`);
}
return param;
}
/**
* 获取token
* @param uscc 统一信用代码
*/
export function getToken(uscc:string) {
return md5(`${uscc}${new Date().valueOf()}${Math.ceil(Math.random() *100)}`);
}
\ No newline at end of file
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