From 92620cdedb88df32fbc22685072e8eb908609256 Mon Sep 17 00:00:00 2001 From: Dream Hunter Date: Sun, 5 Jan 2025 18:51:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20`DISABLE=5FANONYMOUS=5FUSER=5FCRE?= =?UTF-8?q?ATE=5FEMAIL`=20which=20only=20allow=20logi=E2=80=A6=20(#545)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat: add `DISABLE_ANONYMOUS_USER_CREATE_EMAIL` which only allow login user create email address --- CHANGELOG.md | 1 + frontend/src/api/index.js | 1 + frontend/src/store/index.js | 1 + frontend/src/views/common/Login.vue | 14 +++++++++++--- vitepress-docs/docs/en/cli.md | 2 ++ vitepress-docs/docs/zh/guide/cli/worker.md | 2 ++ worker/src/admin_api/worker_config.ts | 1 + worker/src/commom_api.ts | 1 + worker/src/mails_api/index.ts | 5 +++++ worker/src/types.d.ts | 1 + worker/wrangler.toml.template | 2 ++ 11 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb5bb8e1..b50027d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - fix: |UI| 修复 admin portal 无收件人邮箱删除调用api 错误 - feat: |Telegram Bot| 增加 telegram bot 清理无效地址凭证命令 +- feat: 增加 worker 配置 `DISABLE_ANONYMOUS_USER_CREATE_EMAIL` 禁用匿名用户创建邮箱地址,只允许登录用户创建邮箱地址 ## v0.8.3 diff --git a/frontend/src/api/index.js b/frontend/src/api/index.js index 18237394..c4426c87 100644 --- a/frontend/src/api/index.js +++ b/frontend/src/api/index.js @@ -75,6 +75,7 @@ const getOpenSettings = async (message) => { }), adminContact: res["adminContact"] || "", enableUserCreateEmail: res["enableUserCreateEmail"] || false, + disableAnonymousUserCreateEmail: res["disableAnonymousUserCreateEmail"] || false, enableUserDeleteEmail: res["enableUserDeleteEmail"] || false, enableAutoReply: res["enableAutoReply"] || false, enableIndexAbout: res["enableIndexAbout"] || false, diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index 320ba18d..4f229a48 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -19,6 +19,7 @@ export const useGlobalState = createGlobalState( needAuth: false, adminContact: '', enableUserCreateEmail: false, + disableAnonymousUserCreateEmail: false, enableUserDeleteEmail: false, enableAutoReply: false, enableIndexAbout: false, diff --git a/frontend/src/views/common/Login.vue b/frontend/src/views/common/Login.vue index da56e4c0..c8312acd 100644 --- a/frontend/src/views/common/Login.vue +++ b/frontend/src/views/common/Login.vue @@ -184,6 +184,15 @@ const domainsOptions = computed(() => { }); }); +const showNewAddressTab = computed(() => { + if (openSettings.value.disableAnonymousUserCreateEmail + && !userSettings.value.user_email + ) { + return false; + } + return openSettings.value.enableUserCreateEmail; +}); + onMounted(async () => { if (!openSettings.value.domains || openSettings.value.domains.length === 0) { await api.getOpenSettings(); @@ -209,8 +218,7 @@ onMounted(async () => { {{ t('login') }} - + @@ -218,7 +226,7 @@ onMounted(async () => { - + diff --git a/vitepress-docs/docs/en/cli.md b/vitepress-docs/docs/en/cli.md index 4159e507..1e173f11 100644 --- a/vitepress-docs/docs/en/cli.md +++ b/vitepress-docs/docs/en/cli.md @@ -107,6 +107,8 @@ JWT_SECRET = "xxx" # Key used to generate jwt BLACK_LIST = "" # Blacklist, used to filter senders, comma separated # Allow users to create email addresses ENABLE_USER_CREATE_EMAIL = true +# Disable anonymous user create email, if set true, users can only create email addresses after logging in +# DISABLE_ANONYMOUS_USER_CREATE_EMAIL = true # Allow users to delete messages ENABLE_USER_DELETE_EMAIL = true # Allow automatic replies to emails diff --git a/vitepress-docs/docs/zh/guide/cli/worker.md b/vitepress-docs/docs/zh/guide/cli/worker.md index 8b3da467..2210b519 100644 --- a/vitepress-docs/docs/zh/guide/cli/worker.md +++ b/vitepress-docs/docs/zh/guide/cli/worker.md @@ -79,6 +79,8 @@ JWT_SECRET = "xxx" # 用于生成 jwt 的密钥, jwt 用于给用户登录以及 BLACK_LIST = "" # 黑名单,用于过滤发件人,逗号分隔 # 是否允许用户创建邮件, 不配置则不允许 ENABLE_USER_CREATE_EMAIL = true +# 禁用匿名用户创建邮箱,如果设置为 true,则用户只能在登录后创建邮箱地址 +# DISABLE_ANONYMOUS_USER_CREATE_EMAIL = true # 允许用户删除邮件, 不配置则不允许 ENABLE_USER_DELETE_EMAIL = true # 允许自动回复邮件 diff --git a/worker/src/admin_api/worker_config.ts b/worker/src/admin_api/worker_config.ts index 81f90272..ec41cbda 100644 --- a/worker/src/admin_api/worker_config.ts +++ b/worker/src/admin_api/worker_config.ts @@ -33,6 +33,7 @@ export default { "ADMIN_CONTACT": c.env.ADMIN_CONTACT, "ENABLE_USER_CREATE_EMAIL": getBooleanValue(c.env.ENABLE_USER_CREATE_EMAIL), + "DISABLE_ANONYMOUS_USER_CREATE_EMAIL": getBooleanValue(c.env.DISABLE_ANONYMOUS_USER_CREATE_EMAIL), "ENABLE_USER_DELETE_EMAIL": getBooleanValue(c.env.ENABLE_USER_DELETE_EMAIL), "ENABLE_AUTO_REPLY": getBooleanValue(c.env.ENABLE_AUTO_REPLY), "COPYRIGHT": c.env.COPYRIGHT, diff --git a/worker/src/commom_api.ts b/worker/src/commom_api.ts index c9e9b3d0..ca120a49 100644 --- a/worker/src/commom_api.ts +++ b/worker/src/commom_api.ts @@ -28,6 +28,7 @@ api.get('/open_api/settings', async (c) => { "needAuth": needAuth, "adminContact": c.env.ADMIN_CONTACT, "enableUserCreateEmail": getBooleanValue(c.env.ENABLE_USER_CREATE_EMAIL), + "disableAnonymousUserCreateEmail": getBooleanValue(c.env.DISABLE_ANONYMOUS_USER_CREATE_EMAIL), "enableUserDeleteEmail": getBooleanValue(c.env.ENABLE_USER_DELETE_EMAIL), "enableAutoReply": getBooleanValue(c.env.ENABLE_AUTO_REPLY), "enableIndexAbout": getBooleanValue(c.env.ENABLE_INDEX_ABOUT), diff --git a/worker/src/mails_api/index.ts b/worker/src/mails_api/index.ts index 0f188ffc..0464064b 100644 --- a/worker/src/mails_api/index.ts +++ b/worker/src/mails_api/index.ts @@ -103,6 +103,11 @@ api.get('/api/settings', async (c) => { }) api.post('/api/new_address', async (c) => { + if (getBooleanValue(c.env.DISABLE_ANONYMOUS_USER_CREATE_EMAIL) + && !c.get("userPayload") + ) { + return c.text("New address for anonymous user is disabled", 403) + } if (!getBooleanValue(c.env.ENABLE_USER_CREATE_EMAIL)) { return c.text("New address is disabled", 403) } diff --git a/worker/src/types.d.ts b/worker/src/types.d.ts index c931b26c..41476ef4 100644 --- a/worker/src/types.d.ts +++ b/worker/src/types.d.ts @@ -33,6 +33,7 @@ export type Bindings = { ENABLE_AUTO_REPLY: string | boolean | undefined ENABLE_WEBHOOK: string | boolean | undefined ENABLE_USER_CREATE_EMAIL: string | boolean | undefined + DISABLE_ANONYMOUS_USER_CREATE_EMAIL: string | boolean | undefined ENABLE_USER_DELETE_EMAIL: string | boolean | undefined ENABLE_INDEX_ABOUT: string | boolean | undefined DEFAULT_SEND_BALANCE: number | string | undefined diff --git a/worker/wrangler.toml.template b/worker/wrangler.toml.template index ded66f6d..118722c1 100644 --- a/worker/wrangler.toml.template +++ b/worker/wrangler.toml.template @@ -49,6 +49,8 @@ JWT_SECRET = "xxx" BLACK_LIST = "" # Allow users to create email addresses ENABLE_USER_CREATE_EMAIL = true +# Disable anonymous user create email, if set true, users can only create email addresses after logging in +# DISABLE_ANONYMOUS_USER_CREATE_EMAIL = true # Allow users to delete messages ENABLE_USER_DELETE_EMAIL = true # Allow automatic replies to emails