mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
perf: 邮箱支持保存和选择
This commit is contained in:
@@ -17,4 +17,25 @@ export class EmailController extends BaseController {
|
||||
await this.emailService.test(userId, receiver);
|
||||
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('/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({});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { SendMailOptions } from 'nodemailer';
|
||||
import { UserSettingsService } from '../../mine/service/user-settings-service.js';
|
||||
import { PlusService, SysSettingsService, SysSiteInfo } from '@certd/lib-server';
|
||||
import { getEmailSettings } from '../../sys/settings/fix.js';
|
||||
import { UserEmailSetting } from "../../mine/service/models.js";
|
||||
|
||||
export type EmailConfig = {
|
||||
host: string;
|
||||
@@ -108,4 +109,24 @@ export class EmailService implements IEmailService {
|
||||
content: '测试邮件,from certd',
|
||||
});
|
||||
}
|
||||
|
||||
async list(userId: any) {
|
||||
const userEmailSetting = await this.settingsService.getSetting<UserEmailSetting>(userId,UserEmailSetting)
|
||||
return userEmailSetting.list;
|
||||
}
|
||||
|
||||
async delete(userId: any, email: string) {
|
||||
const userEmailSetting = await this.settingsService.getSetting<UserEmailSetting>(userId,UserEmailSetting)
|
||||
userEmailSetting.list = userEmailSetting.list.filter(item=>item !== email);
|
||||
await this.settingsService.saveSetting(userId,userEmailSetting)
|
||||
}
|
||||
async add(userId: any, email: string) {
|
||||
const userEmailSetting = await this.settingsService.getSetting<UserEmailSetting>(userId,UserEmailSetting)
|
||||
//如果已存在
|
||||
if(userEmailSetting.list.includes(email)){
|
||||
return
|
||||
}
|
||||
userEmailSetting.list.unshift(email)
|
||||
await this.settingsService.saveSetting(userId,userEmailSetting)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,3 +26,10 @@ export class UserSiteMonitorSetting extends BaseSettings {
|
||||
|
||||
notificationId?:number= 0;
|
||||
}
|
||||
|
||||
export class UserEmailSetting extends BaseSettings {
|
||||
static __title__ = "用户邮箱设置";
|
||||
static __key__ = "user.email";
|
||||
|
||||
list:string[] = [];
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ import { InjectEntityModel } from "@midwayjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
import { BaseService, BaseSettings } from "@certd/lib-server";
|
||||
import { UserSettingsEntity } from "../entity/user-settings.js";
|
||||
import { merge } from "lodash-es";
|
||||
|
||||
import { mergeUtils } from "@certd/basic";
|
||||
const {merge} = mergeUtils
|
||||
/**
|
||||
* 授权
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user