mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
perf: 支持邮件模版设置
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { Rule, RuleType } from "@midwayjs/validate";
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { BaseController, Constants, SysSettingsService } from "@certd/lib-server";
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { Rule, RuleType } from "@midwayjs/validate";
|
||||
import { CaptchaService } from "../../modules/basic/service/captcha-service.js";
|
||||
import { CodeService } from "../../modules/basic/service/code-service.js";
|
||||
import { EmailService } from "../../modules/basic/service/email-service.js";
|
||||
import { CaptchaService } from "../../modules/basic/service/captcha-service.js";
|
||||
import { AddonGetterService } from "../../modules/pipeline/service/addon-getter-service.js";
|
||||
|
||||
export class SmsCodeReq {
|
||||
@Rule(RuleType.string().required())
|
||||
@@ -49,6 +50,9 @@ export class BasicController extends BaseController {
|
||||
@Inject()
|
||||
captchaService: CaptchaService;
|
||||
|
||||
@Inject()
|
||||
addonGetterService: AddonGetterService;
|
||||
|
||||
@Post('/captcha/get', { summary: Constants.per.guest })
|
||||
async getCaptcha(@Query("captchaAddonId") captchaAddonId:number) {
|
||||
const form = await this.captchaService.getCaptcha(captchaAddonId)
|
||||
@@ -83,17 +87,18 @@ export class BasicController extends BaseController {
|
||||
const opts = {
|
||||
verificationType: body.verificationType,
|
||||
verificationCodeLength: undefined,
|
||||
title: undefined,
|
||||
content: undefined,
|
||||
duration: undefined,
|
||||
};
|
||||
|
||||
if(body?.verificationType === 'forgotPassword') {
|
||||
opts.title = '找回密码';
|
||||
opts.content = '验证码:${code}。您正在找回密码,请输入验证码并完成操作。如非本人操作请忽略';
|
||||
opts.duration = FORGOT_PASSWORD_CODE_DURATION;
|
||||
opts.verificationCodeLength = 6;
|
||||
}else{
|
||||
opts.duration = 10;
|
||||
opts.verificationCodeLength = 6;
|
||||
}
|
||||
|
||||
|
||||
await this.codeService.checkCaptcha(body.captcha);
|
||||
await this.codeService.sendEmailCode(body.email, opts);
|
||||
// 设置缓存内容
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import {
|
||||
addonRegistry,
|
||||
AddonService,
|
||||
CrudController,
|
||||
SysPrivateSettings,
|
||||
SysPublicSettings,
|
||||
@@ -30,6 +31,8 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
|
||||
pipelineService: PipelineService;
|
||||
@Inject()
|
||||
codeService: CodeService;
|
||||
@Inject()
|
||||
addonService: AddonService;
|
||||
|
||||
getService() {
|
||||
return this.service;
|
||||
@@ -86,6 +89,25 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
|
||||
return this.ok(conf);
|
||||
}
|
||||
|
||||
@Post('/getEmailTemplates', { summary: 'sys:settings:view' })
|
||||
async getEmailTemplates(@Body(ALL) body) {
|
||||
const conf = await getEmailSettings(this.service, this.userSettingsService);
|
||||
const templates = conf.templates || {}
|
||||
|
||||
const emailTemplateProviders = await this.addonService.getDefineList("emailTemplate")
|
||||
|
||||
const proviers = []
|
||||
for (const item of emailTemplateProviders) {
|
||||
const templateConf = templates[item.name] || {}
|
||||
proviers.push({
|
||||
name: item.name,
|
||||
title: item.title,
|
||||
addonId : templateConf.addonId,
|
||||
})
|
||||
}
|
||||
return this.ok(proviers);
|
||||
}
|
||||
|
||||
@Post('/saveEmailSettings', { summary: 'sys:settings:edit' })
|
||||
async saveEmailSettings(@Body(ALL) body) {
|
||||
const conf = await getEmailSettings(this.service, this.userSettingsService);
|
||||
|
||||
@@ -18,24 +18,24 @@ export class EmailController extends BaseController {
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/list', { summary: Constants.per.authOnly })
|
||||
public async list() {
|
||||
const userId = super.getUserId();
|
||||
const res = await this.emailService.list(userId);
|
||||
return this.ok(res);
|
||||
}
|
||||
// @Post('/list', { summary: Constants.per.authOnly })
|
||||
// public async list() {
|
||||
// const userId = super.getUserId();
|
||||
// const res = await this.emailService.list(userId);
|
||||
// return this.ok(res);
|
||||
// }
|
||||
|
||||
@Post('/add', { summary: Constants.per.authOnly })
|
||||
public async add(@Body('email') email) {
|
||||
const userId = super.getUserId();
|
||||
await this.emailService.add(userId, email);
|
||||
return this.ok({});
|
||||
}
|
||||
// @Post('/add', { summary: Constants.per.authOnly })
|
||||
// public async add(@Body('email') email) {
|
||||
// const userId = super.getUserId();
|
||||
// await this.emailService.add(userId, email);
|
||||
// return this.ok({});
|
||||
// }
|
||||
|
||||
@Post('/delete', { summary: Constants.per.authOnly })
|
||||
public async delete(@Body('email') email) {
|
||||
const userId = super.getUserId();
|
||||
await this.emailService.delete(userId, email);
|
||||
return this.ok({});
|
||||
}
|
||||
// @Post('/delete', { summary: Constants.per.authOnly })
|
||||
// public async delete(@Body('email') email) {
|
||||
// const userId = super.getUserId();
|
||||
// await this.emailService.delete(userId, email);
|
||||
// return this.ok({});
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user