feat: add CF Turnstile when new address (#200)

This commit is contained in:
Dream Hunter
2024-05-04 23:14:23 +08:00
committed by GitHub
parent 26969bebb8
commit f63c4ebd9c
14 changed files with 154 additions and 17 deletions

View File

@@ -1,11 +1,14 @@
<script setup>
import { ref, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import AdminContact from './admin/AdminContact.vue'
import Turnstile from '../components/Turnstile.vue'
import { useGlobalState } from '../store'
import { api } from '../api'
const message = useMessage()
const router = useRouter()
const {
jwt, localeCache, loading, openSettings, showPassword
@@ -15,6 +18,7 @@ const tabValue = ref('signin')
const password = ref('')
const emailName = ref("")
const emailDomain = ref("")
const cfToken = ref("")
const login = async () => {
if (!password.value) {
@@ -81,11 +85,14 @@ const generateName = async () => {
const newEmail = async () => {
try {
const res = await api.fetch(
`/api/new_address`
+ `?name=${emailName.value || ''}`
+ `&domain=${emailDomain.value || ''}`
);
const res = await api.fetch(`/api/new_address`, {
method: "POST",
body: JSON.stringify({
name: emailName.value,
domain: emailDomain.value,
cf_token: cfToken.value,
}),
});
jwt.value = res["jwt"];
await api.getSettings();
showPassword.value = true;
@@ -95,7 +102,7 @@ const newEmail = async () => {
};
onMounted(async () => {
emailDomain.value = openSettings.value.domains ? openSettings.value.domains[0].value : "";
emailDomain.value = openSettings.value.domains ? openSettings.value.domains[0]?.value : "";
});
</script>
@@ -136,6 +143,7 @@ onMounted(async () => {
<n-select v-model:value="emailDomain" :consistent-menu-width="false"
:options="openSettings.domains" />
</n-input-group>
<Turnstile v-model:value="cfToken" />
<n-button type="primary" block secondary strong @click="newEmail" :loading="loading">
{{ t('ok') }}
</n-button>

View File

@@ -21,7 +21,7 @@ const { t } = useI18n({
zh: {
save: '保存',
successTip: '保存成功',
address_block_list: '用户地址屏蔽关键词(管理员可跳过检查)',
address_block_list: '邮件地址屏蔽关键词(管理员可跳过检查)',
address_block_list_placeholder: '请输入您想要屏蔽的关键词',
send_address_block_list: '发送邮件地址屏蔽关键词',
}

View File

@@ -37,7 +37,7 @@ const { t } = useI18n({
tip: '请输入清理天数',
mailBoxLabel: '收件箱清理天数',
mailUnknowLabel: "无收件人邮件清理天数",
addressUnActiveLabel: "未活地址清理天数",
addressUnActiveLabel: "未活地址清理天数",
sendBoxLabel: "发件箱清理天数",
autoCleanup: "自动清理",
cleanupSuccess: "清理成功",

View File

@@ -14,14 +14,14 @@ const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: {
en: {
userCount: 'User Count',
activeUser: '7 days Active User',
userCount: 'Account Count',
activeUser: '7 days Active Mail Account',
mailCount: 'Mail Count',
sendMailCount: 'Send Mail Count'
},
zh: {
userCount: '用户总数',
activeUser: '周活跃用户',
userCount: '地址总数',
activeUser: '周活跃邮箱地址',
mailCount: '邮件总数',
sendMailCount: '发送邮件总数'
}