diff --git a/.env.template b/.env.template new file mode 100644 index 0000000..31232ee --- /dev/null +++ b/.env.template @@ -0,0 +1,10 @@ +# Configuration SMTP pour contact-backend.js +SMTP_HOST=HOST +SMTP_PORT=PORT +SMTP_SECURE=false +SMTP_USER=USER +SMTP_FROM=FROM +SMTP_PASS=PASSWORD +PORT=PORT + + diff --git a/contact-backend.js b/contact-backend.js new file mode 100644 index 0000000..3ec1702 --- /dev/null +++ b/contact-backend.js @@ -0,0 +1,60 @@ +// Backend minimal Node.js pour traiter le formulaire de contact Hugo +// Place ce fichier à la racine du projet ou dans un dossier backend/ +// Nécessite: npm install express nodemailer cors + + +require('dotenv').config(); +const express = require('express'); +const nodemailer = require('nodemailer'); +const cors = require('cors'); +const multer = require('multer'); +const upload = multer(); +const app = express(); +const PORT = process.env.PORT || 3001; + +// Middleware +app.use(cors()); +// NE PAS utiliser express.urlencoded/json pour /contact, sinon req.body sera vide avec FormData + +// Configurer le transporteur SMTP depuis .env +const transporter = nodemailer.createTransport({ + host: process.env.SMTP_HOST, + port: parseInt(process.env.SMTP_PORT, 10), + secure: process.env.SMTP_SECURE === 'true', + auth: { + user: process.env.SMTP_USER, + pass: process.env.SMTP_PASS + } +}); + +app.post('/contact', upload.none(), async (req, res) => { + // Vérification de la présence de req.body + if (!req.body) { + console.log(req.body); + return res.status(400).send('Aucune donnée reçue.'); + } + // Anti-robot honeypot + if (req.body.website && req.body.website.trim() !== '') { + return res.status(400).send('Bot détecté.'); + } + const { email, sujet, message } = req.body; + if (!email || !sujet || !message) { + return res.status(400).send('Champs manquants.'); + } + try { + await transporter.sendMail({ + from: process.env.SMTP_USER, + to: process.env.SMTP_USER, + replyTo: email, + subject: `Contact site: ${sujet}`, + text: `Email: ${email}\nSujet: ${sujet}\nMessage:\n${message}` + }); + res.status(200).send('Message envoyé !'); + } catch (err) { + res.status(500).send("Erreur d'envoi: " + err.message); + } +}); + +app.listen(PORT, () => { + console.log(`Serveur contact en écoute sur http://localhost:${PORT}`); +}); diff --git a/content/contact.md b/content/contact.md index c19e024..0fb6d19 100644 --- a/content/contact.md +++ b/content/contact.md @@ -2,11 +2,19 @@ title: Contact layout: "simple" contactForm: + action: "http://localhost:3001/contact" fields: - - name: "name" - label: "Nom complet" - type: "text" + - name: "sujet" + label: "Sujet" + type: "select" required: true + options: + - value: "support" + label: "Support technique" + - value: "vente" + label: "Demande commerciale" + - value: "autre" + label: "Autre" - name: "email" label: "Adresse email" type: "email" diff --git a/package.json b/package.json index ae1392f..8ef3d4e 100644 --- a/package.json +++ b/package.json @@ -18,5 +18,12 @@ "postcss": "^8.4.31", "postcss-cli": "^10.1.0", "tailwindcss": "^3.3.5" + }, + "dependencies": { + "cors": "^2.8.6", + "dotenv": "^17.2.4", + "express": "^5.2.1", + "multer": "^2.0.2", + "nodemailer": "^8.0.1" } -} \ No newline at end of file +} diff --git a/static/css/style.css b/static/css/style.css index 5ea77d5..498c5ec 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -2902,6 +2902,11 @@ body { background-color: rgb(234 179 8 / var(--tw-bg-opacity, 1)); } +.bg-blue-500 { + --tw-bg-opacity: 1; + background-color: rgb(59 130 246 / var(--tw-bg-opacity, 1)); +} + .bg-gradient-to-b { background-image: linear-gradient(to bottom, var(--tw-gradient-stops)); } @@ -4399,6 +4404,11 @@ body { background-color: rgb(140 41 8 / var(--tw-bg-opacity, 1)); } +.hover\:bg-blue-700:hover { + --tw-bg-opacity: 1; + background-color: rgb(29 78 216 / var(--tw-bg-opacity, 1)); +} + .hover\:text-gray-900:hover { --tw-text-opacity: 1; color: rgb(17 24 39 / var(--tw-text-opacity, 1)); diff --git a/themes/chill-theme/layouts/shortcodes/contact-form.html b/themes/chill-theme/layouts/shortcodes/contact-form.html index 33490b1..296ad4f 100644 --- a/themes/chill-theme/layouts/shortcodes/contact-form.html +++ b/themes/chill-theme/layouts/shortcodes/contact-form.html @@ -1,18 +1,60 @@ {{ $form := .Page.Params.contactForm }} -
+ +
+ {{ range $form.fields }}
{{ if eq .type "textarea" }} + {{ else if eq .type "select" }} + {{ else }} {{ end }}
{{ end }} -
- -
+ +
+ + +
+ +
+ +
+