mirror of
https://github.com/certd/certd.git
synced 2026-07-28 23:57:41 +08:00
feat: 支持审计日志,操作日志
This commit is contained in:
@@ -3,6 +3,7 @@ import { BaseController } from "@certd/lib-server";
|
||||
import { Constants } from "@certd/lib-server";
|
||||
import { EmailService } from "../../../modules/basic/service/email-service.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -13,10 +14,15 @@ export class EmailController extends BaseController {
|
||||
@Inject()
|
||||
emailService: EmailService;
|
||||
|
||||
getAuditType(): string {
|
||||
return AuditType.mine;
|
||||
}
|
||||
|
||||
@Post("/test", { description: Constants.per.authOnly, summary: "测试邮件发送" })
|
||||
public async test(@Body("receiver") receiver) {
|
||||
const userId = super.getUserId();
|
||||
await this.emailService.test(userId, receiver);
|
||||
this.auditLog({ content: "测试了邮件发送" });
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@@ -31,6 +37,7 @@ export class EmailController extends BaseController {
|
||||
public async add(@Body("email") email) {
|
||||
const userId = super.getUserId();
|
||||
await this.emailService.add(userId, email);
|
||||
this.auditLog({ content: "添加了邮件" });
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@@ -38,6 +45,7 @@ export class EmailController extends BaseController {
|
||||
public async delete(@Body("email") email) {
|
||||
const userId = super.getUserId();
|
||||
await this.emailService.delete(userId, email);
|
||||
this.auditLog({ content: "删除了邮件" });
|
||||
return this.ok({});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { http, logger, utils } from "@certd/basic";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
import { CodeService } from "../../../modules/basic/service/code-service.js";
|
||||
import { EmailService } from "../../../modules/basic/service/email-service.js";
|
||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -40,6 +41,10 @@ export class MineController extends BaseController {
|
||||
@Inject()
|
||||
emailService: EmailService;
|
||||
|
||||
getAuditType(): string {
|
||||
return AuditType.mine;
|
||||
}
|
||||
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询用户信息" })
|
||||
public async info() {
|
||||
const userId = this.getUserId();
|
||||
@@ -73,6 +78,7 @@ export class MineController extends BaseController {
|
||||
public async changePassword(@Body(ALL) body: any) {
|
||||
const userId = this.getUserId();
|
||||
await this.userService.changePassword(userId, body);
|
||||
this.auditLog({ content: "修改了密码" });
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@@ -80,6 +86,7 @@ export class MineController extends BaseController {
|
||||
public async initPassword(@Body(ALL) body: any) {
|
||||
const userId = this.getUserId();
|
||||
await this.userService.initPassword(userId, body);
|
||||
this.auditLog({ content: "初始化了密码" });
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@@ -91,6 +98,7 @@ export class MineController extends BaseController {
|
||||
avatar: body.avatar,
|
||||
nickName: body.nickName,
|
||||
});
|
||||
this.auditLog({ content: "更新了个人资料" });
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@@ -129,6 +137,7 @@ export class MineController extends BaseController {
|
||||
phoneCode: body.phoneCode,
|
||||
mobile: body.mobile,
|
||||
});
|
||||
this.auditLog({ content: "修改了手机号" });
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@@ -145,6 +154,7 @@ export class MineController extends BaseController {
|
||||
await this.userService.updateEmail(userId, {
|
||||
email: body.email,
|
||||
});
|
||||
this.auditLog({ content: "修改了邮箱" });
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@@ -198,6 +208,7 @@ export class MineController extends BaseController {
|
||||
}),
|
||||
});
|
||||
|
||||
this.auditLog({ content: "初始化了Let's Encrypt ACME账号和邮件通知" });
|
||||
return this.ok({ success: true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { PasskeyService } from "../../../modules/login/service/passkey-service.j
|
||||
import { BaseController, Constants } from "@certd/lib-server";
|
||||
import { UserService } from "../../../modules/sys/authority/service/user-service.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
@Provide()
|
||||
@Controller("/api/mine/passkey")
|
||||
@@ -14,6 +15,10 @@ export class MinePasskeyController extends BaseController {
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
|
||||
getAuditType(): string {
|
||||
return AuditType.mine;
|
||||
}
|
||||
|
||||
@Post("/generateRegistration", { description: Constants.per.authOnly, summary: "生成Passkey注册选项" })
|
||||
public async generateRegistration(
|
||||
@Body(ALL)
|
||||
@@ -46,7 +51,7 @@ export class MinePasskeyController extends BaseController {
|
||||
const deviceName = body.deviceName;
|
||||
|
||||
const result = await this.passkeyService.registerPasskey(userId, response, challenge, deviceName, this.ctx);
|
||||
|
||||
this.auditLog({ content: "验证注册了Passkey" });
|
||||
return this.ok(result);
|
||||
}
|
||||
|
||||
@@ -62,6 +67,7 @@ export class MinePasskeyController extends BaseController {
|
||||
|
||||
const result = await this.passkeyService.registerPasskey(userId, response, challenge, deviceName, this.ctx);
|
||||
|
||||
this.auditLog({ content: "注册了Passkey" });
|
||||
return this.ok(result);
|
||||
}
|
||||
|
||||
@@ -90,6 +96,7 @@ export class MinePasskeyController extends BaseController {
|
||||
}
|
||||
|
||||
await this.passkeyService.delete([passkey.id]);
|
||||
this.auditLog({ content: "解绑了Passkey" });
|
||||
return this.ok({});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { merge } from "lodash-es";
|
||||
import { TwoFactorService } from "../../../modules/mine/service/two-factor-service.js";
|
||||
import { isPlus } from "@certd/plus-core";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -19,6 +20,10 @@ export class UserTwoFactorSettingController extends BaseController {
|
||||
@Inject()
|
||||
twoFactorService: TwoFactorService;
|
||||
|
||||
getAuditType(): string {
|
||||
return AuditType.mine;
|
||||
}
|
||||
|
||||
@Post("/get", { description: Constants.per.authOnly, summary: "获取双因子认证设置" })
|
||||
async get() {
|
||||
const userId = this.getUserId();
|
||||
@@ -42,6 +47,7 @@ export class UserTwoFactorSettingController extends BaseController {
|
||||
}
|
||||
|
||||
await this.service.saveSetting(userId, null, setting);
|
||||
this.auditLog({ content: "保存了双因子认证设置" });
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@@ -62,6 +68,7 @@ export class UserTwoFactorSettingController extends BaseController {
|
||||
userId,
|
||||
verifyCode: bean.verifyCode,
|
||||
});
|
||||
this.auditLog({ content: "保存了验证器设置" });
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@@ -69,6 +76,7 @@ export class UserTwoFactorSettingController extends BaseController {
|
||||
async authenticatorOff() {
|
||||
const userId = this.getUserId();
|
||||
await this.twoFactorService.offAuthenticator(userId);
|
||||
this.auditLog({ content: "关闭了验证器" });
|
||||
return this.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { UserGrantSetting } from "../../../modules/mine/service/models.js";
|
||||
import { isPlus } from "@certd/plus-core";
|
||||
import { merge } from "lodash-es";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -20,6 +21,10 @@ export class UserSettingsController extends CrudController<UserSettingsService>
|
||||
return this.service;
|
||||
}
|
||||
|
||||
getAuditType(): string {
|
||||
return AuditType.mine;
|
||||
}
|
||||
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询用户设置分页列表" })
|
||||
async page(@Body(ALL) body) {
|
||||
body.query = body.query ?? {};
|
||||
@@ -62,6 +67,7 @@ export class UserSettingsController extends CrudController<UserSettingsService>
|
||||
async save(@Body(ALL) bean: UserSettingsEntity) {
|
||||
bean.userId = this.getUserId();
|
||||
await this.service.save(bean);
|
||||
this.auditLog({ content: "保存了用户设置" });
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@@ -88,6 +94,7 @@ export class UserSettingsController extends CrudController<UserSettingsService>
|
||||
merge(setting, bean);
|
||||
|
||||
await this.service.saveSetting(userId, null, setting);
|
||||
this.auditLog({ content: "保存了授权设置" });
|
||||
return this.ok({});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user