feat: add ADDRESS_REGEX (#401)

This commit is contained in:
Dream Hunter
2024-08-13 23:21:19 +08:00
committed by GitHub
parent 797b8bb019
commit d90f54345d
9 changed files with 43 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ export const useGlobalState = createGlobalState(
title: '',
announcement: '',
prefix: '',
addressRegex: '',
needAuth: false,
adminContact: '',
enableUserCreateEmail: false,

View File

@@ -72,7 +72,7 @@ const { locale, t } = useI18n({
login: 'Login',
pleaseGetNewEmail: 'Please login or click "Get New Email" button to get a new email address',
getNewEmail: 'Create New Email',
getNewEmailTip1: 'Please input the email you want to use. only allow a-z and 0-9',
getNewEmailTip1: 'Please input the email you want to use. only allow: ',
getNewEmailTip2: 'Levaing it blank will generate a random email address.',
getNewEmailTip3: 'You can choose a domain from the dropdown list.',
credential: 'Email Address Credential',
@@ -87,7 +87,7 @@ const { locale, t } = useI18n({
login: '登录',
pleaseGetNewEmail: '请"登录"或点击 "注册新邮箱" 按钮来获取一个新的邮箱地址',
getNewEmail: '创建新邮箱',
getNewEmailTip1: '请输入你想要使用的邮箱地址, 只允许 a-z, 0-9',
getNewEmailTip1: '请输入你想要使用的邮箱地址, 只允许: ',
getNewEmailTip2: '留空将会生成一个随机的邮箱地址。',
getNewEmailTip3: '你可以从下拉列表中选择一个域名。',
credential: '邮箱地址凭据',
@@ -101,6 +101,18 @@ const { locale, t } = useI18n({
}
});
const addressRegex = computed(() => {
try {
if (openSettings.value.addressRegex) {
return new RegExp(openSettings.value.addressRegex, 'g');
}
} catch (error) {
console.error(error);
message.error(`Invalid addressRegex: ${openSettings.value.addressRegex}`);
}
return /[^a-z0-9]/g;
});
const generateNameLoading = ref(false);
const generateName = async () => {
try {
@@ -110,7 +122,7 @@ const generateName = async () => {
.split('@')[0]
.replace(/\s+/g, '.')
.replace(/\.{2,}/g, '.')
.replace(/[^a-z0-9]/g, '')
.replace(addressRegex.value, '')
.toLowerCase();
} catch (error) {
message.error(error.message || "error");
@@ -206,7 +218,7 @@ onMounted(async () => {
<n-spin :show="generateNameLoading">
<n-form>
<span>
<p>{{ t("getNewEmailTip1") }}</p>
<p>{{ t("getNewEmailTip1") + addressRegex.source }}</p>
<p>{{ t("getNewEmailTip2") }}</p>
<p>{{ t("getNewEmailTip3") }}</p>
</span>