Contactmodule: token- en inzendroute met spamafhandeling, idempotentie en retentietaak

Nieuwe module SlpModularCms.Modules.Contact met eigen DbContext en migratie InitialCreate. GET contact-messages/token en POST contact-messages zijn publiek ([PublicSiteEndpoint]), geven bij echte inzendingen, spam en herhalingen hetzelfde 202 en slaan spam apart op (30 dagen, dagplafond). Standaard staat de module uit (Contact:Enabled=false, 404 met lege body, geen databasetoegang) totdat de rate limiting per client op de basisbranch staat; de rate-limit-sleutel zit in een enkele functie zodat dat later een regel wijzigen is. Mail zit achter een seam (nog een no-op).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 13:07:27 +01:00
co-authored by Claude Sonnet 5.5
parent 0f6f5475a1
commit 7748bbe9c9
37 changed files with 3266 additions and 9 deletions
@@ -0,0 +1,58 @@
namespace SlpModularCms.Modules.Contact.Data.Entities;
public enum ContactMessageStatus
{
New,
Read,
Archived,
Spam,
Converted,
}
public enum ContactMailStatus
{
/// <summary>Waiting to be mailed (also the state while no mail sender is available).</summary>
Pending,
Sent,
Failed,
/// <summary>Never mailed on purpose (spam).</summary>
NotApplicable,
}
/// <summary>
/// A message sent through the website's contact form. Has its own id and status so that it can
/// later be turned into an assignment (quotes, invoices); that is not built yet.
/// </summary>
public class ContactMessage
{
public Guid Id { get; set; }
public string SiteId { get; set; } = string.Empty;
public DateTimeOffset ReceivedAt { get; set; }
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
/// <summary>Opaque value chosen by the site (a package id, a slug, or 'other').</summary>
public string Subject { get; set; } = string.Empty;
public string Message { get; set; } = string.Empty;
public ContactMessageStatus Status { get; set; }
public ContactMailStatus MailStatus { get; set; }
/// <summary>Short error code of the last failed mail attempt (never an address or content).</summary>
public string? MailError { get; set; }
public int MailAttempts { get; set; }
public DateTimeOffset? NextMailAttemptAt { get; set; }
/// <summary>Fixed at insert: a later configuration change does not apply retroactively.</summary>
public DateTimeOffset RetentionUntil { get; set; }
}
/// <summary>Remembers an Idempotency-Key for 24 hours. Holds no request content.</summary>
public class IdempotencyRecord
{
public string SiteId { get; set; } = string.Empty;
public Guid Key { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public int StatusCode { get; set; }
}