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

64 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-09-23 01:52:42 +08:00
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
2024-10-03 22:03:49 +08:00
import { BaseController } from '@certd/lib-server';
2024-09-23 01:52:42 +08:00
import { PlusService } from '../basic/service/plus-service.js';
import { AppKey } from '@certd/pipeline';
2024-10-03 22:03:49 +08:00
import { SysSettingsService } from '@certd/lib-server';
import { SysInstallInfo } 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()
@Controller('/api/sys/account')
export class BasicController extends BaseController {
@Inject()
plusService: PlusService;
@Inject()
sysSettingsService: SysSettingsService;
@Post('/preBindUser', { summary: 'sys:settings:edit' })
public async preBindUser(@Body(ALL) body: PreBindUserReq) {
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
// 设置缓存内容
2024-09-23 14:04:33 +08:00
await this.plusService.requestWithoutSign({
2024-09-23 01:52:42 +08:00
url: '/activation/subject/preBind',
2024-09-23 14:04:33 +08:00
method: 'POST',
2024-09-23 01:52:42 +08:00
data: {
userId: body.userId,
appKey: AppKey,
subjectId: installInfo.siteId,
},
});
return this.ok({});
}
2024-09-23 13:33:46 +08:00
@Post('/bindUser', { summary: 'sys:settings:edit' })
public async bindUser(@Body(ALL) body: BindUserReq) {
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
installInfo.bindUserId = body.userId;
await this.sysSettingsService.saveSetting(installInfo);
return this.ok({});
}
@Post('/unbindUser', { summary: 'sys:settings:edit' })
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
@Post('/updateLicense', { summary: 'sys:settings:edit' })
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
}