Skip to content

Commit 2d2a712

Browse files
committed
feat: add human-readable format for pwned recheck max age in password policy
- Introduced a computed property to convert the pwned recheck maximum age from seconds to a human-readable format, enhancing user understanding of the recheck timing. - Updated the password policy UI to display this new information alongside the recheck settings, improving overall user experience and clarity.
1 parent 007ac85 commit 2d2a712

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

apps/web/src/pages/settings/password-policy.vue

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@
153153
hint="Re-check uniquement si la dernière vérification est plus ancienne que ce délai"
154154
dense
155155
)
156+
template(#append)
157+
q-chip(dense size="sm" color="grey-3" text-color="dark")
158+
span(v-text="pwnedRecheckMaxAgeHuman")
156159
q-select.col-12.col-sm-6.col-md-5.col-lg-4(
157160
:disable='!hasPermission("/settings/passwdadm", "update") || !payload.pwnedRecheckEnabled || !hibpKeyStatus.valid'
158161
outlined
@@ -201,7 +204,7 @@
201204
</template>
202205

203206
<script lang="ts">
204-
import { ref, watch } from 'vue'
207+
import { computed, ref, watch } from 'vue'
205208
206209
type PasswordPolicySettings = {
207210
len: number
@@ -260,6 +263,27 @@ export default defineComponent({
260263
const validations = ref({} as Record<string, any>)
261264
const hibpKeyStatus = ref<{ valid: boolean; reason: string | null }>({ valid: true, reason: null })
262265
266+
const pwnedRecheckMaxAgeHuman = computed(() => {
267+
const secondsRaw = Number(payload.value.pwnedRecheckMaxAgeSeconds || 0)
268+
if (!Number.isFinite(secondsRaw) || secondsRaw <= 0) return '0 minute'
269+
270+
let seconds = Math.floor(secondsRaw)
271+
const days = Math.floor(seconds / 86400)
272+
seconds -= days * 86400
273+
const hours = Math.floor(seconds / 3600)
274+
seconds -= hours * 3600
275+
const minutes = Math.floor(seconds / 60)
276+
seconds -= minutes * 60
277+
const secs = Math.floor(seconds)
278+
279+
const parts: string[] = []
280+
if (days) parts.push(`${days} jour${days > 1 ? 's' : ''}`)
281+
if (hours) parts.push(`${hours} heure${hours > 1 ? 's' : ''}`)
282+
if (minutes || parts.length === 0) parts.push(`${minutes} minute${minutes > 1 ? 's' : ''}`)
283+
if (secs) parts.push(`${secs} seconde${secs > 1 ? 's' : ''}`)
284+
return parts.join(' ')
285+
})
286+
263287
const {
264288
data: result,
265289
pending,
@@ -303,6 +327,7 @@ export default defineComponent({
303327
payload,
304328
pwnedActions,
305329
hibpKeyStatus,
330+
pwnedRecheckMaxAgeHuman,
306331
handleError,
307332
pending,
308333
refresh,

0 commit comments

Comments
 (0)