Commit 9b18f9a7 authored by ml's avatar ml

日志

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