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,44 @@
using System.Diagnostics.CodeAnalysis;
namespace SlpModularCms.Modules.Contact.Models;
/// <summary>
/// The body of POST /contact-messages. Everything is nullable on purpose: a missing field is
/// reported as the validation code <c>required</c> in our own problem shape instead of a
/// framework binding error. <c>HpCheck</c> is the honeypot (JSON name <c>hpCheck</c>).
/// </summary>
public record ContactMessageRequest(
string? Name,
string? Email,
string? Subject,
string? Message,
string? HpCheck,
string? Token,
string? CaptchaToken);
[ExcludeFromCodeCoverage]
public record ContactCaptchaInfo(string Provider, string SiteKey);
[ExcludeFromCodeCoverage]
public record ContactTokenResponse(string Token, int MinSeconds, ContactCaptchaInfo? Captcha);
[ExcludeFromCodeCoverage]
public record ReceivedResponse(string Status);
/// <summary>Validation error codes, as the client maps them to texts.</summary>
public static class ContactErrorCodes
{
public const string Required = "required";
public const string TooLong = "tooLong";
public const string Invalid = "invalid";
public const string Expired = "expired";
}
/// <summary>Outcome of handling one submission.</summary>
public abstract record SubmissionResult
{
/// <summary>Accepted: genuine, spam and replays all look the same to the caller.</summary>
public sealed record Received : SubmissionResult;
public sealed record Invalid(IReadOnlyDictionary<string, string[]> Errors) : SubmissionResult;
}