Registration completed

This commit is contained in:
2024-07-30 23:25:47 +02:00
parent f2600a3012
commit edf23bdbaa
12 changed files with 191 additions and 73 deletions

View File

@@ -16,7 +16,7 @@ const state = reactive<Registration>({
const confirmPassword = ref("");
const { status, signUp } = useAuth();
const { status, register } = useAuth();
const checkedLength = computed(() => state.password.length >= 8 && state.password.length <= 128);
const checkedLowerUpper = computed(() => state.password.toLowerCase() !== state.password && state.password.toUpperCase() !== state.password);
@@ -26,17 +26,23 @@ const checkedSymbol = computed(() => " !\"#$%&'()*+,-./:;<=>?@[]^_`{|}~".split("
const usernameError = ref("");
const emailError = ref("");
function register(): void
async function submit()
{
const data = schema.safeParse(state);
if(data.success && state.password !== "" && confirmPassword.value === state.password)
{
try {
signUp({ ...data.data }, { redirect: true, callbackUrl: '/' });
} catch(e) {
usernameError.value = e?.data?.find(e => e.path.includes("username"))?.message ?? "";
emailError.value = e?.data?.find(e => e.path.includes("email"))?.message ?? "";
let errors = await register(data.data.username, data.data.email, data.data.password, {});
if(status.value === AuthStatus.connected)
{
await navigateTo('/');
}
else
{
errors = errors?.issues ?? errors;
usernameError.value = errors?.find((e: any) => e.path.includes("username"))?.message ?? "";
emailError.value = errors?.find((e: any) => e.path.includes("email"))?.message ?? "";
}
}
else
@@ -48,27 +54,41 @@ function register(): void
</script>
<template>
<Head>
<Title>S'inscrire</Title>
</Head>
<div class="site-body-center-column">
<div class="render-container flex align-center justify-center">
<form v-if="status === 'unauthenticated'" @submit.prevent="register" class="input-form input-form-wide">
<form v-if="status === AuthStatus.disconnected" @submit.prevent="submit" class="input-form input-form-wide">
<h1>Inscription</h1>
<Input type="text" v-model="state.username" placeholder="Entrez un nom d'utiliateur" title="Nom d'utilisateur" :error="usernameError"/>
<Input type="text" v-model="state.email" placeholder="Entrez une addresse mail" title="Adresse mail" :error="emailError"/>
<Input type="password" v-model="state.password" placeholder="Entrez un mot de passe" title="Mot de passe" :error="!(checkedLength && checkedLowerUpper && checkedDigit && checkedSymbol)"/>
<Input type="text" autocomplete="username" v-model="state.username"
placeholder="Entrez un nom d'utiliateur" title="Nom d'utilisateur" :error="usernameError" />
<Input type="text" autocomplete="email" v-model="state.email" placeholder="Entrez une addresse mail"
title="Adresse mail" :error="emailError" />
<Input type="password" autocomplete="new-password" v-model="state.password"
placeholder="Entrez un mot de passe" title="Mot de passe"
:error="!(checkedLength && checkedLowerUpper && checkedDigit && checkedSymbol)" />
<div class="password-validation-group">
<span class="password-validation-title">Votre mot de passe doit respecter les critères suivants :</span>
<span class="password-validation-item" :class="{'validation-error': !checkedLength}">Entre 8 et 128 caractères</span>
<span class="password-validation-item" :class="{'validation-error': !checkedLowerUpper}">Au moins une minuscule et une majuscule</span>
<span class="password-validation-item" :class="{'validation-error': !checkedDigit}">Au moins un chiffre</span>
<span class="password-validation-item" :class="{'validation-error': !checkedSymbol}">Au moins un caractère spécial parmis la liste suivante: <pre>! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ ] ^ _ ` { | } ~</pre></span>
<span class="password-validation-title">Votre mot de passe doit respecter les critères suivants
:</span>
<span class="password-validation-item" :class="{'validation-error': !checkedLength}">Entre 8 et 128
caractères</span>
<span class="password-validation-item" :class="{'validation-error': !checkedLowerUpper}">Au moins
une minuscule et une majuscule</span>
<span class="password-validation-item" :class="{'validation-error': !checkedDigit}">Au moins un
chiffre</span>
<span class="password-validation-item" :class="{'validation-error': !checkedSymbol}">Au moins un
caractère spécial parmis la liste suivante:
<pre>! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ ] ^ _ ` { | } ~</pre>
</span>
</div>
<Input type="password" v-model="confirmPassword" placeholder="Confirmer le mot de passe" title="Confirmer le mot de passe" :error="confirmPassword === '' || confirmPassword === state.password ? '' : 'Les mots de passe saisies ne sont pas identique'"/>
<Input type="password" v-model="confirmPassword" placeholder="Confirmer le mot de passe"
title="Confirmer le mot de passe"
:error="confirmPassword === '' || confirmPassword === state.password ? '' : 'Les mots de passe saisies ne sont pas identique'" />
<button>Valider</button>
</form>
<div v-else-if="status === 'loading'"></div>
<div v-else-if="status === AuthStatus.loading" class="input-form"><div class="loading"></div></div>
<div v-else class="not-found-container">
<div class="not-found-title">👀 Vous n'avez rien à faire ici. 👀</div>
</div>