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
});
const { judgeAgent } = ctx.app.fs.utils
await models.OperationLog.create({
time: new Date().getTime(),
clientType: ctx.header['user-agent'],
clientType: judgeAgent(ctx.header['user-agent']),
content: '登录',
parameter: null,
userId: userInfo.id,
@ -135,9 +136,10 @@ async function logout(ctx) {
}
});
const { judgeAgent } = ctx.app.fs.utils
await models.OperationLog.create({
time: new Date().getTime(),
clientType: ctx.header['user-agent'],
clientType: judgeAgent(ctx.header['user-agent']),
content: '登出',
parameter: null,
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 { judgeAgent } = ctx.app.fs.utils
const userId = ctx.fs.api.userId;
await models.OperationLog.create({
time: new Date().getTime(),
clientType: ctx.header['user-agent'],
clientType: judgeAgent(ctx.header['user-agent']),
content: `下发泵站控制指令`,
parameter: null,
userId,

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

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