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
|
## Fixed
|
||||||
- Invalid preferences are now automatically corrected
|
- Invalid preferences are now automatically corrected
|
||||||
|
- It is now impossible to add the same account twice
|
||||||
|
|
||||||
|
|
||||||
## [0.3.0] - 2023-08-25
|
## [0.3.0] - 2023-08-25
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
"addAccount": "Add account",
|
"addAccount": "Add account",
|
||||||
"cancel": "@:invariants.controls.cancel",
|
"cancel": "@:invariants.controls.cancel",
|
||||||
"error": {
|
"error": {
|
||||||
|
"accountAlreadyExists": "You already have an account on this domain that uses this local part.",
|
||||||
"invalidBase64": "The key must be a valid base64 string.",
|
"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).",
|
"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.",
|
"invalidSeparator": "The separator must be a single character.",
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
"addAccount": "Ajouter",
|
"addAccount": "Ajouter",
|
||||||
"cancel": "@:invariants.controls.cancel",
|
"cancel": "@:invariants.controls.cancel",
|
||||||
"error": {
|
"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.",
|
"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).",
|
"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.",
|
"invalidSeparator": "Le séparateur doit être un unique caractère.",
|
||||||
|
|
|
@ -51,11 +51,24 @@ const addAccount = () => {
|
||||||
resetErrorMessage();
|
resetErrorMessage();
|
||||||
var hasError = false;
|
var hasError = false;
|
||||||
var key = null;
|
var key = null;
|
||||||
|
var accountId = null;
|
||||||
if (separator.value.length != 1) {
|
if (separator.value.length != 1) {
|
||||||
hasError = setErrorMessage('addAccount.error.invalidSeparator', separatorErrorMessageId);
|
hasError = setErrorMessage('addAccount.error.invalidSeparator', separatorErrorMessageId);
|
||||||
}
|
}
|
||||||
if (localPart.value.includes(separator.value)) {
|
try {
|
||||||
hasError = setErrorMessage('addAccount.error.localPartSeparator', localPartErrorMessageId);
|
if (localPart.value.includes(separator.value)) {
|
||||||
|
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 {
|
try {
|
||||||
key = base64Decode(privateKey.value);
|
key = base64Decode(privateKey.value);
|
||||||
|
@ -65,8 +78,8 @@ const addAccount = () => {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
hasError = setErrorMessage(e.message, addrKeyErrorMessageId);
|
hasError = setErrorMessage(e.message, addrKeyErrorMessageId);
|
||||||
}
|
}
|
||||||
if (!hasError) {
|
if (!hasError && key && accountId) {
|
||||||
const hash = sha256(`${localPart.value}@${domainName.value}`);
|
const hash = sha256(accountId);
|
||||||
const newAccount = {
|
const newAccount = {
|
||||||
id: base32Encode(hash, 'RFC4648', { padding: false }).toLowerCase(),
|
id: base32Encode(hash, 'RFC4648', { padding: false }).toLowerCase(),
|
||||||
localPart: localPart.value,
|
localPart: localPart.value,
|
||||||
|
|
Loading…
Reference in a new issue