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:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user