Vertaalbestanden 7: resterende Engelse API-antwoorden (wachtwoord/gebruikersbeheer, 13) en interne-serverfoutzin naar de tekstbestanden; docs/mail-teksten.md (gegenereerd overzicht van alle mailteksten)
TWEEDE GEDRAGSWIJZIGING (goedgekeurd): de 13 Engelse antwoorden van auth/users zijn Nederlands bij Texts:DefaultLanguage=nl; en-bestand = oude tekst letterlijk. De admin toont voor wachtwoord vergeten zijn eigen tekst. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,4 +31,32 @@ public class CoreTextsTests
|
||||
TextCatalog.Default.Get(CoreTexts.Identity.Invitation.CreateFailed, args: ("errors", "a, b")).Should().Be("Kan gebruiker niet aanmaken: a, b");
|
||||
TextCatalog.Default.Get(CoreTexts.Identity.Setup.CreateOwnerFailed, args: ("errors", "a, b")).Should().Be("Fout bij aanmaken eigenaar: a, b");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("core.identity.auth.invalidEmail", "Enter a valid e-mail address.")]
|
||||
[InlineData("core.identity.auth.resetRequested", "If this address belongs to an account, an e-mail with a link has been sent.")]
|
||||
[InlineData("core.identity.auth.linkInvalid", "This link is invalid or has expired.")]
|
||||
[InlineData("core.identity.auth.passwordSet", "Password set. You can sign in now.")]
|
||||
[InlineData("core.identity.auth.passwordRejected", "The password does not meet the requirements.")]
|
||||
[InlineData("core.identity.users.emailInUse", "Email is already in use.")]
|
||||
[InlineData("core.identity.users.unsupportedLanguage", "Unsupported language.")]
|
||||
[InlineData("core.identity.users.updateProfileFailed", "Failed to update profile.")]
|
||||
[InlineData("core.identity.users.lastOwner", "At least one Owner must remain.")]
|
||||
[InlineData("core.identity.users.cannotChangeOwnActive", "You cannot change your own active status.")]
|
||||
[InlineData("core.identity.users.updateUserFailed", "Failed to update user.")]
|
||||
[InlineData("core.identity.users.cannotDeleteSelf", "You cannot delete your own account.")]
|
||||
[InlineData("core.identity.users.deleteUserFailed", "Failed to delete user.")]
|
||||
public void TheEnglishTexts_OfTheFormerlyEnglishOnlyMessages_AreTheOldWording(string key, string expected)
|
||||
=> TextCatalog.Default.Get(new TextKey(key), "en").Should().Be(expected);
|
||||
|
||||
[Fact]
|
||||
public void TheInternalErrorDetail_IsTheOldDutchSentence()
|
||||
=> TextCatalog.Default.Get(CoreTexts.Errors.Internal).Should().Be("Er is een interne serverfout opgetreden.");
|
||||
|
||||
[Fact]
|
||||
public void TheFormerlyEnglishOnlyMessages_AreNowDutchInTheDefaultLanguage()
|
||||
{
|
||||
TextCatalog.Default.Get(CoreTexts.Identity.Users.CannotDeleteSelf).Should().Be("Je kunt je eigen account niet verwijderen.");
|
||||
TextCatalog.Default.Get(CoreTexts.Identity.Auth.ResetRequested).Should().StartWith("Als dit adres bij een account hoort");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using SlpModularCms.Core.Texts;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Diagnostics;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -58,7 +59,7 @@ public class GlobalExceptionHandler : IExceptionHandler
|
||||
Title = title,
|
||||
Detail = exception is InvitationOrUserAlreadyExistsException
|
||||
? exception.Message // Dutch, written for the user, contains no internals
|
||||
: _env.IsDevelopment() ? exception.ToString() : "Er is een interne serverfout opgetreden.",
|
||||
: _env.IsDevelopment() ? exception.ToString() : HttpTexts.From(httpContext).Get(CoreTexts.Errors.Internal),
|
||||
Instance = httpContext.Request.Path
|
||||
};
|
||||
|
||||
|
||||
@@ -26,6 +26,13 @@ public static class CoreTexts
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Generic error texts of the API (the technical ProblemDetails titles stay in code).</summary>
|
||||
public static class Errors
|
||||
{
|
||||
/// <summary>The detail of a 500 answer outside development: no internals.</summary>
|
||||
public static readonly TextKey Internal = new("core.errors.internal");
|
||||
}
|
||||
|
||||
/// <summary>Messages of sign-in, invitations and first-time setup (shown to the administrator). Key path <c>core.identity.*</c>.</summary>
|
||||
public static class Identity
|
||||
{
|
||||
@@ -35,6 +42,26 @@ public static class CoreTexts
|
||||
public static readonly TextKey InvalidRefreshToken = new("core.identity.auth.invalidRefreshToken");
|
||||
public static readonly TextKey TokenReuse = new("core.identity.auth.tokenReuse");
|
||||
public static readonly TextKey UserNotFound = new("core.identity.auth.userNotFound");
|
||||
|
||||
// Answers of the password-reset endpoints (the admin shows its own text for most of them).
|
||||
public static readonly TextKey InvalidEmail = new("core.identity.auth.invalidEmail");
|
||||
public static readonly TextKey ResetRequested = new("core.identity.auth.resetRequested");
|
||||
public static readonly TextKey LinkInvalid = new("core.identity.auth.linkInvalid");
|
||||
public static readonly TextKey PasswordSet = new("core.identity.auth.passwordSet");
|
||||
public static readonly TextKey PasswordRejected = new("core.identity.auth.passwordRejected");
|
||||
}
|
||||
|
||||
/// <summary>Answers of the user-management endpoints.</summary>
|
||||
public static class Users
|
||||
{
|
||||
public static readonly TextKey EmailInUse = new("core.identity.users.emailInUse");
|
||||
public static readonly TextKey UnsupportedLanguage = new("core.identity.users.unsupportedLanguage");
|
||||
public static readonly TextKey UpdateProfileFailed = new("core.identity.users.updateProfileFailed");
|
||||
public static readonly TextKey LastOwner = new("core.identity.users.lastOwner");
|
||||
public static readonly TextKey CannotChangeOwnActive = new("core.identity.users.cannotChangeOwnActive");
|
||||
public static readonly TextKey UpdateUserFailed = new("core.identity.users.updateUserFailed");
|
||||
public static readonly TextKey CannotDeleteSelf = new("core.identity.users.cannotDeleteSelf");
|
||||
public static readonly TextKey DeleteUserFailed = new("core.identity.users.deleteUserFailed");
|
||||
}
|
||||
|
||||
public static class Invitation
|
||||
|
||||
@@ -63,7 +63,12 @@
|
||||
"invalidCredentials": "Invalid credentials.",
|
||||
"invalidRefreshToken": "Invalid refresh token.",
|
||||
"tokenReuse": "Possible token abuse detected. All sessions have been ended.",
|
||||
"userNotFound": "User not found."
|
||||
"userNotFound": "User not found.",
|
||||
"invalidEmail": "Enter a valid e-mail address.",
|
||||
"resetRequested": "If this address belongs to an account, an e-mail with a link has been sent.",
|
||||
"linkInvalid": "This link is invalid or has expired.",
|
||||
"passwordSet": "Password set. You can sign in now.",
|
||||
"passwordRejected": "The password does not meet the requirements."
|
||||
},
|
||||
"invitation": {
|
||||
"userExists": "A user with this e-mail address already exists.",
|
||||
@@ -76,6 +81,16 @@
|
||||
"alreadyInitialized": "The system has already been initialised.",
|
||||
"createOwnerFailed": "Could not create the owner: {errors}",
|
||||
"completed": "System initialised successfully. The first owner has been created."
|
||||
},
|
||||
"users": {
|
||||
"emailInUse": "Email is already in use.",
|
||||
"unsupportedLanguage": "Unsupported language.",
|
||||
"updateProfileFailed": "Failed to update profile.",
|
||||
"lastOwner": "At least one Owner must remain.",
|
||||
"cannotChangeOwnActive": "You cannot change your own active status.",
|
||||
"updateUserFailed": "Failed to update user.",
|
||||
"cannotDeleteSelf": "You cannot delete your own account.",
|
||||
"deleteUserFailed": "Failed to delete user."
|
||||
}
|
||||
},
|
||||
"host": {
|
||||
@@ -87,6 +102,9 @@
|
||||
"note": "This page is replaced automatically as soon as the website is deployed.",
|
||||
"fallback": "<p>There is no website here yet. Manage the site at <a href=\"/admin/\">/admin/</a>.</p>"
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
"internal": "An internal server error occurred."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,12 @@
|
||||
"invalidCredentials": "Ongeldige inloggegevens.",
|
||||
"invalidRefreshToken": "Ongeldig refresh token.",
|
||||
"tokenReuse": "Mogelijk token misbruik gedetecteerd. Alle sessies zijn beëindigd.",
|
||||
"userNotFound": "Gebruiker niet gevonden."
|
||||
"userNotFound": "Gebruiker niet gevonden.",
|
||||
"invalidEmail": "Voer een geldig e-mailadres in.",
|
||||
"resetRequested": "Als dit adres bij een account hoort, is er een e-mail met een link verstuurd.",
|
||||
"linkInvalid": "Deze link is ongeldig of verlopen.",
|
||||
"passwordSet": "Wachtwoord ingesteld. Je kunt nu inloggen.",
|
||||
"passwordRejected": "Het wachtwoord voldoet niet aan de eisen."
|
||||
},
|
||||
"invitation": {
|
||||
"userExists": "Er bestaat al een gebruiker met dit e-mailadres.",
|
||||
@@ -76,6 +81,16 @@
|
||||
"alreadyInitialized": "Systeem is al geïnitialiseerd.",
|
||||
"createOwnerFailed": "Fout bij aanmaken eigenaar: {errors}",
|
||||
"completed": "Systeem succesvol geïnitialiseerd. De eerste eigenaar is aangemaakt."
|
||||
},
|
||||
"users": {
|
||||
"emailInUse": "Dit e-mailadres is al in gebruik.",
|
||||
"unsupportedLanguage": "Deze taal wordt niet ondersteund.",
|
||||
"updateProfileFailed": "Het profiel kon niet worden bijgewerkt.",
|
||||
"lastOwner": "Er moet minstens één eigenaar overblijven.",
|
||||
"cannotChangeOwnActive": "Je kunt je eigen actieve status niet wijzigen.",
|
||||
"updateUserFailed": "De gebruiker kon niet worden bijgewerkt.",
|
||||
"cannotDeleteSelf": "Je kunt je eigen account niet verwijderen.",
|
||||
"deleteUserFailed": "De gebruiker kon niet worden verwijderd."
|
||||
}
|
||||
},
|
||||
"host": {
|
||||
@@ -87,6 +102,9 @@
|
||||
"note": "Deze pagina wordt automatisch vervangen zodra de website is geplaatst.",
|
||||
"fallback": "<p>Er staat hier nog geen website. Beheer via <a href=\"/admin/\">/admin/</a>.</p>"
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
"internal": "Er is een interne serverfout opgetreden."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using SlpModularCms.Core.Texts;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -101,10 +102,10 @@ public class AuthController : ControllerBase
|
||||
|
||||
var email = request?.Email?.Trim();
|
||||
if (!EmailAddressRules.IsValidAddress(email))
|
||||
return BadRequest(new { code = "invalid_email", detail = "Enter a valid e-mail address." });
|
||||
return BadRequest(new { code = "invalid_email", detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Auth.InvalidEmail) });
|
||||
|
||||
_dispatcher.Dispatch(email!);
|
||||
return Accepted(new { message = "If this address belongs to an account, an e-mail with a link has been sent." });
|
||||
return Accepted(new { message = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Auth.ResetRequested) });
|
||||
}
|
||||
|
||||
/// <summary>Anonymous. Sets a new password with the link from the mail; only a completed reset ends sessions.</summary>
|
||||
@@ -118,14 +119,14 @@ public class AuthController : ControllerBase
|
||||
if (request is null || request.UserId == Guid.Empty
|
||||
|| string.IsNullOrWhiteSpace(request.Token) || request.Token.Length > 2048
|
||||
|| string.IsNullOrEmpty(request.NewPassword) || request.NewPassword.Length > 128)
|
||||
return BadRequest(new { code = "invalid_link", detail = "This link is invalid or has expired." });
|
||||
return BadRequest(new { code = "invalid_link", detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Auth.LinkInvalid) });
|
||||
|
||||
var result = await _passwordReset.ResetAsync(request.UserId, request.Token, request.NewPassword, ct);
|
||||
return result.Status switch
|
||||
{
|
||||
PasswordResetStatus.Succeeded => Ok(new { message = "Password set. You can sign in now." }),
|
||||
PasswordResetStatus.PasswordRejected => BadRequest(new { code = "password_rejected", detail = "The password does not meet the requirements.", problems = result.Problems }),
|
||||
_ => BadRequest(new { code = "invalid_link", detail = "This link is invalid or has expired." })
|
||||
PasswordResetStatus.Succeeded => Ok(new { message = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Auth.PasswordSet) }),
|
||||
PasswordResetStatus.PasswordRejected => BadRequest(new { code = "password_rejected", detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Auth.PasswordRejected), problems = result.Problems }),
|
||||
_ => BadRequest(new { code = "invalid_link", detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Auth.LinkInvalid) })
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using SlpModularCms.Core.Texts;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
@@ -105,7 +106,7 @@ public class UsersController : ControllerBase
|
||||
{
|
||||
var existing = await _userManager.FindByEmailAsync(request.Email);
|
||||
if (existing is not null)
|
||||
return BadRequest(new { detail = "Email is already in use." });
|
||||
return BadRequest(new { detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Users.EmailInUse) });
|
||||
}
|
||||
|
||||
// null = leave the preference alone (older clients); "" = clear it (use the site default);
|
||||
@@ -117,7 +118,7 @@ public class UsersController : ControllerBase
|
||||
else if (MailLanguages.Normalize(request.Language) is { } language)
|
||||
user.PreferredLanguage = language;
|
||||
else
|
||||
return BadRequest(new { detail = "Unsupported language." });
|
||||
return BadRequest(new { detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Users.UnsupportedLanguage) });
|
||||
}
|
||||
|
||||
user.DisplayName = request.Name;
|
||||
@@ -128,7 +129,7 @@ public class UsersController : ControllerBase
|
||||
|
||||
var result = await _userManager.UpdateAsync(user);
|
||||
if (!result.Succeeded)
|
||||
return StatusCode(500, new { detail = "Failed to update profile." });
|
||||
return StatusCode(500, new { detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Users.UpdateProfileFailed) });
|
||||
|
||||
var roles = await _userManager.GetRolesAsync(user);
|
||||
var role = roles.FirstOrDefault() ?? "User";
|
||||
@@ -154,7 +155,7 @@ public class UsersController : ControllerBase
|
||||
return Forbid();
|
||||
|
||||
if (!string.IsNullOrEmpty(request.Language) && !MailLanguages.IsSupported(request.Language))
|
||||
return BadRequest(new { detail = "Unsupported language." });
|
||||
return BadRequest(new { detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Users.UnsupportedLanguage) });
|
||||
|
||||
var token = await _invitationService.CreateInvitationAsync(request.Email, request.Role, request.Language);
|
||||
var inviteLink = $"/invite/complete?token={Uri.EscapeDataString(token)}";
|
||||
@@ -249,7 +250,7 @@ public class UsersController : ControllerBase
|
||||
{
|
||||
var ownerCount = (await _userManager.GetUsersInRoleAsync("Owner")).Count;
|
||||
if (ownerCount <= 1)
|
||||
return BadRequest(new { detail = "At least one Owner must remain." });
|
||||
return BadRequest(new { detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Users.LastOwner) });
|
||||
}
|
||||
|
||||
if (targetRoles.Count > 0)
|
||||
@@ -277,7 +278,7 @@ public class UsersController : ControllerBase
|
||||
if (target is null) return NotFound();
|
||||
|
||||
if (IsSelf(target))
|
||||
return BadRequest(new { detail = "You cannot change your own active status." });
|
||||
return BadRequest(new { detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Users.CannotChangeOwnActive) });
|
||||
|
||||
var targetRoles = await _userManager.GetRolesAsync(target);
|
||||
var targetRole = targetRoles.FirstOrDefault() ?? "User";
|
||||
@@ -288,14 +289,14 @@ public class UsersController : ControllerBase
|
||||
{
|
||||
var ownerCount = (await _userManager.GetUsersInRoleAsync("Owner")).Count;
|
||||
if (ownerCount <= 1)
|
||||
return BadRequest(new { detail = "At least one Owner must remain." });
|
||||
return BadRequest(new { detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Users.LastOwner) });
|
||||
}
|
||||
|
||||
var wasActive = target.IsActive;
|
||||
target.IsActive = request.IsActive;
|
||||
var result = await _userManager.UpdateAsync(target);
|
||||
if (!result.Succeeded)
|
||||
return StatusCode(500, new { detail = "Failed to update user." });
|
||||
return StatusCode(500, new { detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Users.UpdateUserFailed) });
|
||||
|
||||
// A notice only on a real change; a mail failure never fails the action.
|
||||
if (wasActive != request.IsActive)
|
||||
@@ -324,7 +325,7 @@ public class UsersController : ControllerBase
|
||||
}
|
||||
|
||||
if (IsSelf(target))
|
||||
return BadRequest(new { detail = "You cannot delete your own account." });
|
||||
return BadRequest(new { detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Users.CannotDeleteSelf) });
|
||||
|
||||
var targetRoles = await _userManager.GetRolesAsync(target);
|
||||
if (!UserManagementRules.CanManage(await GetRequesterRoleAsync(), targetRoles.FirstOrDefault() ?? "User"))
|
||||
@@ -334,14 +335,14 @@ public class UsersController : ControllerBase
|
||||
{
|
||||
var ownerCount = (await _userManager.GetUsersInRoleAsync("Owner")).Count;
|
||||
if (ownerCount <= 1)
|
||||
return BadRequest(new { detail = "At least one Owner must remain." });
|
||||
return BadRequest(new { detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Users.LastOwner) });
|
||||
}
|
||||
|
||||
await _invitationService.DeleteInvitationsByEmailAsync(target.Email ?? string.Empty);
|
||||
|
||||
var result = await _userManager.DeleteAsync(target);
|
||||
if (!result.Succeeded)
|
||||
return StatusCode(500, new { detail = "Failed to delete user." });
|
||||
return StatusCode(500, new { detail = HttpTexts.From(HttpContext).Get(CoreTexts.Identity.Users.DeleteUserFailed) });
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user