Compare commits

..

No commits in common. "db117dab29c218f2228854de043022b4264f9333" and "f45c77ba64b821d0cd7d69d3f68bed93737a37bc" have entirely different histories.

7 changed files with 15 additions and 43 deletions

View file

@ -14,12 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added
- Possibility to set a default account
### Changed ### Changed
- The style has been entirely reworked using Bootstrap instead of Bulma - The style has been entirely reworked using Bootstrap instead of Bulma
- It is now impossible to include the separator in the dedicated name
## [0.3.0] - 2023-08-25 ## [0.3.0] - 2023-08-25

View file

@ -1,5 +1,5 @@
export function sortAccounts(accounts) { export function sortAccounts(accounts) {
accounts.sort((a, b) => { accounts.value.sort((a, b) => {
const va = `${a.localPart}@${a.domain}`; const va = `${a.localPart}@${a.domain}`;
const vb = `${b.localPart}@${b.domain}`; const vb = `${b.localPart}@${b.domain}`;
return va.localeCompare(vb); return va.localeCompare(vb);

View file

@ -71,8 +71,6 @@
}, },
"manageAccounts": { "manageAccounts": {
"title": "Accounts", "title": "Accounts",
"isDefault": "default",
"setDefault": "Set default",
"delete": "@:invariants.controls.delete", "delete": "@:invariants.controls.delete",
"close": "@:invariants.controls.close" "close": "@:invariants.controls.close"
} }

View file

@ -71,8 +71,6 @@
}, },
"manageAccounts": { "manageAccounts": {
"title": "Comptes", "title": "Comptes",
"isDefault": "défaut",
"setDefault": "Définir par défaut",
"delete": "@:invariants.controls.delete", "delete": "@:invariants.controls.delete",
"close": "@:invariants.controls.close" "close": "@:invariants.controls.close"
} }

View file

@ -62,7 +62,6 @@ const addAccount = () => {
separator: separator.value, separator: separator.value,
domain: domainName.value, domain: domainName.value,
key: key, key: key,
isDefault: false,
}; };
accounts.value.push(newAccount); accounts.value.push(newAccount);
return toMainView(); return toMainView();

View file

@ -11,12 +11,8 @@ import LayoutComponent from '../components/LayoutComponent.vue';
import NavBarComponent from '../components/NavBarComponent.vue'; import NavBarComponent from '../components/NavBarComponent.vue';
const router = useRouter(); const router = useRouter();
const accounts = useStorage('sake-accounts', []); const accounts = sortAccounts(useStorage('sake-accounts', []));
const sortedAccounts = computed(() => sortAccounts(accounts.value)); const selectedAccountId = ref(accounts.value[0].id);
const selectedAccountId = ref((() => {
const def = accounts.value.find((a) => a.isDefault);
return def ? def.id : accounts.value[0].id;
})());
const subAddrName = ref(''); const subAddrName = ref('');
const fromRawAccount = (raw_account) => { const fromRawAccount = (raw_account) => {
@ -33,20 +29,15 @@ const generatedAddr = computed(() => {
const raw_account = accounts.value.find((e) => e.id == selectedAccountId.value); const raw_account = accounts.value.find((e) => e.id == selectedAccountId.value);
if (raw_account) { if (raw_account) {
const account = fromRawAccount(raw_account); const account = fromRawAccount(raw_account);
if (subAddrName.value.indexOf(account.separator) != -1) { var hasher = hmac.create(sha256, account.key);
subAddrName.value = subAddrName.value.replaceAll(account.separator, ''); hasher.update(account.localPart);
} hasher.update(account.separator);
if (subAddrName.value) { hasher.update(subAddrName.value);
var hasher = hmac.create(sha256, account.key); const mac = hasher.digest();
hasher.update(account.localPart); const offset = mac[mac.length - 1] & 0xf;
hasher.update(account.separator); const reduced_mac = mac.slice(offset, offset + 5);
hasher.update(subAddrName.value); const code = base32Encode(reduced_mac, 'RFC4648', { padding: false }).toLowerCase();
const mac = hasher.digest(); return `${account.localPart}${account.separator}${subAddrName.value}${account.separator}${code}@${account.domain}`;
const offset = mac[mac.length - 1] & 0xf;
const reduced_mac = mac.slice(offset, offset + 5);
const code = base32Encode(reduced_mac, 'RFC4648', { padding: false }).toLowerCase();
return `${account.localPart}${account.separator}${subAddrName.value}${account.separator}${code}@${account.domain}`;
}
} }
} }
return ''; return '';
@ -67,7 +58,7 @@ const resetForm = () => {
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="account-name">{{ $t("main.account") }}</label> <label class="form-label" for="account-name">{{ $t("main.account") }}</label>
<select class="form-select" id="account-name" v-model="selectedAccountId"> <select class="form-select" id="account-name" v-model="selectedAccountId">
<option v-for="account in sortedAccounts" :key="account.id" :value="account.id">{{ account.localPart }}@{{ account.domain }}</option> <option v-for="account in accounts" :key="account.id" :value="account.id">{{ account.localPart }}@{{ account.domain }}</option>
</select> </select>
</div> </div>

View file

@ -1,24 +1,16 @@
<script setup> <script setup>
import { sortAccounts } from '../accounts'; import { sortAccounts } from '../accounts';
import { computed } from 'vue';
import { RouterLink, useRouter } from 'vue-router'; import { RouterLink, useRouter } from 'vue-router';
import { useStorage } from '@vueuse/core'; import { useStorage } from '@vueuse/core';
import ButtonGroupComponent from '../components/ButtonGroupComponent.vue'; import ButtonGroupComponent from '../components/ButtonGroupComponent.vue';
import LayoutComponent from '../components/LayoutComponent.vue'; import LayoutComponent from '../components/LayoutComponent.vue';
const router = useRouter(); const router = useRouter();
const accounts = useStorage('sake-accounts', []); const accounts = sortAccounts(useStorage('sake-accounts', []));
const sortedAccounts = computed(() => sortAccounts(accounts.value));
const deleteAccount = (accountId) => { const deleteAccount = (accountId) => {
return router.push(`/delete-account/${accountId}`); return router.push(`/delete-account/${accountId}`);
}; };
const setDefaultAccount = (accountId) => {
accounts.value = accounts.value.map((a) => {
a.isDefault = a.id === accountId;
return a;
});
};
const toMainView = () => { const toMainView = () => {
return router.push('/'); return router.push('/');
}; };
@ -30,13 +22,11 @@ const toMainView = () => {
<table class="table"> <table class="table">
<tbody> <tbody>
<tr v-for="account in sortedAccounts"> <tr v-for="account in accounts">
<th class="text-end align-middle"> <th class="text-end align-middle">
<span class="badge text-bg-primary" v-if="account.isDefault">{{ $t("manageAccounts.isDefault") }}</span>
{{ account.localPart }}@{{ account.domain }} {{ account.localPart }}@{{ account.domain }}
</th> </th>
<th> <th>
<button type="button" class="btn btn-primary me-2" @click="setDefaultAccount(account.id)" v-if="!account.isDefault">{{ $t("manageAccounts.setDefault") }}</button>
<button type="button" class="btn btn-danger" @click="deleteAccount(account.id)">{{ $t("manageAccounts.delete") }}</button> <button type="button" class="btn btn-danger" @click="deleteAccount(account.id)">{{ $t("manageAccounts.delete") }}</button>
</th> </th>
</tr> </tr>