mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
feat: 支持vip转移
This commit is contained in:
@@ -26,8 +26,9 @@ export class BasicController extends BaseController {
|
||||
public async preBindUser(@Body(ALL) body: PreBindUserReq) {
|
||||
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
||||
// 设置缓存内容
|
||||
await this.plusService.request({
|
||||
await this.plusService.requestWithoutSign({
|
||||
url: '/activation/subject/preBind',
|
||||
method: 'POST',
|
||||
data: {
|
||||
userId: body.userId,
|
||||
appKey: AppKey,
|
||||
@@ -53,4 +54,11 @@ export class BasicController extends BaseController {
|
||||
await this.sysSettingsService.saveSetting(installInfo);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/updateLicense', { summary: 'sys:settings:edit' })
|
||||
public async updateLicense(@Body(ALL) body: { license: string }) {
|
||||
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
||||
await this.plusService.updateLicense(installInfo.siteId, body.license);
|
||||
return this.ok(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
|
||||
import { SysInstallInfo } from '../../system/service/models.js';
|
||||
import { AppKey, getPlusInfo, isPlus } from '@certd/pipeline';
|
||||
import { SysInstallInfo, SysLicenseInfo } from '../../system/service/models.js';
|
||||
import { AppKey, getPlusInfo, isPlus, verify } from '@certd/pipeline';
|
||||
import * as crypto from 'crypto';
|
||||
import { request } from '../../../utils/http.js';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
@@ -16,6 +16,7 @@ export class PlusService {
|
||||
|
||||
async requestWithoutSign(config: any): Promise<any> {
|
||||
config.baseURL = this.plusServerBaseUrl;
|
||||
config.method = config.method || 'POST';
|
||||
return await request(config);
|
||||
}
|
||||
|
||||
@@ -76,4 +77,24 @@ export class PlusService {
|
||||
data: formData,
|
||||
});
|
||||
}
|
||||
|
||||
async updateLicense(siteId: string, license: string) {
|
||||
let licenseInfo: SysLicenseInfo = await this.sysSettingsService.getSetting(SysLicenseInfo);
|
||||
if (!licenseInfo) {
|
||||
licenseInfo = new SysLicenseInfo();
|
||||
}
|
||||
licenseInfo.license = license;
|
||||
await this.sysSettingsService.saveSetting(licenseInfo);
|
||||
|
||||
const verifyRes = await verify({
|
||||
subjectId: siteId,
|
||||
license,
|
||||
});
|
||||
|
||||
if (!verifyRes.isPlus) {
|
||||
const message = verifyRes.message || '授权码校验失败';
|
||||
logger.error(message);
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { SysSettingsService } from '../service/sys-settings-service.js';
|
||||
import { BaseController } from '../../../basic/base-controller.js';
|
||||
import { AppKey, verify } from '@certd/pipeline';
|
||||
import { SysInstallInfo, SysLicenseInfo } from '../service/models.js';
|
||||
import { AppKey } from '@certd/pipeline';
|
||||
import { SysInstallInfo } from '../service/models.js';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
import { PlusService } from '../../basic/service/plus-service.js';
|
||||
|
||||
@@ -21,10 +21,11 @@ export class SysPlusController extends BaseController {
|
||||
async active(@Body(ALL) body) {
|
||||
const { code } = body;
|
||||
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
||||
const siteId = installInfo.siteId;
|
||||
const formData = {
|
||||
appKey: AppKey,
|
||||
code,
|
||||
subjectId: installInfo.siteId,
|
||||
subjectId: siteId,
|
||||
};
|
||||
|
||||
const res: any = await this.plusService.active(formData);
|
||||
@@ -33,26 +34,10 @@ export class SysPlusController extends BaseController {
|
||||
logger.error('激活失败', res.message);
|
||||
return this.fail(res.message, 1);
|
||||
}
|
||||
|
||||
const license = res.data.license;
|
||||
|
||||
let licenseInfo: SysLicenseInfo = await this.sysSettingsService.getSetting(SysLicenseInfo);
|
||||
if (!licenseInfo) {
|
||||
licenseInfo = new SysLicenseInfo();
|
||||
}
|
||||
licenseInfo.license = license;
|
||||
await this.sysSettingsService.saveSetting(licenseInfo);
|
||||
await this.plusService.updateLicense(siteId, license);
|
||||
|
||||
const verifyRes = await verify({
|
||||
subjectId: installInfo.siteId,
|
||||
license,
|
||||
});
|
||||
|
||||
if (!verifyRes.isPlus) {
|
||||
const message = verifyRes.message || '授权码校验失败';
|
||||
logger.error(message);
|
||||
return this.fail(message, 1);
|
||||
}
|
||||
return this.ok(res.data);
|
||||
return this.ok(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user