Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | 1x 1x 1x | /**
* Service Email — Envoi d'emails via SMTP OVH.
*
* Configuration via variables d'environnement :
* SMTP_HOST — Serveur SMTP (defaut: ssl0.ovh.net)
* SMTP_PORT — Port (defaut: 465)
* SMTP_USER — Adresse email d'envoi
* SMTP_PASSWORD — Mot de passe SMTP
* SMTP_FROM — Adresse expediteur (defaut: SMTP_USER)
*
* @module services/email
*/
const nodemailer = require('nodemailer');
let transporter = null;
/**
* Initialise le transporteur SMTP.
* Appele a la demande (lazy init).
*/
function getTransporter() {
if (transporter) return transporter;
const host = process.env.SMTP_HOST || 'ssl0.ovh.net';
const port = Number.parseInt(process.env.SMTP_PORT) || 465;
const user = process.env.SMTP_USER;
const pass = process.env.SMTP_PASSWORD;
if (!user || !pass) {
console.warn('[email] SMTP_USER ou SMTP_PASSWORD non configure — emails desactives');
return null;
}
transporter = nodemailer.createTransport({
host,
port,
secure: port === 465,
auth: { user, pass },
});
console.log(`[email] SMTP configure : ${user} via ${host}:${port}`);
return transporter;
}
/**
* Envoie un email.
*
* @param {Object} opts
* @param {string} opts.to — Destinataire
* @param {string} opts.subject — Sujet
* @param {string} opts.html — Corps HTML
* @param {string} [opts.text] — Corps texte (fallback auto si absent)
* @returns {Promise<boolean>}
*/
async function sendEmail({ to, subject, html, text }) {
const t = getTransporter();
if (!t) {
console.warn(`[email] Email non envoye (SMTP non configure) : ${subject} → ${to}`);
return false;
}
try {
const from = process.env.SMTP_FROM || process.env.SMTP_USER;
await t.sendMail({
from: `IliaCloud <${from}>`,
to,
subject,
html,
// ReDoS-safe : [^>]+ et '>' sont disjoints — zero ambiguite, backtracking impossible
text: text || html.replace(/<[^>]+>/g, ''), // NOSONAR — regex safe (classe niee)
});
console.log(`[email] Envoye : ${subject} → ${to}`);
return true;
} catch (err) {
console.error(`[email] Erreur envoi : ${err.message}`);
return false;
}
}
/**
* Envoie un email avec piece(s) jointe(s).
*
* @param {Object} opts
* @param {string} opts.to — Destinataire
* @param {string} opts.subject — Sujet
* @param {string} opts.html — Corps HTML
* @param {string} [opts.text] — Corps texte (fallback auto)
* @param {Array} opts.attachments — [{ filename, content (Buffer), contentType }]
* @returns {Promise<boolean>}
*/
async function sendEmailWithAttachment({ to, subject, html, text, attachments }) {
const t = getTransporter();
if (!t) {
console.warn(`[email] Email non envoye (SMTP non configure) : ${subject} → ${to}`);
return false;
}
try {
const from = process.env.SMTP_FROM || process.env.SMTP_USER;
await t.sendMail({
from: `IliaCloud <${from}>`,
to,
subject,
html,
text: text || html.replace(/<[^>]+>/g, ''), // NOSONAR — regex safe (classe niee)
attachments: (attachments || []).map((a) => ({
filename: a.filename,
content: a.content,
contentType: a.contentType,
})),
});
console.log(`[email] Envoye (avec PJ) : ${subject} → ${to}`);
return true;
} catch (err) {
console.error(`[email] Erreur envoi : ${err.message}`);
return false;
}
}
/**
* Envoie l'email de verification d'adresse.
*
* @param {string} email — Adresse du destinataire
* @param {string} token — Token de verification
*/
async function sendVerificationEmail(email, token) {
const baseUrl = process.env.CORS_ORIGIN || 'https://app.iliacloud.com';
const verifyUrl = `${baseUrl}/verify-email?token=${token}`;
return sendEmail({
to: email,
subject: 'Confirmez votre adresse email — IliaCloud',
html: `
<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"></head>
<body style="margin: 0; padding: 0; background-color: #f4f4f7; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background-color: #f4f4f7;">
<tr><td align="center" style="padding: 40px 20px;">
<table role="presentation" width="500" cellpadding="0" cellspacing="0" style="max-width: 500px; width: 100%;">
<!-- Logo -->
<tr><td align="center" style="padding-bottom: 32px;">
<span style="font-size: 28px; font-weight: 800; color: #1e293b; letter-spacing: -0.5px;">
<span style="color: #6366f1;">Ilia</span>Cloud
</span>
</td></tr>
<!-- Card -->
<tr><td style="background: #ffffff; border-radius: 12px; padding: 40px 36px; box-shadow: 0 1px 3px rgba(0,0,0,0.08);">
<h1 style="font-size: 22px; font-weight: 700; color: #1e293b; margin: 0 0 12px 0;">
Confirmez votre email
</h1>
<p style="font-size: 15px; color: #475569; line-height: 1.6; margin: 0 0 28px 0;">
Bienvenue sur IliaCloud ! Cliquez sur le bouton ci-dessous pour confirmer votre adresse email et activer votre compte.
</p>
<!-- Button -->
<table role="presentation" width="100%" cellpadding="0" cellspacing="0">
<tr><td align="center" style="padding: 4px 0 28px 0;">
<a href="${verifyUrl}" style="display: inline-block; background: #6366f1; color: #ffffff; padding: 14px 36px; border-radius: 8px; text-decoration: none; font-weight: 600; font-size: 15px; letter-spacing: 0.2px;">
Confirmer mon email
</a>
</td></tr>
</table>
<!-- Divider -->
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 0 0 20px 0;">
<p style="font-size: 13px; color: #9ca3af; line-height: 1.5; margin: 0;">
Ce lien expire dans 24 heures. Si vous n'avez pas cree de compte sur IliaCloud, ignorez simplement cet email.
</p>
</td></tr>
<!-- Footer -->
<tr><td align="center" style="padding: 24px 0 0 0;">
<p style="font-size: 12px; color: #9ca3af; margin: 0;">
IliaCloud — Gerez vos serveurs depuis votre navigateur
</p>
<p style="font-size: 11px; color: #9ca3af; margin: 8px 0 0 0;">
<a href="${verifyUrl}" style="color: #6366f1; text-decoration: underline; word-break: break-all;">${verifyUrl}</a>
</p>
</td></tr>
</table>
</td></tr>
</table>
</body></html>
`,
});
}
/**
* Envoie l'email de reinitialisation de mot de passe.
*
* @param {string} email — Adresse du destinataire
* @param {string} token — Token de reinitialisation
*/
async function sendPasswordResetEmail(email, token) {
const baseUrl = process.env.CORS_ORIGIN || 'https://app.iliacloud.com';
const resetUrl = `${baseUrl}/reset-password?token=${token}`;
return sendEmail({
to: email,
subject: 'Reinitialisation de votre mot de passe — IliaCloud',
html: `
<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"></head>
<body style="margin: 0; padding: 0; background-color: #f4f4f7; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background-color: #f4f4f7;">
<tr><td align="center" style="padding: 40px 20px;">
<table role="presentation" width="500" cellpadding="0" cellspacing="0" style="max-width: 500px; width: 100%;">
<!-- Logo -->
<tr><td align="center" style="padding-bottom: 32px;">
<span style="font-size: 28px; font-weight: 800; color: #1e293b; letter-spacing: -0.5px;">
<span style="color: #6366f1;">Ilia</span>Cloud
</span>
</td></tr>
<!-- Card -->
<tr><td style="background: #ffffff; border-radius: 12px; padding: 40px 36px; box-shadow: 0 1px 3px rgba(0,0,0,0.08);">
<h1 style="font-size: 22px; font-weight: 700; color: #1e293b; margin: 0 0 12px 0;">
Reinitialiser votre mot de passe
</h1>
<p style="font-size: 15px; color: #475569; line-height: 1.6; margin: 0 0 28px 0;">
Vous avez demande la reinitialisation de votre mot de passe. Cliquez sur le bouton ci-dessous pour choisir un nouveau mot de passe.
</p>
<!-- Button -->
<table role="presentation" width="100%" cellpadding="0" cellspacing="0">
<tr><td align="center" style="padding: 4px 0 28px 0;">
<a href="${resetUrl}" style="display: inline-block; background: #6366f1; color: #ffffff; padding: 14px 36px; border-radius: 8px; text-decoration: none; font-weight: 600; font-size: 15px; letter-spacing: 0.2px;">
Reinitialiser mon mot de passe
</a>
</td></tr>
</table>
<!-- Divider -->
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 0 0 20px 0;">
<p style="font-size: 13px; color: #9ca3af; line-height: 1.5; margin: 0;">
Ce lien expire dans 1 heure. Si vous n'avez pas demande de reinitialisation, ignorez simplement cet email — votre mot de passe restera inchange.
</p>
</td></tr>
<!-- Footer -->
<tr><td align="center" style="padding: 24px 0 0 0;">
<p style="font-size: 12px; color: #9ca3af; margin: 0;">
IliaCloud — Gerez vos serveurs depuis votre navigateur
</p>
<p style="font-size: 11px; color: #9ca3af; margin: 8px 0 0 0;">
<a href="${resetUrl}" style="color: #6366f1; text-decoration: underline; word-break: break-all;">${resetUrl}</a>
</p>
</td></tr>
</table>
</td></tr>
</table>
</body></html>
`,
});
}
/**
* Envoie l'email de confirmation pour un changement d'adresse.
*
* @param {string} newEmail — Nouvelle adresse a verifier
* @param {string} token — Token de verification
*/
async function sendEmailChangeVerification(newEmail, token) {
const baseUrl = process.env.CORS_ORIGIN || 'https://app.iliacloud.com';
const verifyUrl = `${baseUrl}/verify-new-email?token=${token}`;
return sendEmail({
to: newEmail,
subject: 'Confirmez votre nouvelle adresse email — IliaCloud',
html: `
<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"></head>
<body style="margin: 0; padding: 0; background-color: #f4f4f7; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background-color: #f4f4f7;">
<tr><td align="center" style="padding: 40px 20px;">
<table role="presentation" width="500" cellpadding="0" cellspacing="0" style="max-width: 500px; width: 100%;">
<!-- Logo -->
<tr><td align="center" style="padding-bottom: 32px;">
<span style="font-size: 28px; font-weight: 800; color: #1e293b; letter-spacing: -0.5px;">
<span style="color: #6366f1;">Ilia</span>Cloud
</span>
</td></tr>
<!-- Card -->
<tr><td style="background: #ffffff; border-radius: 12px; padding: 40px 36px; box-shadow: 0 1px 3px rgba(0,0,0,0.08);">
<h1 style="font-size: 22px; font-weight: 700; color: #1e293b; margin: 0 0 12px 0;">
Confirmez votre nouvelle adresse
</h1>
<p style="font-size: 15px; color: #475569; line-height: 1.6; margin: 0 0 28px 0;">
Vous avez demande a changer votre adresse email sur IliaCloud. Cliquez sur le bouton ci-dessous pour confirmer cette nouvelle adresse.
</p>
<!-- Button -->
<table role="presentation" width="100%" cellpadding="0" cellspacing="0">
<tr><td align="center" style="padding: 4px 0 28px 0;">
<a href="${verifyUrl}" style="display: inline-block; background: #6366f1; color: #ffffff; padding: 14px 36px; border-radius: 8px; text-decoration: none; font-weight: 600; font-size: 15px; letter-spacing: 0.2px;">
Confirmer cette adresse
</a>
</td></tr>
</table>
<!-- Divider -->
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 0 0 20px 0;">
<p style="font-size: 13px; color: #9ca3af; line-height: 1.5; margin: 0;">
Ce lien expire dans 24 heures. Si vous n'avez pas demande ce changement, ignorez cet email — votre adresse restera inchangee.
</p>
</td></tr>
<!-- Footer -->
<tr><td align="center" style="padding: 24px 0 0 0;">
<p style="font-size: 12px; color: #9ca3af; margin: 0;">
IliaCloud — Gerez vos serveurs depuis votre navigateur
</p>
<p style="font-size: 11px; color: #9ca3af; margin: 8px 0 0 0;">
<a href="${verifyUrl}" style="color: #6366f1; text-decoration: underline; word-break: break-all;">${verifyUrl}</a>
</p>
</td></tr>
</table>
</td></tr>
</table>
</body></html>
`,
});
}
module.exports = { sendEmail, sendEmailWithAttachment, sendVerificationEmail, sendPasswordResetEmail, sendEmailChangeVerification };
|