mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-09-11 12:46:19 +00:00
handle exist email duplicate in sub group
This commit is contained in:
parent
1c4fe53284
commit
93ea2b80dd
2 changed files with 23 additions and 8 deletions
|
@ -230,20 +230,29 @@
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
makeGroupEmailsUnique(dbInbounds, baseEmail, groupClients) {
|
makeGroupEmailsUnique(dbInbounds, baseEmail, groupClients) {
|
||||||
|
// Extract the base part of the email (before the "__" if present)
|
||||||
const match = baseEmail.match(/^(.*?)__/);
|
const match = baseEmail.match(/^(.*?)__/);
|
||||||
let base = match ? match[1] : baseEmail;
|
const base = match ? match[1] : baseEmail;
|
||||||
|
|
||||||
|
// Generate initial emails for each client in the group
|
||||||
const generatedEmails = groupClients.map((_, index) => `${base}__${index + 1}`);
|
const generatedEmails = groupClients.map((_, index) => `${base}__${index + 1}`);
|
||||||
|
|
||||||
const isDuplicate = (emailToCheck) => {
|
// Function to check if an email already exists in dbInbounds but belongs to a different subId
|
||||||
|
const isDuplicate = (emailToCheck, clientSubId) => {
|
||||||
return dbInbounds.some((dbInbound) => {
|
return dbInbounds.some((dbInbound) => {
|
||||||
const settings = JSON.parse(dbInbound.settings);
|
const settings = JSON.parse(dbInbound.settings);
|
||||||
const clients = settings && settings.clients ? settings.clients : [];
|
const clients = settings && settings.clients ? settings.clients : [];
|
||||||
return clients.some(client => emailToCheck.includes(client.email));
|
return clients.some(client => client.email === emailToCheck && client.subId !== clientSubId);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (generatedEmails.some(email => isDuplicate(email))) {
|
// Check if any of the generated emails are duplicates
|
||||||
|
const hasDuplicates = generatedEmails.some((email, index) => {
|
||||||
|
return isDuplicate(email, groupClients[index].subId);
|
||||||
|
});
|
||||||
|
|
||||||
|
// If duplicates exist, add a random string to the base email to ensure uniqueness
|
||||||
|
if (hasDuplicates) {
|
||||||
const randomString = `-${RandomUtil.randomLowerAndNum(4)}`;
|
const randomString = `-${RandomUtil.randomLowerAndNum(4)}`;
|
||||||
return groupClients.map((_, index) => `${base}${randomString}__${index + 1}`);
|
return groupClients.map((_, index) => `${base}${randomString}__${index + 1}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1017,8 +1017,11 @@
|
||||||
okText: '{{ i18n "pages.client.submitAdd"}}',
|
okText: '{{ i18n "pages.client.submitAdd"}}',
|
||||||
dbInbounds: this.dbInbounds,
|
dbInbounds: this.dbInbounds,
|
||||||
confirm: async (clients, dbInboundIds) => {
|
confirm: async (clients, dbInboundIds) => {
|
||||||
await this.addGroupClient(clients, dbInboundIds, clientModal);
|
await this.addGroupClient(clients, dbInboundIds, clientModal).then((res) => {
|
||||||
await this.showQrcode(dbInboundIds[0],clients[0], true)
|
if(res){
|
||||||
|
this.showQrcode(dbInboundIds[0],clients[0], true)
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
isEdit: false
|
isEdit: false
|
||||||
});
|
});
|
||||||
|
@ -1030,8 +1033,11 @@
|
||||||
okText: '{{ i18n "pages.client.submitAdd"}}',
|
okText: '{{ i18n "pages.client.submitAdd"}}',
|
||||||
dbInbound: dbInbound,
|
dbInbound: dbInbound,
|
||||||
confirm: async (clients, dbInboundId) => {
|
confirm: async (clients, dbInboundId) => {
|
||||||
await this.addClient(clients, dbInboundId, clientModal);
|
await this.addClient(clients, dbInboundId, clientModal).then((res) => {
|
||||||
await this.showQrcode(dbInboundId,clients)
|
if(res){
|
||||||
|
this.showQrcode(dbInboundId,clients)
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
isEdit: false
|
isEdit: false
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue