Files
certd/packages/ui/certd-server/src/controller/sys/account/account-controller.ts
T

56 lines
1.8 KiB
TypeScript
Raw Normal View History

2026-05-31 01:41:33 +08:00
import { ALL, Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
import { BaseController, PlusService, SysInstallInfo, SysSettingsService } from "@certd/lib-server";
2024-09-23 01:52:42 +08:00
export type PreBindUserReq = {
userId: number;
};
2024-09-23 13:33:46 +08:00
export type BindUserReq = {
userId: number;
};
2024-09-23 01:52:42 +08:00
/**
*/
@Provide()
2026-05-31 01:41:33 +08:00
@Controller("/api/sys/account")
2024-09-23 01:52:42 +08:00
export class BasicController extends BaseController {
@Inject()
plusService: PlusService;
@Inject()
sysSettingsService: SysSettingsService;
2026-05-31 01:41:33 +08:00
@Post("/preBindUser", { description: "sys:settings:edit" })
2024-09-23 01:52:42 +08:00
public async preBindUser(@Body(ALL) body: PreBindUserReq) {
// 设置缓存内容
2026-03-04 23:15:48 +08:00
if (body.userId == null || body.userId <= 0) {
throw new Error("用户ID不能为空");
}
2024-11-07 02:22:14 +08:00
await this.plusService.userPreBind(body.userId);
2024-09-23 01:52:42 +08:00
return this.ok({});
}
2024-09-23 13:33:46 +08:00
2026-05-31 01:41:33 +08:00
@Post("/bindUser", { description: "sys:settings:edit" })
2024-09-23 13:33:46 +08:00
public async bindUser(@Body(ALL) body: BindUserReq) {
2026-03-04 23:15:48 +08:00
if (body.userId == null || body.userId <= 0) {
throw new Error("用户ID不能为空");
}
2024-09-23 13:33:46 +08:00
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
installInfo.bindUserId = body.userId;
await this.sysSettingsService.saveSetting(installInfo);
return this.ok({});
}
2026-05-31 01:41:33 +08:00
@Post("/unbindUser", { description: "sys:settings:edit" })
2024-09-23 13:33:46 +08:00
public async unbindUser() {
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
installInfo.bindUserId = null;
await this.sysSettingsService.saveSetting(installInfo);
return this.ok({});
}
2024-09-23 14:04:33 +08:00
2026-05-31 01:41:33 +08:00
@Post("/updateLicense", { description: "sys:settings:edit" })
2024-09-23 14:04:33 +08:00
public async updateLicense(@Body(ALL) body: { license: string }) {
2024-09-24 11:11:08 +08:00
await this.plusService.updateLicense(body.license);
2024-09-23 14:04:33 +08:00
return this.ok(true);
}
2024-09-23 01:52:42 +08:00
}