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]
### Added
- Possibility to set a default account
### Changed
- 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

View file

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

View file

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

View file

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

View file

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

View file

@ -11,12 +11,8 @@ import LayoutComponent from '../components/LayoutComponent.vue';
import NavBarComponent from '../components/NavBarComponent.vue';
const router = useRouter();
const accounts = useStorage('sake-accounts', []);
const sortedAccounts = computed(() => sortAccounts(accounts.value));
const selectedAccountId = ref((() => {
const def = accounts.value.find((a) => a.isDefault);
return def ? def.id : accounts.value[0].id;
})());
const accounts = sortAccounts(useStorage('sake-accounts', []));
const selectedAccountId = ref(accounts.value[0].id);
const subAddrName = ref('');
const fromRawAccount = (raw_account) => {
@ -33,20 +29,15 @@ const generatedAddr = computed(() => {
const raw_account = accounts.value.find((e) => e.id == selectedAccountId.value);
if (raw_account) {
const account = fromRawAccount(raw_account);
if (subAddrName.value.indexOf(account.separator) != -1) {
subAddrName.value = subAddrName.value.replaceAll(account.separator, '');
}
if (subAddrName.value) {
var hasher = hmac.create(sha256, account.key);
hasher.update(account.localPart);
hasher.update(account.separator);
hasher.update(subAddrName.value);
const mac = hasher.digest();
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}`;
}
var hasher = hmac.create(sha256, account.key);
hasher.update(account.localPart);
hasher.update(account.separator);
hasher.update(subAddrName.value);
const mac = hasher.digest();
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 '';
@ -67,7 +58,7 @@ const resetForm = () => {
<div class="mb-3">
<label class="form-label" for="account-name">{{ $t("main.account") }}</label>
<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>
</div>

View file

@ -1,24 +1,16 @@
<script setup>
import { sortAccounts } from '../accounts';
import { computed } from 'vue';
import { RouterLink, useRouter } from 'vue-router';
import { useStorage } from '@vueuse/core';
import ButtonGroupComponent from '../components/ButtonGroupComponent.vue';
import LayoutComponent from '../components/LayoutComponent.vue';
const router = useRouter();
const accounts = useStorage('sake-accounts', []);
const sortedAccounts = computed(() => sortAccounts(accounts.value));
const accounts = sortAccounts(useStorage('sake-accounts', []));
const deleteAccount = (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 = () => {
return router.push('/');
};
@ -30,13 +22,11 @@ const toMainView = () => {
<table class="table">
<tbody>
<tr v-for="account in sortedAccounts">
<tr v-for="account in accounts">
<th class="text-end align-middle">
<span class="badge text-bg-primary" v-if="account.isDefault">{{ $t("manageAccounts.isDefault") }}</span>
{{ account.localPart }}@{{ account.domain }}
</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>
</th>
</tr>