Browse Source

登录登出接口

master
巴林闲侠 2 years ago
parent
commit
9049f58014
  1. 52
      api/app/lib/controllers/auth/index.js

52
api/app/lib/controllers/auth/index.js

@ -17,60 +17,14 @@ async function login (ctx, next) {
if (!emisLoginRes) { if (!emisLoginRes) {
throw "无此用户,请使用正确的登录信息" throw "无此用户,请使用正确的登录信息"
} else { } 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.authorized = true
emisLoginRes.expired = moment().add(1, 'day') emisLoginRes.expired = moment().add(1, 'day')
emisLoginRes.pomsUserInfo = pomsRegisterRes.dataValues emisLoginRes.hrUserInfo = undefined
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
}
})
await ctx.redis.hmset(emisLoginRes.token, { await ctx.redis.hmset(emisLoginRes.token, {
expired: moment().add(1, 'day'), expired: moment().add(1, 'day'),
userInfo:JSON.stringify(emisLoginRes) userInfo: JSON.stringify(emisLoginRes)
}); });
ctx.status = 200; ctx.status = 200;

Loading…
Cancel
Save