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
@@ -0,0 +1,186 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import { api, ApiError } from '@/api/client'
|
||||
import AlertBanner from '@/components/AlertBanner.vue'
|
||||
import MfaPanel from '@/components/MfaPanel.vue'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
|
||||
const { user } = useAuth()
|
||||
const { t } = useI18n()
|
||||
|
||||
const initials = computed(() =>
|
||||
`${user.value?.first_name[0] ?? ''}${user.value?.last_name[0] ?? ''}`.toUpperCase(),
|
||||
)
|
||||
|
||||
const form = reactive({ current: '', next: '', confirm: '' })
|
||||
const errors = ref<Record<string, string>>({})
|
||||
const saved = ref(false)
|
||||
const loading = ref(false)
|
||||
const mismatch = computed(() => form.confirm !== '' && form.confirm !== form.next)
|
||||
|
||||
async function changePassword() {
|
||||
errors.value = {}
|
||||
saved.value = false
|
||||
loading.value = true
|
||||
try {
|
||||
await api.changePassword(form.current, form.next)
|
||||
Object.assign(form, { current: '', next: '', confirm: '' })
|
||||
saved.value = true
|
||||
} catch (e) {
|
||||
errors.value =
|
||||
e instanceof ApiError && e.status === 400
|
||||
? e.fieldErrors()
|
||||
: { new_password: t('account.error') }
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="user" class="account container-xxl">
|
||||
<h1>{{ $t('account.title') }}</h1>
|
||||
|
||||
<section class="prism-card profile">
|
||||
<span class="avatar" aria-hidden="true">{{ initials }}</span>
|
||||
<div>
|
||||
<p class="name">{{ $t('nav.doctor', { name: `${user.first_name} ${user.last_name}` }) }}</p>
|
||||
<p class="meta">
|
||||
{{ user.email
|
||||
}}<template v-if="user.roles.length"> · {{ user.roles.join(', ') }}</template>
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="row g-4">
|
||||
<div class="col-lg-6">
|
||||
<section class="prism-card panel" aria-labelledby="password-heading">
|
||||
<h2 id="password-heading" class="card-title">{{ $t('account.passwordTitle') }}</h2>
|
||||
<AlertBanner v-if="saved" variant="info" class="mb-3">
|
||||
{{ $t('account.passwordSaved') }}
|
||||
</AlertBanner>
|
||||
<form novalidate @submit.prevent="changePassword">
|
||||
<div class="mb-3">
|
||||
<label for="current" class="form-label">{{ $t('account.currentPassword') }}</label>
|
||||
<input
|
||||
id="current"
|
||||
v-model="form.current"
|
||||
type="password"
|
||||
class="form-control"
|
||||
:class="{ 'is-invalid': errors.current_password }"
|
||||
autocomplete="current-password"
|
||||
/>
|
||||
<div class="invalid-feedback">{{ errors.current_password }}</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="next" class="form-label">{{ $t('account.newPassword') }}</label>
|
||||
<input
|
||||
id="next"
|
||||
v-model="form.next"
|
||||
type="password"
|
||||
class="form-control"
|
||||
:class="{ 'is-invalid': errors.new_password }"
|
||||
autocomplete="new-password"
|
||||
aria-describedby="new-password-rules"
|
||||
/>
|
||||
<div class="invalid-feedback">{{ errors.new_password }}</div>
|
||||
<div id="new-password-rules" class="form-text">
|
||||
{{ $t('register.passwordRules') }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label for="confirm" class="form-label">{{ $t('account.confirmPassword') }}</label>
|
||||
<input
|
||||
id="confirm"
|
||||
v-model="form.confirm"
|
||||
type="password"
|
||||
class="form-control"
|
||||
:class="{ 'is-invalid': mismatch }"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
<div class="invalid-feedback">{{ $t('register.mismatch') }}</div>
|
||||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
class="btn btn-primary save"
|
||||
:disabled="
|
||||
loading || !form.current || form.next.length < 12 || form.next !== form.confirm
|
||||
"
|
||||
>
|
||||
{{ $t('account.save') }}
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<MfaPanel />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.account {
|
||||
max-width: 1440px;
|
||||
padding: 40px 48px;
|
||||
}
|
||||
|
||||
@media (max-width: 767.98px) {
|
||||
.account {
|
||||
padding: 24px 16px;
|
||||
}
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.875rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.profile {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
padding: 20px 28px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 50%;
|
||||
background: var(--prism-navy);
|
||||
color: #fff;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 700;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.name {
|
||||
margin: 0;
|
||||
color: var(--prism-navy);
|
||||
font-size: 1.125rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.meta {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.panel {
|
||||
padding: 24px 28px;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-size: 1.25rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.save {
|
||||
min-width: 160px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,93 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
import { api, ApiError } from '@/api/client'
|
||||
import AlertBanner from '@/components/AlertBanner.vue'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const email = ref('')
|
||||
const sent = ref(false)
|
||||
const resent = ref(false)
|
||||
const error = ref('')
|
||||
const loading = ref(false)
|
||||
|
||||
async function send() {
|
||||
error.value = ''
|
||||
loading.value = true
|
||||
try {
|
||||
await api.requestPasswordReset(email.value)
|
||||
resent.value = sent.value
|
||||
sent.value = true
|
||||
} catch (e) {
|
||||
error.value =
|
||||
e instanceof ApiError && e.status === 429
|
||||
? t('forgot.throttled')
|
||||
: e instanceof ApiError && e.status === 400
|
||||
? (e.fieldErrors().email ?? t('forgot.error'))
|
||||
: t('forgot.error')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="auth-page">
|
||||
<!-- Maquette 9 -->
|
||||
<section v-if="!sent" class="auth-card wide prism-card" aria-labelledby="forgot-title">
|
||||
<h1 id="forgot-title">{{ $t('forgot.title') }}</h1>
|
||||
<p class="intro">{{ $t('forgot.intro') }}</p>
|
||||
|
||||
<AlertBanner v-if="error" variant="error" class="mb-3">{{ error }}</AlertBanner>
|
||||
|
||||
<form novalidate @submit.prevent="send">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">{{ $t('login.email') }}</label>
|
||||
<input
|
||||
id="email"
|
||||
v-model.trim="email"
|
||||
type="email"
|
||||
class="form-control"
|
||||
autocomplete="username"
|
||||
required
|
||||
:placeholder="$t('login.emailPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100" :disabled="loading || !email">
|
||||
{{ loading ? $t('forgot.submitting') : $t('forgot.submit') }}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p class="auth-links mb-0">
|
||||
<RouterLink :to="{ name: 'login' }" class="link-strong">{{ $t('forgot.back') }}</RouterLink>
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<!-- Maquette 10 -->
|
||||
<section
|
||||
v-else
|
||||
class="auth-card wide prism-card text-center"
|
||||
aria-labelledby="sent-title"
|
||||
aria-live="polite"
|
||||
>
|
||||
<div class="icon-circle" aria-hidden="true">@</div>
|
||||
<h1 id="sent-title">{{ $t('forgot.sentTitle') }}</h1>
|
||||
<p>{{ $t('forgot.sentText', { email }) }}</p>
|
||||
<AlertBanner v-if="error" variant="error" class="mb-3 text-start">{{ error }}</AlertBanner>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-primary w-100"
|
||||
:disabled="loading || resent"
|
||||
@click="send"
|
||||
>
|
||||
{{ $t('forgot.resend') }}
|
||||
</button>
|
||||
<p v-if="resent" class="text-success mt-2 mb-0" role="status">{{ $t('forgot.resent') }}</p>
|
||||
<p class="auth-links mb-0">
|
||||
<RouterLink :to="{ name: 'login' }" class="link-strong">{{ $t('forgot.back') }}</RouterLink>
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,119 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
import { api, ApiError } from '@/api/client'
|
||||
|
||||
type State = 'loading' | 'sent' | 'confirmed' | 'expired' | 'invalid' | 'used'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const state = ref<State>('loading')
|
||||
const email = ref<string>((history.state?.email as string | undefined) ?? '')
|
||||
const token = ref('')
|
||||
const resent = ref(false)
|
||||
const resending = ref(false)
|
||||
|
||||
onMounted(async () => {
|
||||
const jeton = route.query.jeton
|
||||
if (typeof jeton !== 'string' || !jeton) {
|
||||
state.value = 'sent'
|
||||
return
|
||||
}
|
||||
token.value = jeton
|
||||
// Retire le jeton de la barre d'adresse et de l'historique.
|
||||
await router.replace({ name: 'register-status' })
|
||||
try {
|
||||
await api.verifyEmail(jeton)
|
||||
state.value = 'confirmed'
|
||||
} catch (e) {
|
||||
const code = e instanceof ApiError ? e.code : undefined
|
||||
state.value = code === 'expired_token' ? 'expired' : code === 'used_token' ? 'used' : 'invalid'
|
||||
}
|
||||
})
|
||||
|
||||
async function resend() {
|
||||
resending.value = true
|
||||
try {
|
||||
await api.resendVerification(token.value ? { token: token.value } : { email: email.value })
|
||||
resent.value = true
|
||||
} finally {
|
||||
resending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const ICONS: Record<State, string> = {
|
||||
loading: 'bi-hourglass-split',
|
||||
sent: 'bi-envelope',
|
||||
confirmed: 'bi-check-lg',
|
||||
expired: 'bi-clock-history',
|
||||
invalid: 'bi-x-lg',
|
||||
used: 'bi-check-lg',
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="auth-page">
|
||||
<section
|
||||
class="auth-card wide prism-card text-center"
|
||||
aria-labelledby="status-title"
|
||||
aria-live="polite"
|
||||
>
|
||||
<div class="icon-circle" aria-hidden="true"><i class="bi" :class="ICONS[state]"></i></div>
|
||||
|
||||
<template v-if="state === 'loading'">
|
||||
<h1 id="status-title">{{ $t('registerStatus.loading') }}</h1>
|
||||
</template>
|
||||
|
||||
<template v-else-if="state === 'sent'">
|
||||
<h1 id="status-title">{{ $t('registerStatus.sent.title') }}</h1>
|
||||
<p v-if="email">{{ $t('registerStatus.sent.textTo', { email }) }}</p>
|
||||
<p v-else>{{ $t('registerStatus.sent.text') }}</p>
|
||||
<p class="form-text">{{ $t('registerStatus.sent.hint') }}</p>
|
||||
<button
|
||||
v-if="email"
|
||||
type="button"
|
||||
class="btn btn-outline-primary"
|
||||
:disabled="resending || resent"
|
||||
@click="resend"
|
||||
>
|
||||
{{ $t('registerStatus.resend') }}
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<template v-else-if="state === 'confirmed' || state === 'used'">
|
||||
<h1 id="status-title">{{ $t('registerStatus.confirmed.title') }}</h1>
|
||||
<p>{{ $t('registerStatus.confirmed.text') }}</p>
|
||||
<RouterLink :to="{ name: 'login' }" class="btn btn-primary">
|
||||
{{ $t('registerStatus.toLogin') }}
|
||||
</RouterLink>
|
||||
</template>
|
||||
|
||||
<template v-else-if="state === 'expired'">
|
||||
<h1 id="status-title">{{ $t('registerStatus.expired.title') }}</h1>
|
||||
<p>{{ $t('registerStatus.expired.text') }}</p>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
:disabled="resending || resent"
|
||||
@click="resend"
|
||||
>
|
||||
{{ $t('registerStatus.resend') }}
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<h1 id="status-title">{{ $t('registerStatus.invalid.title') }}</h1>
|
||||
<p>{{ $t('registerStatus.invalid.text') }}</p>
|
||||
<RouterLink :to="{ name: 'register' }" class="btn btn-outline-primary">
|
||||
{{ $t('registerStatus.restart') }}
|
||||
</RouterLink>
|
||||
</template>
|
||||
|
||||
<p v-if="resent" class="text-success mt-3 mb-0" role="status">
|
||||
{{ $t('registerStatus.resent') }}
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,196 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
import { api, ApiError } from '@/api/client'
|
||||
import AlertBanner from '@/components/AlertBanner.vue'
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
|
||||
const form = reactive({
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
email: '',
|
||||
inami_number: '',
|
||||
password: '',
|
||||
confirm: '',
|
||||
accept_terms: false,
|
||||
})
|
||||
const errors = ref<Record<string, string>>({})
|
||||
const error = ref('')
|
||||
const loading = ref(false)
|
||||
|
||||
const mismatch = computed(() => form.confirm !== '' && form.confirm !== form.password)
|
||||
const canSubmit = computed(
|
||||
() =>
|
||||
form.first_name &&
|
||||
form.last_name &&
|
||||
form.email &&
|
||||
form.password.length >= 12 &&
|
||||
form.password === form.confirm &&
|
||||
form.accept_terms,
|
||||
)
|
||||
|
||||
async function submit() {
|
||||
errors.value = {}
|
||||
error.value = ''
|
||||
loading.value = true
|
||||
try {
|
||||
await api.register({
|
||||
first_name: form.first_name,
|
||||
last_name: form.last_name,
|
||||
email: form.email,
|
||||
inami_number: form.inami_number,
|
||||
password: form.password,
|
||||
accept_terms: form.accept_terms,
|
||||
})
|
||||
// L'adresse du médecin passe par l'état de navigation, pas par l'URL.
|
||||
await router.push({ name: 'register-status', state: { email: form.email } })
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError && e.status === 400) {
|
||||
errors.value = e.fieldErrors()
|
||||
error.value = errors.value.non_field_errors ?? t('register.fixErrors')
|
||||
} else if (e instanceof ApiError && e.status === 429) {
|
||||
error.value = t('register.throttled')
|
||||
} else {
|
||||
error.value = t('register.error')
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="auth-page register-page">
|
||||
<section class="auth-card wide prism-card" aria-labelledby="register-title">
|
||||
<h1 id="register-title">{{ $t('register.title') }}</h1>
|
||||
<p class="intro">{{ $t('register.intro') }}</p>
|
||||
|
||||
<AlertBanner v-if="error" variant="error" class="mb-3">{{ error }}</AlertBanner>
|
||||
|
||||
<form novalidate @submit.prevent="submit">
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-sm-6">
|
||||
<label for="first_name" class="form-label">{{ $t('register.firstName') }}</label>
|
||||
<input
|
||||
id="first_name"
|
||||
v-model.trim="form.first_name"
|
||||
class="form-control"
|
||||
:class="{ 'is-invalid': errors.first_name }"
|
||||
autocomplete="given-name"
|
||||
placeholder="Jean"
|
||||
required
|
||||
/>
|
||||
<div class="invalid-feedback">{{ errors.first_name }}</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<label for="last_name" class="form-label">{{ $t('register.lastName') }}</label>
|
||||
<input
|
||||
id="last_name"
|
||||
v-model.trim="form.last_name"
|
||||
class="form-control"
|
||||
:class="{ 'is-invalid': errors.last_name }"
|
||||
autocomplete="family-name"
|
||||
placeholder="Dupont"
|
||||
required
|
||||
/>
|
||||
<div class="invalid-feedback">{{ errors.last_name }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">{{ $t('login.email') }}</label>
|
||||
<input
|
||||
id="email"
|
||||
v-model.trim="form.email"
|
||||
type="email"
|
||||
class="form-control"
|
||||
:class="{ 'is-invalid': errors.email }"
|
||||
autocomplete="email"
|
||||
:placeholder="$t('login.emailPlaceholder')"
|
||||
required
|
||||
/>
|
||||
<div class="invalid-feedback">{{ errors.email }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="inami" class="form-label">{{ $t('register.inami') }}</label>
|
||||
<input
|
||||
id="inami"
|
||||
v-model.trim="form.inami_number"
|
||||
class="form-control"
|
||||
:class="{ 'is-invalid': errors.inami_number }"
|
||||
placeholder="1-23456-78-901"
|
||||
/>
|
||||
<div class="invalid-feedback">{{ errors.inami_number }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">{{ $t('login.password') }}</label>
|
||||
<input
|
||||
id="password"
|
||||
v-model="form.password"
|
||||
type="password"
|
||||
class="form-control"
|
||||
:class="{ 'is-invalid': errors.password }"
|
||||
autocomplete="new-password"
|
||||
aria-describedby="password-rules"
|
||||
required
|
||||
/>
|
||||
<div class="invalid-feedback">{{ errors.password }}</div>
|
||||
<div id="password-rules" class="form-text">{{ $t('register.passwordRules') }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="confirm" class="form-label">{{ $t('register.confirm') }}</label>
|
||||
<input
|
||||
id="confirm"
|
||||
v-model="form.confirm"
|
||||
type="password"
|
||||
class="form-control"
|
||||
:class="{ 'is-invalid': mismatch }"
|
||||
autocomplete="new-password"
|
||||
required
|
||||
/>
|
||||
<div class="invalid-feedback">{{ $t('register.mismatch') }}</div>
|
||||
</div>
|
||||
|
||||
<div class="form-check mb-4">
|
||||
<input
|
||||
id="terms"
|
||||
v-model="form.accept_terms"
|
||||
class="form-check-input"
|
||||
:class="{ 'is-invalid': errors.accept_terms }"
|
||||
type="checkbox"
|
||||
/>
|
||||
<label class="form-check-label" for="terms">{{ $t('register.terms') }}</label>
|
||||
<div class="invalid-feedback">{{ errors.accept_terms }}</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary w-100" :disabled="loading || !canSubmit">
|
||||
{{ loading ? $t('register.submitting') : $t('register.submit') }}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p class="auth-links mb-0">
|
||||
<RouterLink :to="{ name: 'login' }" class="link-strong">
|
||||
{{ $t('register.haveAccount') }}
|
||||
</RouterLink>
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.register-page {
|
||||
padding-top: 32px;
|
||||
}
|
||||
|
||||
.form-check-input:checked {
|
||||
background-color: var(--prism-orange);
|
||||
border-color: var(--prism-orange);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,132 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
import { api, ApiError } from '@/api/client'
|
||||
import AlertBanner from '@/components/AlertBanner.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
|
||||
// Le jeton reste en mémoire : il est retiré de la barre d'adresse et de l'historique.
|
||||
const token = ref('')
|
||||
const state = ref<'checking' | 'form' | 'invalid'>('checking')
|
||||
const password = ref('')
|
||||
const confirm = ref('')
|
||||
const errors = ref<Record<string, string>>({})
|
||||
const error = ref('')
|
||||
const loading = ref(false)
|
||||
|
||||
const mismatch = computed(() => confirm.value !== '' && confirm.value !== password.value)
|
||||
|
||||
onMounted(async () => {
|
||||
const jeton = route.params.jeton
|
||||
if (typeof jeton !== 'string' || !jeton) {
|
||||
state.value = 'invalid'
|
||||
return
|
||||
}
|
||||
token.value = jeton
|
||||
await router.replace({ name: 'reset-password' })
|
||||
try {
|
||||
await api.validateResetToken(jeton)
|
||||
state.value = 'form'
|
||||
} catch {
|
||||
state.value = 'invalid'
|
||||
}
|
||||
})
|
||||
|
||||
async function submit() {
|
||||
errors.value = {}
|
||||
error.value = ''
|
||||
loading.value = true
|
||||
try {
|
||||
await api.resetPassword(token.value, password.value)
|
||||
await router.push({ name: 'login', state: { notice: 'password-reset' } })
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError && e.code === 'invalid_token') {
|
||||
state.value = 'invalid'
|
||||
} else if (e instanceof ApiError && e.status === 400) {
|
||||
errors.value = e.fieldErrors()
|
||||
} else {
|
||||
error.value = t('reset.error')
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="auth-page">
|
||||
<section
|
||||
v-if="state === 'checking'"
|
||||
class="auth-card wide prism-card text-center"
|
||||
aria-live="polite"
|
||||
>
|
||||
<p class="mb-0">{{ $t('reset.checking') }}</p>
|
||||
</section>
|
||||
|
||||
<!-- Maquette 11 -->
|
||||
<section
|
||||
v-else-if="state === 'form'"
|
||||
class="auth-card wide prism-card"
|
||||
aria-labelledby="reset-title"
|
||||
>
|
||||
<h1 id="reset-title">{{ $t('reset.title') }}</h1>
|
||||
<p class="intro">{{ $t('reset.intro') }}</p>
|
||||
|
||||
<AlertBanner v-if="error" variant="error" class="mb-3">{{ error }}</AlertBanner>
|
||||
|
||||
<form novalidate @submit.prevent="submit">
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">{{ $t('reset.password') }}</label>
|
||||
<input
|
||||
id="password"
|
||||
v-model="password"
|
||||
type="password"
|
||||
class="form-control"
|
||||
:class="{ 'is-invalid': errors.new_password }"
|
||||
autocomplete="new-password"
|
||||
aria-describedby="password-rules"
|
||||
/>
|
||||
<div class="invalid-feedback">{{ errors.new_password }}</div>
|
||||
<div id="password-rules" class="form-text">{{ $t('register.passwordRules') }}</div>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label for="confirm" class="form-label">{{ $t('reset.confirm') }}</label>
|
||||
<input
|
||||
id="confirm"
|
||||
v-model="confirm"
|
||||
type="password"
|
||||
class="form-control"
|
||||
:class="{ 'is-invalid': mismatch }"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
<div class="invalid-feedback">{{ $t('register.mismatch') }}</div>
|
||||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
class="btn btn-primary w-100"
|
||||
:disabled="loading || password.length < 12 || password !== confirm"
|
||||
>
|
||||
{{ loading ? $t('reset.submitting') : $t('reset.submit') }}
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<!-- Maquette 12 -->
|
||||
<section v-else class="auth-card wide prism-card text-center" aria-labelledby="invalid-title">
|
||||
<div class="icon-circle warning" aria-hidden="true">!</div>
|
||||
<h1 id="invalid-title">{{ $t('reset.invalidTitle') }}</h1>
|
||||
<p>{{ $t('reset.invalidText') }}</p>
|
||||
<RouterLink :to="{ name: 'forgot-password' }" class="btn btn-primary w-100">
|
||||
{{ $t('reset.newLink') }}
|
||||
</RouterLink>
|
||||
<p class="auth-links mb-0">
|
||||
<RouterLink :to="{ name: 'login' }" class="link-strong">{{ $t('forgot.back') }}</RouterLink>
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user