Forbid to add the same account twice
This commit is contained in:
parent
43b73bbe5f
commit
55ce44aebf
4 changed files with 20 additions and 4 deletions
|
@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## Fixed
|
||||
- Invalid preferences are now automatically corrected
|
||||
- It is now impossible to add the same account twice
|
||||
|
||||
|
||||
## [0.3.0] - 2023-08-25
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
"addAccount": "Add account",
|
||||
"cancel": "@:invariants.controls.cancel",
|
||||
"error": {
|
||||
"accountAlreadyExists": "You already have an account on this domain that uses this local part.",
|
||||
"invalidBase64": "The key must be a valid base64 string.",
|
||||
"invalidKeyLength": "The key's length must be either 128 bits (16 bytes) or 256 bits (32 bytes).",
|
||||
"invalidSeparator": "The separator must be a single character.",
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
"addAccount": "Ajouter",
|
||||
"cancel": "@:invariants.controls.cancel",
|
||||
"error": {
|
||||
"accountAlreadyExists": "Vous avez déjà un compte sur ce nom de domaine qui utilise cette partie locale.",
|
||||
"invalidBase64": "La clé doit être une chaîne de caractère en base64.",
|
||||
"invalidKeyLength": "La longueur de la clé doit être de 128 bits (16 bytes) ou de 256 bits (32 bytes).",
|
||||
"invalidSeparator": "Le séparateur doit être un unique caractère.",
|
||||
|
|
|
@ -51,11 +51,24 @@ const addAccount = () => {
|
|||
resetErrorMessage();
|
||||
var hasError = false;
|
||||
var key = null;
|
||||
var accountId = null;
|
||||
if (separator.value.length != 1) {
|
||||
hasError = setErrorMessage('addAccount.error.invalidSeparator', separatorErrorMessageId);
|
||||
}
|
||||
try {
|
||||
if (localPart.value.includes(separator.value)) {
|
||||
hasError = setErrorMessage('addAccount.error.localPartSeparator', localPartErrorMessageId);
|
||||
throw new Error('addAccount.error.localPartSeparator');
|
||||
}
|
||||
accountId = `${localPart.value}@${domainName.value}`;
|
||||
for (const acc of accounts.value) {
|
||||
const comp = `${acc.localPart}@${acc.domain}`;
|
||||
if (accountId == comp) {
|
||||
throw new Error('addAccount.error.accountAlreadyExists');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
hasError = setErrorMessage(e.message, localPartErrorMessageId);
|
||||
}
|
||||
try {
|
||||
key = base64Decode(privateKey.value);
|
||||
|
@ -65,8 +78,8 @@ const addAccount = () => {
|
|||
} catch (e) {
|
||||
hasError = setErrorMessage(e.message, addrKeyErrorMessageId);
|
||||
}
|
||||
if (!hasError) {
|
||||
const hash = sha256(`${localPart.value}@${domainName.value}`);
|
||||
if (!hasError && key && accountId) {
|
||||
const hash = sha256(accountId);
|
||||
const newAccount = {
|
||||
id: base32Encode(hash, 'RFC4648', { padding: false }).toLowerCase(),
|
||||
localPart: localPart.value,
|
||||
|
|
Loading…
Reference in a new issue