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
@@ -1,46 +1,100 @@
|
||||
<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 } = 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>>()
|
||||
|
||||
async function onSubmit() {
|
||||
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 {
|
||||
await login(email.value, password.value)
|
||||
const next = typeof route.query.next === 'string' && route.query.next.startsWith('/')
|
||||
await router.push(next ? (route.query.next as string) : { name: 'assessment' })
|
||||
if (await login(email.value, password.value)) {
|
||||
password.value = ''
|
||||
step.value = 'code'
|
||||
} else {
|
||||
await done()
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = e instanceof ApiError && e.status === 400 ? e.message : 'login.error'
|
||||
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 class="auth-card prism-card" aria-labelledby="login-title">
|
||||
<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 === 'login.error' ? $t('login.error') : error }}
|
||||
</AlertBanner>
|
||||
<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="onSubmit">
|
||||
<form novalidate @submit.prevent="submitPassword">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">{{ $t('login.email') }}</label>
|
||||
<input
|
||||
@@ -72,41 +126,67 @@ async function onSubmit() {
|
||||
{{ 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>
|
||||
|
||||
<style scoped>
|
||||
.auth-page {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 100px 16px;
|
||||
}
|
||||
|
||||
@media (max-width: 575.98px) {
|
||||
.auth-page {
|
||||
padding: 32px 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
width: 100%;
|
||||
max-width: 460px;
|
||||
padding: 40px 39px;
|
||||
}
|
||||
|
||||
@media (max-width: 575.98px) {
|
||||
.auth-card {
|
||||
padding: 28px 20px;
|
||||
}
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.75rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.intro {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user