email datenschztz erst alles bestätigt bei allen hebeln

This commit is contained in:
2026-03-27 12:03:20 +01:00
parent 3dd4f7b656
commit 5b85bea4eb
3 changed files with 68 additions and 3 deletions
@@ -3,6 +3,8 @@ import * as consentPublicService from '../services/consent-public.service.js';
import { createAuditLog } from '../services/audit.service.js';
import { CONSENT_TYPE_LABELS } from '../services/consent.service.js';
import { ConsentType } from '@prisma/client';
import { sendEmail } from '../services/smtpService.js';
import { getSystemEmailCredentials } from '../services/emailProvider/emailProviderService.js';
/**
* Öffentliche Consent-Seite: Kundendaten + Datenschutztext + Status
@@ -76,6 +78,66 @@ export async function grantAllConsents(req: Request, res: Response) {
}
}
// Bestätigungs-E-Mail senden
if (customer?.customer.email) {
try {
const systemEmail = await getSystemEmailCredentials();
if (systemEmail) {
const consentList = Object.values(ConsentType)
.map(t => CONSENT_TYPE_LABELS[t]?.label || t)
.map(label => `<li>${label}</li>`)
.join('');
const confirmationHtml = `
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
<h2 style="color: #16a34a;">Bestätigung Ihrer Einwilligungen</h2>
<p>Sehr geehrte(r) ${customer.customer.firstName} ${customer.customer.lastName},</p>
<p>
vielen Dank! Hiermit bestätigen wir, dass Sie am ${new Date().toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' })}
folgenden Einwilligungen zugestimmt haben:
</p>
<ul style="color: #16a34a;">
${consentList}
</ul>
<p>
Sie können Ihre Einwilligungen jederzeit über Ihr Kundenportal widerrufen.
</p>
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 24px 0;">
<p style="color: #9ca3af; font-size: 12px;">
Hacker-Net Telekommunikation Stefan Hacker<br>
Am Wunderburgpark 5b, 26135 Oldenburg<br>
info@hacker-net.de
</p>
</div>
`;
await sendEmail(
{
host: systemEmail.smtpServer,
port: systemEmail.smtpPort,
user: systemEmail.emailAddress,
password: systemEmail.password,
encryption: systemEmail.smtpEncryption,
allowSelfSignedCerts: systemEmail.allowSelfSignedCerts,
},
systemEmail.emailAddress,
{
to: customer.customer.email,
subject: 'Bestätigung Ihrer Datenschutz-Einwilligungen',
html: confirmationHtml,
},
{
context: 'consent-confirmation',
customerId: customer.customer.id,
}
);
}
} catch (emailError) {
// E-Mail-Fehler soll den Consent-Grant nicht blockieren
console.error('Bestätigungs-E-Mail konnte nicht gesendet werden:', emailError);
}
}
res.json({ success: true, data: results });
} catch (error: any) {
console.error('Fehler beim Erteilen der Einwilligungen:', error);