U1 mail-foundation (backend): verzender, opties, sjabloon, SiteSettings met toegestane afzenderlijst
IEmailSender met MailKit-implementatie (StartTls, timeout, fouten als waarde), opties met startvalidatie, nl/en sjabloon, taalkeuze, tabel SiteSettings (additieve migratie), SiteSettings-API (Beheerder leest, Eigenaar wijzigt) en emailEnabled/defaultLanguage in de capabilities. Zonder SMTP-host verandert er niets. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SlpModularCms.Core.SiteSettings;
|
||||
|
||||
namespace SlpModularCms.Modules.Identity.Controllers;
|
||||
|
||||
/// <summary>Per-site settings. Mail: an Administrator reads, only an Owner changes.</summary>
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class SiteSettingsController : ControllerBase
|
||||
{
|
||||
private readonly ISiteSettingsService _settings;
|
||||
|
||||
public SiteSettingsController(ISiteSettingsService settings)
|
||||
{
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
[HttpGet("mail")]
|
||||
[Authorize(Policy = "AdminOnly")]
|
||||
public async Task<IActionResult> GetMail(CancellationToken ct) => Ok(await _settings.GetMailAsync(ct));
|
||||
|
||||
[HttpPut("mail")]
|
||||
[Authorize(Policy = "OwnerOnly")]
|
||||
public async Task<IActionResult> SetMail([FromBody] UpdateMailSettingsRequest request, CancellationToken ct)
|
||||
{
|
||||
var result = await _settings.SetMailAsync(request.FromAddress, request.FromName, User.Identity?.Name, ct);
|
||||
if (result.Ok) return Ok(await _settings.GetMailAsync(ct));
|
||||
|
||||
return result.Error == SetMailResult.MailDisabled
|
||||
? Conflict(new { code = result.Error, detail = "Mail is not enabled on this site." })
|
||||
: BadRequest(new { code = result.Error, detail = "The mail settings are not valid." });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Both values empty (or null) resets the sender to the configured defaults.</summary>
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
public record UpdateMailSettingsRequest(string? FromAddress, string? FromName);
|
||||
Reference in New Issue
Block a user