Ajoute les pages de compte au front et le favicon de la SSMG
- Inscription, suivi de l'inscription (lien de confirmation), seconde étape de connexion (code à 6 chiffres ou code de secours), mot de passe oublié et réinitialisation, page « Mon compte » (mot de passe, 2FA avec QR code et codes de secours), d'après les maquettes Penpot. - Les jetons reçus par e-mail sont retirés de l'URL dès l'arrivée. - Favicon de la SSMG (ssmg.be) ; retour en haut de page à chaque navigation. - 93 tests Vitest ; README et CLAUDE.md mis à jour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d2da878dbd
commit
0617fa8dc4
29 files changed
+2305
-58
No files matched your search
@@ -30,6 +30,9 @@ async function onLogout() {
|
||||
<template v-if="user">
|
||||
<nav class="d-none d-md-flex align-items-center gap-4">
|
||||
<span class="text-muted-prism">{{ $t('nav.doctor', { name: user.last_name }) }}</span>
|
||||
<RouterLink :to="{ name: 'account' }" class="nav-account">{{
|
||||
$t('nav.account')
|
||||
}}</RouterLink>
|
||||
<button type="button" class="btn btn-link nav-logout p-0" @click="onLogout">
|
||||
{{ $t('nav.logout') }}
|
||||
</button>
|
||||
@@ -47,6 +50,13 @@ async function onLogout() {
|
||||
</button>
|
||||
<div v-if="menuOpen" class="menu-overlay prism-card">
|
||||
<p class="mb-2 text-muted-prism">{{ $t('nav.doctor', { name: user.last_name }) }}</p>
|
||||
<RouterLink
|
||||
:to="{ name: 'account' }"
|
||||
class="nav-account d-block mb-2"
|
||||
@click="menuOpen = false"
|
||||
>
|
||||
{{ $t('nav.account') }}
|
||||
</RouterLink>
|
||||
<button type="button" class="btn btn-link nav-logout p-0" @click="onLogout">
|
||||
{{ $t('nav.logout') }}
|
||||
</button>
|
||||
@@ -118,6 +128,17 @@ async function onLogout() {
|
||||
color: var(--prism-text);
|
||||
}
|
||||
|
||||
.nav-account {
|
||||
color: var(--prism-navy);
|
||||
font-weight: 500;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.nav-account:hover,
|
||||
.nav-account.router-link-active {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.nav-logout {
|
||||
color: var(--prism-orange);
|
||||
font-weight: 500;
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
<script setup lang="ts">
|
||||
import { nextTick, ref } from 'vue'
|
||||
|
||||
/** Saisie d'un code à 6 chiffres en 6 cases (maquettes 13 et 14). Accepte le collage. */
|
||||
const props = withDefaults(defineProps<{ length?: number; label: string; autofocus?: boolean }>(), {
|
||||
length: 6,
|
||||
autofocus: false,
|
||||
})
|
||||
const emit = defineEmits<{ complete: [code: string] }>()
|
||||
const model = defineModel<string>({ default: '' })
|
||||
|
||||
const inputs = ref<HTMLInputElement[]>([])
|
||||
const digits = ref<string[]>(Array.from({ length: props.length }, (_, i) => model.value[i] ?? ''))
|
||||
|
||||
function sync() {
|
||||
// On teste la chaîne locale : `model.value` n'est mis à jour qu'au rendu du parent.
|
||||
const code = digits.value.join('')
|
||||
model.value = code
|
||||
if (code.length === props.length) emit('complete', code)
|
||||
}
|
||||
|
||||
function focus(index: number) {
|
||||
void nextTick(() => inputs.value[Math.max(0, Math.min(index, props.length - 1))]?.focus())
|
||||
}
|
||||
|
||||
function onInput(index: number, event: Event) {
|
||||
const value = (event.target as HTMLInputElement).value.replace(/\D/g, '')
|
||||
if (value.length > 1) {
|
||||
fill(index, value)
|
||||
return
|
||||
}
|
||||
digits.value[index] = value
|
||||
sync()
|
||||
if (value) focus(index + 1)
|
||||
}
|
||||
|
||||
function fill(start: number, value: string) {
|
||||
for (const [offset, char] of [...value].entries()) {
|
||||
if (start + offset < props.length) digits.value[start + offset] = char
|
||||
}
|
||||
sync()
|
||||
focus(start + value.length)
|
||||
}
|
||||
|
||||
function onPaste(index: number, event: ClipboardEvent) {
|
||||
const text = event.clipboardData?.getData('text').replace(/\D/g, '') ?? ''
|
||||
if (!text) return
|
||||
event.preventDefault()
|
||||
fill(index, text)
|
||||
}
|
||||
|
||||
function onKeydown(index: number, event: KeyboardEvent) {
|
||||
if (event.key === 'Backspace' && !digits.value[index]) focus(index - 1)
|
||||
if (event.key === 'ArrowLeft') focus(index - 1)
|
||||
if (event.key === 'ArrowRight') focus(index + 1)
|
||||
}
|
||||
|
||||
function clear() {
|
||||
digits.value = digits.value.map(() => '')
|
||||
sync()
|
||||
focus(0)
|
||||
}
|
||||
|
||||
defineExpose({ clear })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="code-input" role="group" :aria-label="label">
|
||||
<input
|
||||
v-for="(_, index) in digits"
|
||||
:key="index"
|
||||
ref="inputs"
|
||||
v-model="digits[index]"
|
||||
type="text"
|
||||
inputmode="numeric"
|
||||
maxlength="6"
|
||||
:autocomplete="index === 0 ? 'one-time-code' : 'off'"
|
||||
:autofocus="autofocus && index === 0"
|
||||
:aria-label="`${label} – chiffre ${index + 1}`"
|
||||
class="form-control digit"
|
||||
@input="onInput(index, $event)"
|
||||
@paste="onPaste(index, $event)"
|
||||
@keydown="onKeydown(index, $event)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.code-input {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.digit {
|
||||
width: 52px;
|
||||
height: 60px;
|
||||
padding: 0;
|
||||
text-align: center;
|
||||
font-size: 1.5rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
@media (max-width: 400px) {
|
||||
.digit {
|
||||
width: 42px;
|
||||
height: 52px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,266 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import { api, ApiError } from '@/api/client'
|
||||
import type { TotpSetup } from '@/api/types'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
|
||||
import AlertBanner from './AlertBanner.vue'
|
||||
import CodeInput from './CodeInput.vue'
|
||||
import RecoveryCodes from './RecoveryCodes.vue'
|
||||
|
||||
type Mode = 'idle' | 'setup' | 'codes' | 'disable' | 'regenerate'
|
||||
|
||||
const { user, load } = useAuth()
|
||||
const { t } = useI18n()
|
||||
|
||||
const mode = ref<Mode>('idle')
|
||||
const setup = ref<TotpSetup | null>(null)
|
||||
const codes = ref<string[]>([])
|
||||
const code = ref('')
|
||||
const password = ref('')
|
||||
const error = ref('')
|
||||
const loading = ref(false)
|
||||
const done = ref('')
|
||||
|
||||
function reset(next: Mode = 'idle') {
|
||||
mode.value = next
|
||||
code.value = ''
|
||||
password.value = ''
|
||||
error.value = ''
|
||||
}
|
||||
|
||||
function message(e: unknown) {
|
||||
if (e instanceof ApiError && e.status === 400) return e.message
|
||||
if (e instanceof ApiError && e.status === 429) return t('login.throttled')
|
||||
return t('account.error')
|
||||
}
|
||||
|
||||
async function run(action: () => Promise<void>) {
|
||||
error.value = ''
|
||||
loading.value = true
|
||||
try {
|
||||
await action()
|
||||
} catch (e) {
|
||||
error.value = message(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const start = () =>
|
||||
run(async () => {
|
||||
done.value = ''
|
||||
setup.value = await api.setupTotp()
|
||||
reset('setup')
|
||||
})
|
||||
|
||||
const enable = () =>
|
||||
run(async () => {
|
||||
codes.value = (await api.enableTotp(code.value)).recovery_codes
|
||||
setup.value = null
|
||||
reset('codes')
|
||||
})
|
||||
|
||||
const disable = () =>
|
||||
run(async () => {
|
||||
await api.disableTotp(password.value, code.value)
|
||||
await load(true)
|
||||
reset()
|
||||
done.value = t('account.mfa.disabled')
|
||||
})
|
||||
|
||||
const regenerate = () =>
|
||||
run(async () => {
|
||||
codes.value = (await api.regenerateRecoveryCodes(code.value)).recovery_codes
|
||||
reset('codes')
|
||||
})
|
||||
|
||||
async function finish() {
|
||||
codes.value = []
|
||||
await load(true)
|
||||
reset()
|
||||
done.value = t('account.mfa.enabledDone')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="prism-card panel" aria-labelledby="mfa-heading">
|
||||
<!-- Étape 1 et 2 de l'activation (maquette 14) -->
|
||||
<template v-if="mode === 'setup' && setup">
|
||||
<h2 id="mfa-heading" class="card-title">{{ $t('account.mfa.setupTitle') }}</h2>
|
||||
<AlertBanner v-if="error" variant="error" class="mb-3">{{ error }}</AlertBanner>
|
||||
<div class="row g-4">
|
||||
<div class="col-12">
|
||||
<h3 class="step">{{ $t('account.mfa.step1') }}</h3>
|
||||
<p class="small-text">{{ $t('account.mfa.step1Text') }}</p>
|
||||
<img :src="setup.qr_code" :alt="$t('account.mfa.qrAlt')" class="qr" />
|
||||
<p class="secret">
|
||||
{{ $t('account.mfa.secret') }} <span class="font-monospace">{{ setup.secret }}</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<h3 class="step">{{ $t('account.mfa.step2') }}</h3>
|
||||
<p class="small-text">{{ $t('account.mfa.step2Text') }}</p>
|
||||
<form @submit.prevent="enable">
|
||||
<CodeInput v-model="code" class="mb-3" :label="$t('mfa.codeLabel')" />
|
||||
<button
|
||||
type="submit"
|
||||
class="btn btn-primary action"
|
||||
:disabled="loading || code.length !== 6"
|
||||
>
|
||||
{{ $t('account.mfa.activate') }}
|
||||
</button>
|
||||
</form>
|
||||
<button type="button" class="btn btn-link link-strong px-0 mt-2" @click="reset()">
|
||||
{{ $t('account.cancel') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Codes de secours (maquette 15) -->
|
||||
<RecoveryCodes v-else-if="mode === 'codes'" :codes="codes" @done="finish" />
|
||||
|
||||
<template v-else>
|
||||
<div class="d-flex align-items-start justify-content-between gap-3 mb-3">
|
||||
<h2 id="mfa-heading" class="card-title mb-0">{{ $t('account.mfa.title') }}</h2>
|
||||
<span class="status" :class="{ on: user?.mfa_enabled }">
|
||||
{{ user?.mfa_enabled ? $t('account.mfa.on') : $t('account.mfa.off') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<AlertBanner v-if="done" variant="info" class="mb-3">{{ done }}</AlertBanner>
|
||||
<AlertBanner v-if="user?.is_staff && !user.mfa_enabled" variant="error" class="mb-3">
|
||||
{{ $t('account.mfa.mandatory') }}
|
||||
</AlertBanner>
|
||||
|
||||
<template v-if="!user?.mfa_enabled">
|
||||
<p>{{ $t('account.mfa.explain') }}</p>
|
||||
<AlertBanner v-if="error" variant="error" class="mb-3">{{ error }}</AlertBanner>
|
||||
<button type="button" class="btn btn-outline-primary" :disabled="loading" @click="start">
|
||||
{{ $t('account.mfa.enable') }}
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<p>{{ $t('account.mfa.enabledText') }}</p>
|
||||
|
||||
<form
|
||||
v-if="mode === 'regenerate' || mode === 'disable'"
|
||||
class="mt-3"
|
||||
@submit.prevent="mode === 'disable' ? disable() : regenerate()"
|
||||
>
|
||||
<AlertBanner v-if="error" variant="error" class="mb-3">{{ error }}</AlertBanner>
|
||||
<div v-if="mode === 'disable'" class="mb-3">
|
||||
<label for="mfa-password" class="form-label">{{ $t('account.currentPassword') }}</label>
|
||||
<input
|
||||
id="mfa-password"
|
||||
v-model="password"
|
||||
type="password"
|
||||
class="form-control"
|
||||
autocomplete="current-password"
|
||||
/>
|
||||
</div>
|
||||
<label for="mfa-code" class="form-label">
|
||||
{{ mode === 'disable' ? $t('account.mfa.codeOrRecovery') : $t('mfa.codeLabel') }}
|
||||
</label>
|
||||
<input
|
||||
id="mfa-code"
|
||||
v-model.trim="code"
|
||||
class="form-control mb-3"
|
||||
autocomplete="one-time-code"
|
||||
:inputmode="mode === 'disable' ? 'text' : 'numeric'"
|
||||
/>
|
||||
<div class="d-flex flex-wrap gap-3 align-items-center">
|
||||
<button
|
||||
type="submit"
|
||||
class="btn"
|
||||
:class="mode === 'disable' ? 'btn-danger' : 'btn-primary'"
|
||||
:disabled="loading || !code || (mode === 'disable' && !password)"
|
||||
>
|
||||
{{ mode === 'disable' ? $t('account.mfa.disable') : $t('account.mfa.regenerate') }}
|
||||
</button>
|
||||
<button type="button" class="btn btn-link link-strong px-0" @click="reset()">
|
||||
{{ $t('account.cancel') }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div v-else class="d-flex flex-wrap gap-3">
|
||||
<button type="button" class="btn btn-outline-primary" @click="reset('regenerate')">
|
||||
{{ $t('account.mfa.regenerate') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="!user.is_staff"
|
||||
type="button"
|
||||
class="btn btn-link link-strong px-0"
|
||||
@click="reset('disable')"
|
||||
>
|
||||
{{ $t('account.mfa.disable') }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.panel {
|
||||
padding: 24px 28px;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-size: 1.25rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.step {
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.small-text {
|
||||
font-size: 0.8125rem;
|
||||
}
|
||||
|
||||
.qr {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--prism-border);
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.secret {
|
||||
margin-top: 1rem;
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 500;
|
||||
color: var(--prism-navy);
|
||||
}
|
||||
|
||||
.action {
|
||||
min-width: 160px;
|
||||
}
|
||||
|
||||
.status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
height: 28px;
|
||||
padding: 0 14px;
|
||||
border-radius: 14px;
|
||||
border: 1px solid var(--prism-border);
|
||||
background: var(--prism-bg);
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.status.on {
|
||||
background: var(--prism-level-1);
|
||||
border-color: var(--prism-level-1);
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,97 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
const props = defineProps<{ codes: string[] }>()
|
||||
const emit = defineEmits<{ done: [] }>()
|
||||
|
||||
const saved = ref(false)
|
||||
const copied = ref(false)
|
||||
|
||||
async function copy() {
|
||||
await navigator.clipboard.writeText(props.codes.join('\n'))
|
||||
copied.value = true
|
||||
}
|
||||
|
||||
function download() {
|
||||
const blob = new Blob([`Codes de secours PRISM\n\n${props.codes.join('\n')}\n`], {
|
||||
type: 'text/plain',
|
||||
})
|
||||
const url = URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = 'prism-codes-de-secours.txt'
|
||||
link.click()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<h2 class="card-title">{{ $t('account.mfa.codesTitle') }}</h2>
|
||||
<p>{{ $t('account.mfa.codesText', { count: codes.length }) }}</p>
|
||||
<div class="codes-warning" role="status">{{ $t('account.mfa.codesWarning') }}</div>
|
||||
|
||||
<ul class="codes list-unstyled">
|
||||
<li v-for="code in codes" :key="code" class="font-monospace">{{ code }}</li>
|
||||
</ul>
|
||||
|
||||
<div class="d-flex flex-wrap gap-3 mb-4">
|
||||
<button type="button" class="btn btn-outline-primary action" @click="copy">
|
||||
{{ copied ? $t('account.mfa.copied') : $t('account.mfa.copy') }}
|
||||
</button>
|
||||
<button type="button" class="btn btn-outline-primary action" @click="download">
|
||||
{{ $t('account.mfa.download') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
<div class="form-check mb-3">
|
||||
<input id="codes-saved" v-model="saved" class="form-check-input" type="checkbox" />
|
||||
<label for="codes-saved" class="form-check-label">{{ $t('account.mfa.saved') }}</label>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary action" :disabled="!saved" @click="emit('done')">
|
||||
{{ $t('account.mfa.finish') }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.card-title {
|
||||
font-size: 1.25rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.codes-warning {
|
||||
background: #fdf0e6;
|
||||
color: #7a3b0e;
|
||||
font-weight: 500;
|
||||
border-radius: 6px;
|
||||
padding: 0.6rem 0.875rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.codes {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.codes li {
|
||||
background: var(--prism-bg);
|
||||
border: 1px solid var(--prism-border);
|
||||
border-radius: 6px;
|
||||
padding: 0.7rem 0.875rem;
|
||||
font-size: 1rem;
|
||||
color: var(--prism-navy);
|
||||
}
|
||||
|
||||
.action {
|
||||
min-width: 160px;
|
||||
}
|
||||
|
||||
.form-check-input:checked {
|
||||
background-color: var(--prism-orange);
|
||||
border-color: var(--prism-orange);
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user