mirror of
https://github.com/schroinerxy/cloud-mail.git
synced 2026-06-21 19:35:50 +08:00
新增注册邮箱名自定义字符过滤
This commit is contained in:
@@ -46,6 +46,7 @@ export const setting = sqliteTable('setting', {
|
||||
tgMsgFrom: text('tg_msg_from').default('only-name').notNull(),
|
||||
tgMsgTo: text('tg_msg_to').default('show').notNull(),
|
||||
tgMsgText: text('tg_msg_text').default('hide').notNull(),
|
||||
minEmailPrefix: integer('min_email_prefix').default(0).notNull()
|
||||
minEmailPrefix: integer('min_email_prefix').default(0).notNull(),
|
||||
emailPrefixFilter: text('email_prefix_filter').default('').notNull()
|
||||
});
|
||||
export default setting
|
||||
|
||||
@@ -28,6 +28,7 @@ const en = {
|
||||
pwdLengthLimit: 'Password length exceeds the limit',
|
||||
emailLengthLimit: 'Email length exceeds the limit',
|
||||
minEmailPrefix: 'Email must be at least {{msg}} characters',
|
||||
banEmailPrefix: 'Invalid characters in email address',
|
||||
pwdMinLength: 'Password must be at least 6 characters',
|
||||
notEmailDomain: 'Invalid email domain',
|
||||
emptyRegKey: 'Invite code cannot be empty',
|
||||
|
||||
@@ -27,8 +27,9 @@ const zh = {
|
||||
notExistEmailReply: '邮件不存在无法回复',
|
||||
pwdLengthLimit: '密码长度超出限制',
|
||||
emailLengthLimit: '邮箱长度超出限制',
|
||||
minEmailPrefix: '邮箱名不能小于{{msg}}位',
|
||||
pwdMinLength: '密码不能小于6位',
|
||||
minEmailPrefix: '邮箱名至少{{msg}}位',
|
||||
banEmailPrefix: '邮箱名包含非法字符',
|
||||
pwdMinLength: '密码至少六位',
|
||||
notEmailDomain: '非法邮箱域名',
|
||||
emptyRegKey: '注册码不能为空',
|
||||
notExistRegKey: '注册码不存在',
|
||||
|
||||
@@ -24,10 +24,19 @@ const init = {
|
||||
await this.v2DB(c);
|
||||
await this.v2_3DB(c);
|
||||
await this.v2_4DB(c);
|
||||
await this.v2_5DB(c);
|
||||
await settingService.refresh(c);
|
||||
return c.text(t('initSuccess'));
|
||||
},
|
||||
|
||||
async v2_5DB(c) {
|
||||
try {
|
||||
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN email_prefix_filter text NOT NULL DEFAULT '';`).run();
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
|
||||
async v2_4DB(c) {
|
||||
try {
|
||||
await c.env.db.prepare(`
|
||||
@@ -54,6 +63,7 @@ const init = {
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
async v2_3DB(c) {
|
||||
|
||||
@@ -17,7 +17,7 @@ const accountService = {
|
||||
|
||||
async add(c, params, userId) {
|
||||
|
||||
const {addEmailVerify , addEmail, manyEmail, addVerifyCount, minEmailPrefix} = await settingService.query(c);
|
||||
const { addEmailVerify , addEmail, manyEmail, addVerifyCount, minEmailPrefix, emailPrefixFilter } = await settingService.query(c);
|
||||
|
||||
let { email, token } = params;
|
||||
|
||||
@@ -43,6 +43,10 @@ const accountService = {
|
||||
throw new BizError(t('minEmailPrefix', { msg: minEmailPrefix } ));
|
||||
}
|
||||
|
||||
if (emailPrefixFilter.some(content => emailUtils.getName(email).includes(content))) {
|
||||
throw new BizError(t('banEmailPrefix'));
|
||||
}
|
||||
|
||||
let accountRow = await this.selectByEmailIncludeDel(c, email);
|
||||
|
||||
if (accountRow && accountRow.isDel === isDel.DELETE) {
|
||||
|
||||
@@ -26,7 +26,7 @@ const loginService = {
|
||||
|
||||
const { email, password, token, code } = params;
|
||||
|
||||
let {regKey, register, registerVerify, regVerifyCount, minEmailPrefix} = await settingService.query(c)
|
||||
let { regKey, register, registerVerify, regVerifyCount, minEmailPrefix, emailPrefixFilter } = await settingService.query(c)
|
||||
|
||||
if (oauth) {
|
||||
registerVerify = settingConst.registerVerify.CLOSE;
|
||||
@@ -45,6 +45,10 @@ const loginService = {
|
||||
throw new BizError(t('minEmailPrefix', { msg: minEmailPrefix } ));
|
||||
}
|
||||
|
||||
if (emailPrefixFilter.some(content => emailUtils.getName(email).includes(content))) {
|
||||
throw new BizError(t('banEmailPrefix'));
|
||||
}
|
||||
|
||||
if (emailUtils.getName(email).length > 64) {
|
||||
throw new BizError(t('emailLengthLimit'));
|
||||
}
|
||||
|
||||
@@ -58,6 +58,8 @@ const settingService = {
|
||||
setting.linuxdoCallbackUrl = c.env.linuxdo_callback_url;
|
||||
setting.linuxdoSwitch = linuxdoSwitch;
|
||||
|
||||
setting.emailPrefixFilter = setting.emailPrefixFilter.split(",").filter(Boolean);
|
||||
|
||||
c.set?.('setting', setting);
|
||||
return setting;
|
||||
},
|
||||
@@ -108,6 +110,11 @@ const settingService = {
|
||||
Object.keys(resendTokens).forEach(domain => {
|
||||
if (!resendTokens[domain]) delete resendTokens[domain];
|
||||
});
|
||||
|
||||
if (Array.isArray(params.emailPrefixFilter)) {
|
||||
params.emailPrefixFilter = params.emailPrefixFilter + '';
|
||||
}
|
||||
|
||||
params.resendTokens = JSON.stringify(resendTokens);
|
||||
await orm(c).update(setting).set({ ...params }).returning().get();
|
||||
await this.refresh(c);
|
||||
|
||||
Reference in New Issue
Block a user