changement
This commit is contained in:
@@ -5,6 +5,8 @@ import { useAuth } from '../context/AuthContext'
|
||||
import usePageMeta from '../hooks/usePageMeta'
|
||||
import Captcha from '../components/Captcha'
|
||||
import { CAPTCHA_ENABLED } from '../config/captcha'
|
||||
import { isPasswordValid, PASSWORD_RULES_ERROR } from '../utils/passwordRules'
|
||||
import PasswordRules from '../components/PasswordRules'
|
||||
|
||||
// Une naissance ne peut pas être dans le futur : borne haute du sélecteur.
|
||||
const AUJOURD_HUI = new Date().toISOString().split('T')[0]
|
||||
@@ -42,6 +44,7 @@ export default function Inscription() {
|
||||
lastName: '',
|
||||
firstName: '',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
birthdate: '',
|
||||
gender: '',
|
||||
})
|
||||
@@ -63,6 +66,9 @@ export default function Inscription() {
|
||||
|
||||
const handleChange = (e) => setForm({ ...form, [e.target.name]: e.target.value })
|
||||
|
||||
// Signalé dès que la confirmation est saisie, sans attendre l'envoi.
|
||||
const passwordMismatch = form.confirmPassword !== '' && form.password !== form.confirmPassword
|
||||
|
||||
// Même route que la connexion : le provider crée le compte à la première venue.
|
||||
const handleOAuthSignup = (provider) => {
|
||||
const apiUrl = import.meta.env.VITE_API_URL || ''
|
||||
@@ -79,6 +85,16 @@ export default function Inscription() {
|
||||
return
|
||||
}
|
||||
|
||||
if (!isPasswordValid(form.password)) {
|
||||
setError(PASSWORD_RULES_ERROR)
|
||||
return
|
||||
}
|
||||
|
||||
if (form.password !== form.confirmPassword) {
|
||||
setError('Les deux mots de passe ne correspondent pas.')
|
||||
return
|
||||
}
|
||||
|
||||
setLoading(true)
|
||||
try {
|
||||
await registerApi({
|
||||
@@ -86,6 +102,7 @@ export default function Inscription() {
|
||||
firstname: form.firstName,
|
||||
lastname: form.lastName,
|
||||
password: form.password,
|
||||
confirmPassword: form.confirmPassword,
|
||||
birthdate: form.birthdate,
|
||||
gender: form.gender,
|
||||
marketingOptIn,
|
||||
@@ -256,6 +273,7 @@ export default function Inscription() {
|
||||
<label htmlFor="reg-password" className="block text-sm font-medium text-gray-800 mb-1">Mot de passe <span className="text-gray-800">*</span></label>
|
||||
<div className="relative">
|
||||
<input type={showPassword ? 'text' : 'password'} id="reg-password" name="password" value={form.password} onChange={handleChange} required placeholder="Votre mot de passe"
|
||||
autoComplete="new-password" aria-describedby="reg-password-rules"
|
||||
className="w-full border border-gray-200 rounded-lg px-4 py-3 pr-12 text-sm text-gray-700 placeholder-gray-500 focus:outline-none focus:ring-1 focus:ring-[#006B6B] focus:border-[#006B6B]" />
|
||||
<button type="button" onClick={() => setShowPassword(!showPassword)}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-600" aria-label="Afficher/masquer">
|
||||
@@ -264,6 +282,17 @@ export default function Inscription() {
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
<PasswordRules id="reg-password-rules" password={form.password} />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="reg-confirm-password" className="block text-sm font-medium text-gray-800 mb-1">Confirmer le mot de passe <span className="text-gray-800">*</span></label>
|
||||
<input type={showPassword ? 'text' : 'password'} id="reg-confirm-password" name="confirmPassword" value={form.confirmPassword} onChange={handleChange} required placeholder="Saisissez-le à nouveau"
|
||||
autoComplete="new-password" aria-invalid={passwordMismatch} aria-describedby={passwordMismatch ? 'reg-confirm-password-error' : undefined}
|
||||
className={`w-full border rounded-lg px-4 py-3 text-sm text-gray-700 placeholder-gray-500 focus:outline-none focus:ring-1 ${passwordMismatch ? 'border-red-300 focus:ring-red-400 focus:border-red-400' : 'border-gray-200 focus:ring-[#006B6B] focus:border-[#006B6B]'}`} />
|
||||
{passwordMismatch && (
|
||||
<p id="reg-confirm-password-error" className="text-xs text-red-600 mt-1">Les deux mots de passe ne correspondent pas.</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<label className="flex items-start gap-3 cursor-pointer">
|
||||
|
||||
Reference in New Issue
Block a user