mirror of https://github.com/certd/certd
chore:
parent
cd83a6f209
commit
1c33fb4e14
|
@ -1,7 +1,8 @@
|
||||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||||
import { PlusRequestService } from '@certd/plus-core';
|
import { AppKey, PlusRequestService } from '@certd/plus-core';
|
||||||
import { logger } from '@certd/basic';
|
import { http, HttpRequestConfig, logger } from '@certd/basic';
|
||||||
import { SysInstallInfo, SysLicenseInfo, SysSettingsService } from '../../settings/index.js';
|
import { SysInstallInfo, SysLicenseInfo, SysSettingsService } from '../../settings/index.js';
|
||||||
|
import { merge } from 'lodash-es';
|
||||||
|
|
||||||
@Provide()
|
@Provide()
|
||||||
@Scope(ScopeEnum.Singleton)
|
@Scope(ScopeEnum.Singleton)
|
||||||
|
@ -65,9 +66,46 @@ export class PlusService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async userPreBind(userId: number) {
|
||||||
|
const plusRequestService = await this.getPlusRequestService();
|
||||||
|
await plusRequestService.requestWithoutSign({
|
||||||
|
url: '/activation/subject/preBind',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
userId,
|
||||||
|
appKey: AppKey,
|
||||||
|
subjectId: this.getSubjectId(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async sendEmail(email: any) {
|
||||||
|
const plusRequestService = await this.getPlusRequestService();
|
||||||
|
await plusRequestService.request({
|
||||||
|
url: '/activation/emailSend',
|
||||||
|
data: {
|
||||||
|
subject: email.subject,
|
||||||
|
text: email.content,
|
||||||
|
to: email.receivers,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async getAccessToken() {
|
async getAccessToken() {
|
||||||
const plusRequestService = await this.getPlusRequestService();
|
const plusRequestService = await this.getPlusRequestService();
|
||||||
await this.register();
|
await this.register();
|
||||||
return await plusRequestService.getAccessToken();
|
return await plusRequestService.getAccessToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async requestWithToken(config: HttpRequestConfig) {
|
||||||
|
const plusRequestService = await this.getPlusRequestService();
|
||||||
|
const token = await this.getAccessToken();
|
||||||
|
merge(config, {
|
||||||
|
baseURL: plusRequestService.getBaseURL(),
|
||||||
|
headers: {
|
||||||
|
Authorization: token,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return await http.request(config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||||
import { BaseController, PlusService } from '@certd/lib-server';
|
import { BaseController, PlusService, SysInstallInfo, SysSettingsService } from '@certd/lib-server';
|
||||||
import { AppKey } from '@certd/plus-core';
|
|
||||||
import { SysSettingsService } from '@certd/lib-server';
|
|
||||||
import { SysInstallInfo } from '@certd/lib-server';
|
|
||||||
|
|
||||||
export type PreBindUserReq = {
|
export type PreBindUserReq = {
|
||||||
userId: number;
|
userId: number;
|
||||||
|
@ -23,18 +20,8 @@ export class BasicController extends BaseController {
|
||||||
|
|
||||||
@Post('/preBindUser', { summary: 'sys:settings:edit' })
|
@Post('/preBindUser', { summary: 'sys:settings:edit' })
|
||||||
public async preBindUser(@Body(ALL) body: PreBindUserReq) {
|
public async preBindUser(@Body(ALL) body: PreBindUserReq) {
|
||||||
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
|
||||||
// 设置缓存内容
|
// 设置缓存内容
|
||||||
await this.plusService.requestWithoutSign({
|
await this.plusService.userPreBind(body.userId);
|
||||||
url: '/activation/subject/preBind',
|
|
||||||
method: 'POST',
|
|
||||||
data: {
|
|
||||||
userId: body.userId,
|
|
||||||
appKey: AppKey,
|
|
||||||
subjectId: installInfo.siteId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,14 +49,7 @@ export class EmailService implements IEmailService {
|
||||||
* receivers: string[];
|
* receivers: string[];
|
||||||
*/
|
*/
|
||||||
|
|
||||||
await this.plusService.request({
|
await this.plusService.sendEmail(email);
|
||||||
url: '/activation/emailSend',
|
|
||||||
data: {
|
|
||||||
subject: email.subject,
|
|
||||||
text: email.content,
|
|
||||||
to: email.receivers,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,7 +32,7 @@ export class CommonDnsProvider implements IDnsProvider {
|
||||||
|
|
||||||
await this.plusService.register();
|
await this.plusService.register();
|
||||||
|
|
||||||
const res = await this.plusService.requestWithoutSign({
|
const res = await this.plusService.requestWithToken({
|
||||||
url: '/activation/certd/cname/recordCreate',
|
url: '/activation/certd/cname/recordCreate',
|
||||||
data: {
|
data: {
|
||||||
subjectId: this.plusService.getSubjectId(),
|
subjectId: this.plusService.getSubjectId(),
|
||||||
|
@ -45,7 +45,7 @@ export class CommonDnsProvider implements IDnsProvider {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
async removeRecord(options: RemoveRecordOptions<any>) {
|
async removeRecord(options: RemoveRecordOptions<any>) {
|
||||||
const res = await this.plusService.requestWithoutSign({
|
const res = await this.plusService.requestWithToken({
|
||||||
url: '/activation/certd/cname/recordRemove',
|
url: '/activation/certd/cname/recordRemove',
|
||||||
data: {
|
data: {
|
||||||
subjectId: this.plusService.getSubjectId(),
|
subjectId: this.plusService.getSubjectId(),
|
||||||
|
|
Loading…
Reference in New Issue