Contact: Friendly Captcha v2, opstartvalidatie, ASF-host met Contact-module en hosttests (CMS-U9)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,7 +30,10 @@ public class ContactModule : IModule
|
||||
{
|
||||
services.AddOptions<ContactOptions>()
|
||||
.Configure<IConfiguration>((options, config) =>
|
||||
config.GetSection(ContactOptions.SectionName).Bind(options));
|
||||
config.GetSection(ContactOptions.SectionName).Bind(options))
|
||||
.ValidateOnStart();
|
||||
// A switched-on captcha with missing settings stops the host at start-up (setting names only, never a value).
|
||||
services.AddSingleton<IValidateOptions<ContactOptions>, ContactOptionsValidator>();
|
||||
|
||||
services.AddDbContext<ContactDbContext>((serviceProvider, options) =>
|
||||
{
|
||||
@@ -43,7 +46,14 @@ public class ContactModule : IModule
|
||||
services.AddScoped<IContactRepository, ContactRepository>();
|
||||
services.AddScoped<IContactSubmissionService, ContactSubmissionService>();
|
||||
services.AddSingleton<IContactTokenService, ContactTokenService>();
|
||||
services.AddSingleton<ICaptchaVerifier, NullCaptchaVerifier>();
|
||||
// Captcha: the provider is chosen by configuration; while it is off (or unset) everything passes.
|
||||
services.AddHttpClient(FriendlyCaptchaVerifier.HttpClientName);
|
||||
services.AddSingleton<FriendlyCaptchaVerifier>();
|
||||
services.AddSingleton<NullCaptchaVerifier>();
|
||||
services.AddSingleton<ICaptchaVerifier>(sp =>
|
||||
sp.GetRequiredService<IOptions<ContactOptions>>().Value.Captcha is { Enabled: true, IsFriendlyCaptcha: true }
|
||||
? sp.GetRequiredService<FriendlyCaptchaVerifier>()
|
||||
: sp.GetRequiredService<NullCaptchaVerifier>());
|
||||
// Mail: the request only stores and signals; the background service sends (and retries) with the host's mail pieces.
|
||||
services.AddScoped<IContactMailSender, ContactMailSender>();
|
||||
services.AddSingleton<IContactMailSignal, ContactMailSignal>();
|
||||
|
||||
Reference in New Issue
Block a user