Commit 9b18f9a7 authored by ml's avatar ml

日志

parent de83f4a5
......@@ -956,7 +956,7 @@
},
"node_modules/@madex/ex-js-public": {
"version": "1.0.0",
"resolved": "git+ssh://git@bitbucket.org/biiigle/ex-js-public.git#70be0b0aea2ef27e1862cc62631611ad9431c491",
"resolved": "git+ssh://git@bitbucket.org/biiigle/ex-js-public.git#a328aeba78ae3f4860368a6c790ef434f7dd53be",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
......
......@@ -91,7 +91,7 @@ export const saveAuth = async (req: any, aclAuthVO: AclAuthVO) => {
try {
await isAdminUserBySessionId(req.cookies.session_id);
await preCheckAuth(aclAuthVO);
let res = await aclRoleAuthService.saveAuth(aclAuthVO);
let res = await aclRoleAuthService.saveAuth(aclAuthVO, req.cookies.session_id);
return Res3Utils.result(res);
}
catch (e) {
......@@ -111,7 +111,7 @@ export const delAuth = async (req: any, aclAuthVO: AclAuthVO) => {
try {
await isAdminUserBySessionId(req.cookies.session_id);
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclAuthVO.id);
let res = await aclRoleAuthService.delAuth(aclAuthVO.id);
let res = await aclRoleAuthService.delAuth(aclAuthVO.id, req.cookies.session_id);
return Res3Utils.result(res);
}
catch (e) {
......@@ -235,7 +235,7 @@ export const changeRoleAuth = async (req: any, aclAuthVO: AclAuthVO) => {
try {
await isAdminUserBySessionId(req.cookies.session_id);
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclAuthVO.id);
let res = await aclRoleAuthService.changeRoleAuth(aclAuthVO.id, aclAuthVO.authIds);
let res = await aclRoleAuthService.changeRoleAuth(aclAuthVO.id, aclAuthVO.authIds, req.cookies.session_id);
return Res3Utils.result(res);
}
catch (e) {
......@@ -255,7 +255,7 @@ export const changeUserRole = async (req: any, aclRoleVO: AclRoleVO) => {
try {
await isAdminUserBySessionId(req.cookies.session_id);
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclRoleVO.user_id);
let res = await aclRoleAuthService.changeUserRole(aclRoleVO.user_id, aclRoleVO.roleIds);
let res = await aclRoleAuthService.changeUserRole(aclRoleVO.user_id, aclRoleVO.roleIds, req.cookies.session_id);
return Res3Utils.result(res);
}
catch (e) {
......
......@@ -36,7 +36,7 @@ export const add = async (req: any, aclUserInfoVO: AclUserInfoVO) => {
try {
await isAdminUserBySessionId(req.cookies.session_id);
await preCheck(aclUserInfoVO);
let res = await aclUserService.add(aclUserInfoVO);
let res = await aclUserService.add(aclUserInfoVO,req.cookies.session_id);
return Res3Utils.result(res);
}
catch (e) {
......@@ -55,7 +55,7 @@ export const update = async (req: any, aclUserInfoVO: AclUserInfoVO) => {
try {
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclUserInfoVO.user_id);
await isAdminUserBySessionId(req.cookies.session_id);
let res = await aclUserService.update(aclUserInfoVO);
let res = await aclUserService.update(aclUserInfoVO,req.cookies.session_id);
return Res3Utils.result(res);
}
catch (e) {
......@@ -75,7 +75,7 @@ export const updateStatus = async (req: any, aclUserInfoVO: AclUserInfoVO) => {
try {
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclUserInfoVO.user_id);
await isAdminUserBySessionId(req.cookies.session_id);
let res = await aclUserService.updateStatus(aclUserInfoVO);
let res = await aclUserService.updateStatus(aclUserInfoVO,req.cookies.session_id);
return Res3Utils.result(res);
}
catch (e) {
......@@ -95,7 +95,7 @@ export const resetPwd = async (req: any, aclUserInfoVO: AclUserInfoVO) => {
try {
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclUserInfoVO.user_id);
await isAdminUserBySessionId(req.cookies.session_id);
let res = await aclUserService.resetPwd(aclUserInfoVO);
let res = await aclUserService.resetPwd(aclUserInfoVO,req.cookies.session_id);
return Res3Utils.result(res);
}
catch (e) {
......
......@@ -39,7 +39,7 @@ export const changeForceStatus = async (req: any, authConfigVO: AuthConfigVO) =>
await isAdminUserBySessionId(req.cookies.session_id);
ApiAssert.notNull(ErrorCode.PARAM_MISS, authConfigVO.user_id);
ApiAssert.notNull(ErrorCode.PARAM_MISS, authConfigVO.force);
let res = await userAuthConfigService.changeForceStatus(Number(authConfigVO.user_id), authConfigVO.force);
let res = await userAuthConfigService.changeForceStatus(Number(authConfigVO.user_id), authConfigVO.force,req.cookies.session_id);
return Res3Utils.result(res);
}
catch (e) {
......@@ -60,7 +60,7 @@ export const changeLockedStatus = async (req: any, authConfigVO: AuthConfigVO) =
await isAdminUserBySessionId(req.cookies.session_id);
ApiAssert.notNull(ErrorCode.PARAM_MISS, authConfigVO.user_id);
//暂时只支持解锁
let res = await userAuthConfigService.changeLockedStatus(authConfigVO.user_id);
let res = await userAuthConfigService.changeLockedStatus(authConfigVO.user_id,req.cookies.session_id);
return Res3Utils.result(res);
}
catch (e) {
......@@ -79,7 +79,7 @@ export const resetTotp = async (req: any, authConfigVO: AuthConfigVO) => {
try {
await isAdminUserBySessionId(req.cookies.session_id);
ApiAssert.notNull(ErrorCode.PARAM_MISS, authConfigVO.user_id);
let res = await userAuthConfigService.resetTotp(authConfigVO.user_id);
let res = await userAuthConfigService.resetTotp(authConfigVO.user_id,req.cookies.session_id);
return Res3Utils.result(res);
}
catch (e) {
......
......@@ -2,6 +2,7 @@
import { madAdminOrmDB, aclAuth, aclUserRole, aclRoleAuth, aclRole } from "@madex/ex-ts-dao";
import { ErrorCode } from "../../../constant/errorCode";
import { getOneAclUserByUid } from "../../../utils/aclUserUtils";
import * as userOptLogService from "./userOptLog.service";
let { logger } = require('@madex/ex-js-public');
......@@ -9,7 +10,7 @@ let { logger } = require('@madex/ex-js-public');
export interface AclAuthVO {
id?: number;
pid?: number;//当前登陆的用户 的 user_id
pid?: number;
name?: string | any;
......@@ -141,7 +142,7 @@ export const getAuthByRole = async (role_id: number | undefined) => {
};
export const saveAuth = async (aclAuthVO: AclAuthVO) => {
export const saveAuth = async (aclAuthVO: AclAuthVO, session_id: any) => {
await _checkPid(aclAuthVO.pid);
if (aclAuthVO.id) {
await _checkUrl(aclAuthVO.url, aclAuthVO.id);
......@@ -160,10 +161,11 @@ export const saveAuth = async (aclAuthVO: AclAuthVO) => {
await _checkUrl(aclAuthVO.url);
aclAuth.prototype.create(aclAuthVO);
}
userOptLogService.addOptLog(null, `save auth : ${JSON.stringify(aclAuthVO)}`, userOptLogService.LogType.SAVE, '', session_id);
return "ok";
};
export const delAuth = async (id: number | undefined) => {
export const delAuth = async (id: number | undefined, session_id: any) => {
let exist = await aclAuth.prototype.find({
where: { id },
......@@ -207,6 +209,8 @@ export const delAuth = async (id: number | undefined) => {
}
throw e
}
userOptLogService.addOptLog(null, `del auth : ${JSON.stringify(exist)}`, userOptLogService.LogType.DEL, '', session_id);
return "ok"
};
export const roleList = async (aclRolePageVO: AclRolePageVO) => {
......@@ -269,6 +273,9 @@ export const saveRole = async (aclRoleVO: AclRoleVO) => {
type: aclRoleVO.type ? aclRoleVO.type : 0,
})
}
userOptLogService.addOptLog(aclRoleVO.creator, `save role : ${JSON.stringify(aclRoleVO)}`, userOptLogService.LogType.SAVE, '');
return "ok";
};
......@@ -323,12 +330,12 @@ export const delRole = async (id: number | any, currentUserId: number) => {
}
throw e
}
userOptLogService.addOptLog(currentUserId, `del role : ${JSON.stringify(exist)}`, userOptLogService.LogType.DEL, '');
return "ok"
};
export const changeRoleAuth = async (id: number | any, authIds: any) => {
export const changeRoleAuth = async (id: number | any, authIds: any, session_id: any) => {
let sp = authIds.split(",");
let role = await aclRole.prototype.find({
where: {
......@@ -420,12 +427,14 @@ export const changeRoleAuth = async (id: number | any, authIds: any) => {
throw e
}
}
userOptLogService.addOptLog(null, `change role auth : role_id : ${id}, authIds : ${authIds}`, userOptLogService.LogType.UPDATE, '', session_id);
return "ok"
};
export const changeUserRole = async (userId: number | any, roleIds: any, tx?: any) => {
export const changeUserRole = async (userId: number | any, roleIds: any, session_id: any) => {
let sp = roleIds.split(",");
await getOneAclUserByUid(userId);
let roleIDArr: any[] = [];
......@@ -444,12 +453,11 @@ export const changeUserRole = async (userId: number | any, roleIds: any, tx?: an
where: {
user_id: userId
},
transaction: tx,
})
}
else {
// 检查权限是不是都存在
let roleArr = await getRole(roleIDArr, tx);
let roleArr = await getRole(roleIDArr);
if (roleArr.length !== roleIDArr.length) {
throw ErrorCode.ROLE_EXIST_ILLEGAL
}
......@@ -458,7 +466,6 @@ export const changeUserRole = async (userId: number | any, roleIds: any, tx?: an
where: {
user_id: userId,
},
transaction: tx,
raw: true
});
let oldIDArr = oldData.map(item => item.role_id);
......@@ -484,7 +491,9 @@ export const changeUserRole = async (userId: number | any, roleIds: any, tx?: an
addData.push(item)
}
}
let tx;
try {
tx = await madAdminOrmDB.transaction()
if (deleteIDArr.length) {
await aclUserRole.prototype.destroy({
where: {
......@@ -501,12 +510,17 @@ export const changeUserRole = async (userId: number | any, roleIds: any, tx?: an
transaction: tx
})
}
await tx.commit();
tx = null;
}
catch (e) {
if (tx) {
await tx.rollback();
}
throw e
}
}
userOptLogService.addOptLog(null, `change user role : user_id : ${userId}, roleIds : ${roleIDArr}`, userOptLogService.LogType.UPDATE, '', session_id);
return "ok"
};
......
......@@ -4,6 +4,7 @@ import { AclUserInfoConst } from "../../../constant/aclUserConstant";
import { CryptUtils } from "../../../utils/crypt-utils";
import { ErrorCode } from "../../../constant/errorCode";
import { getOneAclUserByAccount, getOneAclUserByUid } from "../../../utils/aclUserUtils";
import * as userOptLogService from "./userOptLog.service";
let { logger } = require('@madex/ex-js-public');
......@@ -80,7 +81,7 @@ export const list = async (aclUserInfoPageVO: AclUserInfoPageVO) => {
});
return resList;
};
export const add = async (aclUserInfoVO: AclUserInfoVO) => {
export const add = async (aclUserInfoVO: AclUserInfoVO, session_id: any) => {
if (!aclUserInfoVO.createdAt) {
aclUserInfoVO.createdAt = new Date();
}
......@@ -102,11 +103,11 @@ export const add = async (aclUserInfoVO: AclUserInfoVO) => {
aclUserInfoVO.pwd_salt = CryptUtils.salt();
await aclUserInfo.prototype.create(aclUserInfoVO);
//TODO:写日志
userOptLogService.addOptLog(null, `add user : ${JSON.stringify(aclUserInfoVO)}`, userOptLogService.LogType.ADD, '', session_id);
return 'ok';
};
export const update = async (aclUserInfoVO: AclUserInfoVO) => {
export const update = async (aclUserInfoVO: AclUserInfoVO, session_id: any) => {
let userId = Number(aclUserInfoVO.user_id);
await getOneAclUserByUid(userId);
......@@ -127,11 +128,12 @@ export const update = async (aclUserInfoVO: AclUserInfoVO) => {
user_id: userId
}
});
//TODO:写日志
userOptLogService.addOptLog(null, `update user : ${JSON.stringify(aclUserInfoVO)}`, userOptLogService.LogType.UPDATE, '', session_id);
return 'ok';
};
export const updateStatus = async (aclUserInfoVO: AclUserInfoVO) => {
export const updateStatus = async (aclUserInfoVO: AclUserInfoVO, session_id: any) => {
let userId = Number(aclUserInfoVO.user_id);
await getOneAclUserByUid(userId);
......@@ -145,12 +147,12 @@ export const updateStatus = async (aclUserInfoVO: AclUserInfoVO) => {
user_id: userId
}
});
//TODO:写日志
userOptLogService.addOptLog(null, `update status : ${JSON.stringify(aclUserInfoVO)}`, userOptLogService.LogType.UPDATE, '', session_id);
return 'ok';
};
export const resetPwd = async (aclUserInfoVO: AclUserInfoVO) => {
export const resetPwd = async (aclUserInfoVO: AclUserInfoVO, session_id: any) => {
let userId = Number(aclUserInfoVO.user_id);
await getOneAclUserByUid(userId);
......@@ -166,7 +168,8 @@ export const resetPwd = async (aclUserInfoVO: AclUserInfoVO) => {
user_id: userId
}
});
//TODO:写日志
userOptLogService.addOptLog(null, `reset pwd : ${JSON.stringify(aclUserInfoVO)}`, userOptLogService.LogType.UPDATE, '', session_id);
return 'ok';
};
......
......@@ -9,6 +9,7 @@ import { getOneAclUserByAccount, getOneAclUserByUid } from "../../../utils/aclUs
import { RedisVal } from "../../../constant/redis-val";
import Config from "../../../../config";
import { AuthConfigConst } from "../../../constant/aclUserAuthConfigConstant";
import * as userOptLogService from "./userOptLog.service";
let { apiAssertUtils: ApiAssert, datetimeUtils: DatetimeUtils } = require('@madex/ex-js-public');
......@@ -140,7 +141,7 @@ export async function queryConfigList(userId: number | undefined, userType: any,
}
export async function changeForceStatus(userId: number, forceStatus: any) {
export async function changeForceStatus(userId: number, forceStatus: any, session_id: any) {
let arr = [AuthConfigConst.FORCE.FALSE, AuthConfigConst.FORCE.TRUE];
if (!arr.includes(forceStatus)) {
throw ErrorCode.PARAM_MISS
......@@ -181,11 +182,12 @@ export async function changeForceStatus(userId: number, forceStatus: any) {
if (Number(forceStatus) === AuthConfigConst.FORCE.TRUE && configExist && configExist.totp_encrypt !== '') {
await _deleteAllSessionByUserId(userId)
}
userOptLogService.addOptLog(null, `change user: ${userId} force status : ${forceStatus}`, userOptLogService.LogType.UPDATE, '', session_id);
return 'success'
}
export async function changeLockedStatus(userId: number | undefined) {
export async function changeLockedStatus(userId: number | undefined, session_id: any) {
//查询是否已有配置记录
let configExist = await _checkAndGetAuthConfig(userId)
......@@ -206,10 +208,11 @@ export async function changeLockedStatus(userId: number | undefined) {
updatedAt: new Date()
}
await aclUserAuthConfig.prototype.update(data2Update, { where: { id: configExist.id } })
userOptLogService.addOptLog(null, `change user:${userId} lock status : ${AuthConfigConst.IS_LOCKED.FALSE}`, userOptLogService.LogType.UPDATE, '', session_id);
return "success"
}
export async function resetTotp(userId: number | undefined) {
export async function resetTotp(userId: number | undefined, session_id: any) {
//查询是否已有配置记录
let configExist = await _checkAndGetAuthConfig(userId)
if (!configExist || configExist.totp_encrypt === '') {
......@@ -226,6 +229,8 @@ export async function resetTotp(userId: number | undefined) {
await aclUserAuthConfig.prototype.update(data2Update, { where: { id: configExist.id } })
//剔除登录态
await _deleteAllSessionByUserId(Number(userId));
userOptLogService.addOptLog(null, `reset user:${userId} totp`, userOptLogService.LogType.UPDATE, '', session_id);
return 'success'
}
......
......@@ -10,6 +10,7 @@ import * as userAuthConfigService from "../service/userAuthConfig.service";
import { getOneAclUserByAccount, getOneAclUserByUid } from "../../../utils/aclUserUtils";
import { RedisVal } from "../../../constant/redis-val";
import Config from "../../../../config";
import * as userOptLogService from "./userOptLog.service";
const Otplib = require('otplib');
......@@ -17,7 +18,7 @@ const Otplib = require('otplib');
const BIND_TOTP_REDIS_KEY_PRE = "bastard.totp."
let { apiAssertUtils: ApiAssert ,BigNumberUtils} = require('@madex/ex-js-public');
let { apiAssertUtils: ApiAssert, BigNumberUtils } = require('@madex/ex-js-public');
let { authCommon: AuthCommon, redisUtilsCommon: RedisClient, } = require('@madex/ex-js-common');
......@@ -99,7 +100,9 @@ export async function login(account: any, pwd: any, s: string) {
await RedisClient.writeSync(sessionId, cookies, Config.LOGIN_EXPIRED);
await _unlockPwd(userInfo.user_id);
//TODO:写日志
userOptLogService.addOptLog(userInfo.user_id, `user login`, userOptLogService.LogType.LOGIN, '');
return {
result: "success",
sessionId: sessionId,
......@@ -170,6 +173,7 @@ export async function updatePwd(userId: any, originPwd: any, newPwd: any) {
user_id: userId
}
});
userOptLogService.addOptLog(userInfo.user_id, `update self pwd`, userOptLogService.LogType.UPDATE, '');
return 'success';
}
......@@ -217,6 +221,7 @@ export async function bindTotpConfirm(sessionId: any, userId: any, totpCode: any
cookies.needConfirm = 0
await RedisClient.writeSync(sessionId, cookies, Config.LOGIN_EXPIRED)
}
userOptLogService.addOptLog(null, `bind totp`, userOptLogService.LogType.TOTP, '', sessionId);
return "success"
}
......@@ -267,7 +272,8 @@ async function _updateTotpConfig(userId: number, totpEncrypt: any) {
raw: true
}
await aclUserAuthConfig.prototype.update(data2Update, condition)
} else {
}
else {
let now = new Date()
let data2Add = {
user_id: userId,
......@@ -281,6 +287,7 @@ async function _updateTotpConfig(userId: number, totpEncrypt: any) {
await aclUserAuthConfig.prototype.create(data2Add)
}
}
/*
async function test() {
let pwd = CryptUtils.defPwd();
......
import { aclUserOptLog } from "@madex/ex-ts-dao";
import { getCurrentUserId } from "../../../utils/aclUserUtils";
let { logger } = require('@madex/ex-js-public');
export const LogType = {
DEFAULT: 0,//默认
LOGIN: 1,//登陆
ADD: 2,//添加
UPDATE: 3,//修改
DEL: 4,//删除
TOTP: 5,//谷歌
SAVE: 6,//保存(添加或修改)
}
export const addOptLog = async function (user_id: any, msg: any, type: any, fail_reason?: any, session_id?: any) {
try {
if ((!user_id && !session_id) || !msg) {
throw 'user_id or session_id or msg is null'
}
if (!user_id) {
user_id = await getCurrentUserId(session_id);
}
await aclUserOptLog.prototype.create({
user_id: user_id,
msg: msg,
type: type ? type : LogType.DEFAULT,
createdAt: new Date(),
updatedAt: new Date(),
fail_reason: fail_reason ? fail_reason : ''
})
}
catch (e) {
logger.error('optLogService.addOptLog.error:' + e)
}
}
\ 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