diff --git a/resources/js_vue3/components/Dots.vue b/resources/js_vue3/components/Dots.vue index 69816010..e0fa127f 100644 --- a/resources/js_vue3/components/Dots.vue +++ b/resources/js_vue3/components/Dots.vue @@ -8,6 +8,10 @@ type: Number, default: null }, + period: { // Used only to identify the dots component in Accounts.vue + type: Number, + default: null + }, }) const activeDot = ref(0) @@ -37,7 +41,8 @@ defineExpose({ turnOn, - turnOff + turnOff, + props }) diff --git a/resources/js_vue3/components/TotpLooper.vue b/resources/js_vue3/components/TotpLooper.vue index e5bf1227..ef998e17 100644 --- a/resources/js_vue3/components/TotpLooper.vue +++ b/resources/js_vue3/components/TotpLooper.vue @@ -58,9 +58,9 @@ /** * Starts looping */ - const startLoop = () => { + const startLoop = (generated_at = null) => { clearLooper() - generatedAt.value = props.generated_at + generatedAt.value = generated_at != null ? generated_at : props.generated_at emit('loop-started', initialStepIndex.value) @@ -110,7 +110,8 @@ defineExpose({ startLoop, - clearLooper + clearLooper, + props }) diff --git a/resources/js_vue3/services/twofaccountService.js b/resources/js_vue3/services/twofaccountService.js index 8879e129..48a729e0 100644 --- a/resources/js_vue3/services/twofaccountService.js +++ b/resources/js_vue3/services/twofaccountService.js @@ -7,6 +7,10 @@ export default { return apiClient.get('/twofaccounts' + (withOtp ? '?withOtp=1' : '')) }, + getByIds(ids, withOtp = false) { + return apiClient.get('/twofaccounts?ids=' + ids + (withOtp ? '&withOtp=1' : '')) + }, + get(id, config = {}) { return apiClient.get('/twofaccounts/' + id, { ...config }) }, diff --git a/resources/js_vue3/stores/twofaccounts.js b/resources/js_vue3/stores/twofaccounts.js index bfeda36a..7102da66 100644 --- a/resources/js_vue3/stores/twofaccounts.js +++ b/resources/js_vue3/stores/twofaccounts.js @@ -34,6 +34,19 @@ export const useTwofaccounts = defineStore({ ) }, + /** + * Lists unique periods used by twofaccounts in the collection + * ex: The items collection has 3 accounts with a period of 30s and 5 accounts with a period of 40s + * => The method will return [30, 40] + */ + periods(state) { + return state.items.filter(acc => acc.otp_type == 'totp').map(function(item) { + return { period: item.period, generated_at: item.otp?.generated_at } + }).filter((value, index, self) => index === self.findIndex((t) => ( + t.period === value.period + ))).sort() + }, + orderedIds(state) { return state.items.map(a => a.id) }, @@ -141,11 +154,20 @@ export const useTwofaccounts = defineStore({ }, /** - *Sorts accounts descending + * Sorts accounts descending */ sortDesc() { this.items.sort((a, b) => a.service < b.service ? 1 : -1) this.saveOrder() }, + + /** + * Gets the IDs of all accounts that match the given period + * @param {*} period + * @returns {Array} IDs of matching accounts + */ + accountIdsWithPeriod(period) { + return this.items.filter(a => a.period == period).map(item => item.id) + }, }, }) diff --git a/resources/js_vue3/views/Accounts.vue b/resources/js_vue3/views/Accounts.vue index 464878ab..be4f1bf2 100644 --- a/resources/js_vue3/views/Accounts.vue +++ b/resources/js_vue3/views/Accounts.vue @@ -1,6 +1,6 @@ - -