|
|
@ -17,60 +17,14 @@ async function login (ctx, next) { |
|
|
|
if (!emisLoginRes) { |
|
|
|
throw "无此用户,请使用正确的登录信息" |
|
|
|
} else { |
|
|
|
const pomsRegisterRes = await models.User.findOne({ |
|
|
|
where: { |
|
|
|
pepUserId: emisLoginRes.id, |
|
|
|
$or: { |
|
|
|
deleted: false, |
|
|
|
role: { $contains: ['admin'] } |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
if (!pomsRegisterRes) { |
|
|
|
throw '你还不是飞尚运维中台成员,请联系管理员添加权限' |
|
|
|
} else if ( |
|
|
|
pomsRegisterRes.disabled && !pomsRegisterRes.role.includes('admin') |
|
|
|
) { |
|
|
|
throw '当前账号已禁用' |
|
|
|
} |
|
|
|
|
|
|
|
emisLoginRes.authorized = true |
|
|
|
emisLoginRes.expired = moment().add(1, 'day') |
|
|
|
emisLoginRes.pomsUserInfo = pomsRegisterRes.dataValues |
|
|
|
|
|
|
|
let userUpdateData = { |
|
|
|
lastInTime: moment().format(), |
|
|
|
inTimes: pomsRegisterRes.inTimes + 1, |
|
|
|
lastInAddress: '' |
|
|
|
} |
|
|
|
try { |
|
|
|
// 获取ip转为地点并记录
|
|
|
|
let ip = |
|
|
|
// '117.90.39.49' ||
|
|
|
|
ctx.ip |
|
|
|
console.log(`当前登录用户IP:${ip}`); |
|
|
|
if (ip && /^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)$/.test(ip)) { |
|
|
|
const ipLocationRes = await ctx.app.fs.godRequest.post('ip', { |
|
|
|
query: { |
|
|
|
ip, |
|
|
|
} |
|
|
|
}) |
|
|
|
if (ipLocationRes) { |
|
|
|
userUpdateData.lastInAddress = ipLocationRes.province + ipLocationRes.city |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`IP GET, error: ${error}`); |
|
|
|
} |
|
|
|
|
|
|
|
await models.User.update(userUpdateData, { |
|
|
|
where: { |
|
|
|
id: emisLoginRes.id |
|
|
|
} |
|
|
|
}) |
|
|
|
emisLoginRes.hrUserInfo = undefined |
|
|
|
|
|
|
|
await ctx.redis.hmset(emisLoginRes.token, { |
|
|
|
expired: moment().add(1, 'day'), |
|
|
|
userInfo:JSON.stringify(emisLoginRes) |
|
|
|
userInfo: JSON.stringify(emisLoginRes) |
|
|
|
}); |
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|