feat: add reCAPTCHA verification, email check, fix email service
- Add reCAPTCHA verification on registration - Add POST /api/auth/check-email endpoint - Fix email service lazy loading - Add FRONTEND_URL and RECAPTCHA keys to env 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2eddd7aa1a
commit
b75f209c35
3
.env
3
.env
|
|
@ -23,3 +23,6 @@ SMTP_PORT=587
|
||||||
SMTP_USER=thetiptopgr3@gmail.com
|
SMTP_USER=thetiptopgr3@gmail.com
|
||||||
SMTP_PASS=xydqvyrxcwwsiups
|
SMTP_PASS=xydqvyrxcwwsiups
|
||||||
EMAIL_FROM=thetiptopgr3@gmail.com
|
EMAIL_FROM=thetiptopgr3@gmail.com
|
||||||
|
|
||||||
|
# reCAPTCHA v2 (obtenir les clés sur https://www.google.com/recaptcha/admin)
|
||||||
|
RECAPTCHA_SECRET_KEY=YOUR_RECAPTCHA_SECRET_KEY
|
||||||
|
|
|
||||||
3
.env.dev
3
.env.dev
|
|
@ -27,3 +27,6 @@ SMTP_PORT=587
|
||||||
SMTP_USER=thetiptopgr3@gmail.com
|
SMTP_USER=thetiptopgr3@gmail.com
|
||||||
SMTP_PASS=xydqvyrxcwwsiups
|
SMTP_PASS=xydqvyrxcwwsiups
|
||||||
EMAIL_FROM=thetiptopgr3@gmail.com
|
EMAIL_FROM=thetiptopgr3@gmail.com
|
||||||
|
|
||||||
|
# reCAPTCHA v2
|
||||||
|
RECAPTCHA_SECRET_KEY=YOUR_RECAPTCHA_SECRET_KEY
|
||||||
|
|
|
||||||
|
|
@ -27,3 +27,6 @@ SMTP_PORT=587
|
||||||
SMTP_USER=thetiptopgr3@gmail.com
|
SMTP_USER=thetiptopgr3@gmail.com
|
||||||
SMTP_PASS=xydqvyrxcwwsiups
|
SMTP_PASS=xydqvyrxcwwsiups
|
||||||
EMAIL_FROM=thetiptopgr3@gmail.com
|
EMAIL_FROM=thetiptopgr3@gmail.com
|
||||||
|
|
||||||
|
# reCAPTCHA v2
|
||||||
|
RECAPTCHA_SECRET_KEY=YOUR_RECAPTCHA_SECRET_KEY
|
||||||
|
|
|
||||||
|
|
@ -27,3 +27,6 @@ SMTP_PORT=587
|
||||||
SMTP_USER=thetiptopgr3@gmail.com
|
SMTP_USER=thetiptopgr3@gmail.com
|
||||||
SMTP_PASS=xydqvyrxcwwsiups
|
SMTP_PASS=xydqvyrxcwwsiups
|
||||||
EMAIL_FROM=thetiptopgr3@gmail.com
|
EMAIL_FROM=thetiptopgr3@gmail.com
|
||||||
|
|
||||||
|
# reCAPTCHA v2
|
||||||
|
RECAPTCHA_SECRET_KEY=YOUR_RECAPTCHA_SECRET_KEY
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,45 @@ import { promisify } from 'util';
|
||||||
|
|
||||||
const resolveMx = promisify(dns.resolveMx);
|
const resolveMx = promisify(dns.resolveMx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vérifier le token reCAPTCHA
|
||||||
|
*/
|
||||||
|
const verifyCaptcha = async (token) => {
|
||||||
|
if (!token) return false;
|
||||||
|
|
||||||
|
const secretKey = process.env.RECAPTCHA_SECRET_KEY;
|
||||||
|
if (!secretKey) {
|
||||||
|
console.warn('⚠️ RECAPTCHA_SECRET_KEY non configuré - captcha désactivé');
|
||||||
|
return true; // Désactiver la vérification si pas de clé
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('https://www.google.com/recaptcha/api/siteverify', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
|
body: `secret=${secretKey}&response=${token}`
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
console.log('📋 reCAPTCHA verification:', data.success ? '✅ OK' : '❌ Failed');
|
||||||
|
return data.success;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Erreur vérification reCAPTCHA:', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inscription d'un nouvel utilisateur
|
* Inscription d'un nouvel utilisateur
|
||||||
* POST /api/auth/register
|
* POST /api/auth/register
|
||||||
*/
|
*/
|
||||||
export const register = asyncHandler(async (req, res, next) => {
|
export const register = asyncHandler(async (req, res, next) => {
|
||||||
const { email, password, firstName, lastName, phone, address, city, postalCode } = req.body;
|
const { email, password, firstName, lastName, phone, address, city, postalCode, captchaToken } = req.body;
|
||||||
|
|
||||||
|
// Vérifier le captcha
|
||||||
|
const captchaValid = await verifyCaptcha(captchaToken);
|
||||||
|
if (!captchaValid) {
|
||||||
|
return next(new AppError('Vérification captcha échouée. Veuillez réessayer.', 400));
|
||||||
|
}
|
||||||
|
|
||||||
// Vérifier si l'utilisateur existe déjà
|
// Vérifier si l'utilisateur existe déjà
|
||||||
const existingUser = await pool.query('SELECT id FROM users WHERE email = $1', [email]);
|
const existingUser = await pool.query('SELECT id FROM users WHERE email = $1', [email]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user