- 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>
193 lines
5.6 KiB
Vue
193 lines
5.6 KiB
Vue
<script setup lang="ts">
|
|
import { ref } from 'vue'
|
|
import { useI18n } from 'vue-i18n'
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
|
import { ApiError } from '@/api/client'
|
|
import AlertBanner from '@/components/AlertBanner.vue'
|
|
import CodeInput from '@/components/CodeInput.vue'
|
|
import { useAuth } from '@/composables/useAuth'
|
|
|
|
const { login, verifyMfa } = useAuth()
|
|
const router = useRouter()
|
|
const route = useRoute()
|
|
const { t } = useI18n()
|
|
|
|
const step = ref<'password' | 'code'>('password')
|
|
const useRecovery = ref(false)
|
|
const email = ref('')
|
|
const password = ref('')
|
|
const code = ref('')
|
|
const error = ref('')
|
|
const loading = ref(false)
|
|
// Message transmis par la page de réinitialisation (état de navigation, pas l'URL).
|
|
const notice = ref<string>(history.state?.notice === 'password-reset' ? t('reset.done') : '')
|
|
const codeInput = ref<InstanceType<typeof CodeInput>>()
|
|
|
|
function message(e: unknown): string {
|
|
if (e instanceof ApiError && e.status === 429) return t('login.throttled')
|
|
if (e instanceof ApiError && e.status === 400) return e.message
|
|
return t('login.error')
|
|
}
|
|
|
|
async function done() {
|
|
const next = route.query.next
|
|
await router.push(
|
|
typeof next === 'string' && next.startsWith('/') && !next.startsWith('//')
|
|
? next
|
|
: { name: 'assessment' },
|
|
)
|
|
}
|
|
|
|
async function submitPassword() {
|
|
error.value = ''
|
|
loading.value = true
|
|
try {
|
|
if (await login(email.value, password.value)) {
|
|
password.value = ''
|
|
step.value = 'code'
|
|
} else {
|
|
await done()
|
|
}
|
|
} catch (e) {
|
|
error.value = message(e)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function submitCode() {
|
|
if (!code.value) return
|
|
error.value = ''
|
|
loading.value = true
|
|
try {
|
|
await verifyMfa(code.value)
|
|
await done()
|
|
} catch (e) {
|
|
error.value = message(e)
|
|
if (e instanceof ApiError && e.code === 'mfa_expired') backToPassword()
|
|
else if (!useRecovery.value) codeInput.value?.clear()
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function backToPassword() {
|
|
step.value = 'password'
|
|
code.value = ''
|
|
useRecovery.value = false
|
|
}
|
|
|
|
function toggleRecovery() {
|
|
useRecovery.value = !useRecovery.value
|
|
code.value = ''
|
|
error.value = ''
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="auth-page">
|
|
<section v-if="step === 'password'" class="auth-card prism-card" aria-labelledby="login-title">
|
|
<h1 id="login-title">{{ $t('login.title') }}</h1>
|
|
<p class="intro">{{ $t('login.intro') }}</p>
|
|
|
|
<AlertBanner v-if="error" variant="error" class="mb-3">{{ error }}</AlertBanner>
|
|
<AlertBanner v-else-if="notice" variant="info" class="mb-3">{{ notice }}</AlertBanner>
|
|
|
|
<form novalidate @submit.prevent="submitPassword">
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">{{ $t('login.email') }}</label>
|
|
<input
|
|
id="email"
|
|
v-model="email"
|
|
type="email"
|
|
class="form-control"
|
|
autocomplete="username"
|
|
required
|
|
:placeholder="$t('login.emailPlaceholder')"
|
|
/>
|
|
</div>
|
|
<div class="mb-4">
|
|
<label for="password" class="form-label">{{ $t('login.password') }}</label>
|
|
<input
|
|
id="password"
|
|
v-model="password"
|
|
type="password"
|
|
class="form-control"
|
|
autocomplete="current-password"
|
|
required
|
|
/>
|
|
</div>
|
|
<button
|
|
type="submit"
|
|
class="btn btn-primary w-100"
|
|
:disabled="loading || !email || !password"
|
|
>
|
|
{{ loading ? $t('login.submitting') : $t('login.submit') }}
|
|
</button>
|
|
</form>
|
|
|
|
<p class="auth-links mb-0">
|
|
<RouterLink :to="{ name: 'forgot-password' }" class="link-strong">
|
|
{{ $t('login.forgot') }}
|
|
</RouterLink>
|
|
</p>
|
|
|
|
<hr class="my-4" />
|
|
<p class="text-center mb-3">{{ $t('login.noAccount') }}</p>
|
|
<RouterLink :to="{ name: 'register' }" class="btn btn-outline-primary w-100">
|
|
{{ $t('login.createAccount') }}
|
|
</RouterLink>
|
|
</section>
|
|
|
|
<section v-else class="auth-card wide prism-card text-center" aria-labelledby="mfa-title">
|
|
<div class="icon-circle" aria-hidden="true">2FA</div>
|
|
<h1 id="mfa-title">{{ $t('mfa.title') }}</h1>
|
|
<p class="intro">
|
|
{{ useRecovery ? $t('mfa.recoveryIntro') : $t('mfa.intro') }}
|
|
</p>
|
|
|
|
<AlertBanner v-if="error" variant="error" class="mb-3 text-start">{{ error }}</AlertBanner>
|
|
|
|
<form novalidate @submit.prevent="submitCode">
|
|
<div v-if="useRecovery" class="mb-4 text-start">
|
|
<label for="recovery" class="form-label">{{ $t('mfa.recoveryLabel') }}</label>
|
|
<input
|
|
id="recovery"
|
|
v-model="code"
|
|
type="text"
|
|
class="form-control font-monospace"
|
|
autocomplete="off"
|
|
placeholder="ABCD-EFGH"
|
|
/>
|
|
</div>
|
|
<CodeInput
|
|
v-else
|
|
ref="codeInput"
|
|
v-model="code"
|
|
class="justify-content-center mb-4"
|
|
:label="$t('mfa.codeLabel')"
|
|
autofocus
|
|
@complete="submitCode"
|
|
/>
|
|
<button type="submit" class="btn btn-primary w-100" :disabled="loading || !code">
|
|
{{ $t('mfa.submit') }}
|
|
</button>
|
|
</form>
|
|
|
|
<p class="auth-links mb-2">
|
|
<button type="button" class="btn btn-link link-strong p-0" @click="toggleRecovery">
|
|
{{ useRecovery ? $t('mfa.useApp') : $t('mfa.useRecovery') }}
|
|
</button>
|
|
</p>
|
|
<button
|
|
type="button"
|
|
class="btn btn-link text-reset text-decoration-none p-0"
|
|
@click="backToPassword"
|
|
>
|
|
{{ $t('mfa.back') }}
|
|
</button>
|
|
</section>
|
|
</div>
|
|
</template>
|