Browse Source

(*) 判断客户端类型

master
liujiangyong 10 months ago
parent
commit
02288e12a7
  1. 6
      api/app/lib/controllers/auth/index.js
  2. 3
      api/app/lib/controllers/bigScreen/index .js
  3. 3
      api/app/lib/controllers/organization/authority.js
  4. 12
      api/app/lib/controllers/organization/user.js
  5. 17
      api/app/lib/utils/func.js

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

@ -40,9 +40,10 @@ async function login(ctx, next) {
expired: expired expired: expired
}); });
const { judgeAgent } = ctx.app.fs.utils
await models.OperationLog.create({ await models.OperationLog.create({
time: new Date().getTime(), time: new Date().getTime(),
clientType: ctx.header['user-agent'], clientType: judgeAgent(ctx.header['user-agent']),
content: '登录', content: '登录',
parameter: null, parameter: null,
userId: userInfo.id, userId: userInfo.id,
@ -135,9 +136,10 @@ async function logout(ctx) {
} }
}); });
const { judgeAgent } = ctx.app.fs.utils
await models.OperationLog.create({ await models.OperationLog.create({
time: new Date().getTime(), time: new Date().getTime(),
clientType: ctx.header['user-agent'], clientType: judgeAgent(ctx.header['user-agent']),
content: '登出', content: '登出',
parameter: null, parameter: null,
userId: userInfo.userInfo.id, userId: userInfo.userInfo.id,

3
api/app/lib/controllers/bigScreen/index .js

@ -158,10 +158,11 @@ async function getCapabilitiesInvoke(ctx, next) {
const res = await ctx.app.iota.request.post(`/capabilities/invoke`, data) || {} const res = await ctx.app.iota.request.post(`/capabilities/invoke`, data) || {}
const { judgeAgent } = ctx.app.fs.utils
const userId = ctx.fs.api.userId; const userId = ctx.fs.api.userId;
await models.OperationLog.create({ await models.OperationLog.create({
time: new Date().getTime(), time: new Date().getTime(),
clientType: ctx.header['user-agent'], clientType: judgeAgent(ctx.header['user-agent']),
content: `下发泵站控制指令`, content: `下发泵站控制指令`,
parameter: null, parameter: null,
userId, userId,

3
api/app/lib/controllers/organization/authority.js

@ -74,9 +74,10 @@ async function updateUserRes(ctx, next) {
raw: true, raw: true,
transaction: transaction, transaction: transaction,
}) })
const { judgeAgent } = ctx.app.fs.utils
await models.OperationLog.create({ await models.OperationLog.create({
time: new Date().getTime(), time: new Date().getTime(),
clientType: ctx.header['user-agent'], clientType: judgeAgent(ctx.header['user-agent']),
content: `修改 (${user.name}) 用户权限`, content: `修改 (${user.name}) 用户权限`,
parameter: null, parameter: null,
userId: operationUserId, userId: operationUserId,

12
api/app/lib/controllers/organization/user.js

@ -48,10 +48,11 @@ async function creatUser(ctx, next) {
password: Hex.stringify(MD5(data.password)), password: Hex.stringify(MD5(data.password)),
delete: false, delete: false,
}) })
const { judgeAgent } = ctx.app.fs.utils
const userId = ctx.fs.api.userId; const userId = ctx.fs.api.userId;
await models.OperationLog.create({ await models.OperationLog.create({
time: new Date().getTime(), time: new Date().getTime(),
clientType: ctx.header['user-agent'], clientType: judgeAgent(ctx.header['user-agent']),
content: `新建用户:${data.name}`, content: `新建用户:${data.name}`,
parameter: null, parameter: null,
userId, userId,
@ -96,10 +97,11 @@ async function updateUser(ctx, next) {
where: { id } where: { id }
}); });
const { judgeAgent } = ctx.app.fs.utils
const userId = ctx.fs.api.userId; const userId = ctx.fs.api.userId;
await models.OperationLog.create({ await models.OperationLog.create({
time: new Date().getTime(), time: new Date().getTime(),
clientType: ctx.header['user-agent'], clientType: judgeAgent(ctx.header['user-agent']),
content: `修改 (${data.name}) 用户信息`, content: `修改 (${data.name}) 用户信息`,
parameter: null, parameter: null,
userId, userId,
@ -129,11 +131,12 @@ async function deleteUser(ctx, next) {
returning: true, returning: true,
}); });
const { judgeAgent } = ctx.app.fs.utils
const userId = ctx.fs.api.userId; const userId = ctx.fs.api.userId;
const userName = delUser[1].map(item => item.name).join() const userName = delUser[1].map(item => item.name).join()
await models.OperationLog.create({ await models.OperationLog.create({
time: new Date().getTime(), time: new Date().getTime(),
clientType: ctx.header['user-agent'], clientType: judgeAgent(ctx.header['user-agent']),
content: `删除用户:${userName}`, content: `删除用户:${userName}`,
parameter: null, parameter: null,
userId, userId,
@ -171,10 +174,11 @@ async function resetPwd(ctx, next) {
returning: true, returning: true,
}, },
); );
const { judgeAgent } = ctx.app.fs.utils
const userId = ctx.fs.api.userId; const userId = ctx.fs.api.userId;
await models.OperationLog.create({ await models.OperationLog.create({
time: new Date().getTime(), time: new Date().getTime(),
clientType: ctx.header['user-agent'], clientType: judgeAgent(ctx.header['user-agent']),
content: `修改 (${updateUser[1][0].name}) 用户密码`, content: `修改 (${updateUser[1][0].name}) 用户密码`,
parameter: null, parameter: null,
userId, userId,

17
api/app/lib/utils/func.js

@ -0,0 +1,17 @@
'use strict';
module.exports = function (app, opts) {
const judgeAgent = (userAgent = '') => {
if (/miniProgram/i.test(userAgent)) {
return '小程序'
} else if (/Mobi|Android|iPhone/i.test(userAgent)) {
return '手机浏览器'
} else {
return 'PC浏览器'
}
}
return {
judgeAgent,
}
}
Loading…
Cancel
Save