4.5 KiB
Code summary - U2 identity-mail-flows
What was built
Data (migration AddLanguagePreference, additive, reversible): Users.PreferredLanguage (nullable, nl/en), Invitations.Language (nullable).
Core
IIdentityMailService/IdentityMailService: one orchestration point for invitation, new-link, deactivation, reactivation and role-change mails. Builds the link asApp:PublicBaseUrl + /admin + path, resolves the language (user preference, else the invitation's, elseApp:DefaultLanguage, else nl), takes the sender and name from the site settings, logo and colour from config, renders, sends, logs only kind and recipient domain, and never throws (a failure is aMailSendResult). Returnsdisabledwhen the site has no SMTP host.InvitationService: language stored normalised on the invitation and copied to the new account'sPreferredLanguageon completion.- D2: the security stamp is a claim of the access token (
AuthService) and is compared inActiveUserTokenValidation. A password change or reset changes the stamp, so every access token issued before it is refused; a token without the claim (issued before this release) is refused once; the refresh token silently issues a new one that carries the claim. UserResponse/UserDtocarryLanguage.
Identity module (UsersController)
POST Users/inviteacceptslanguage, sends the mail, returns{ inviteLink, mail }(the invitation exists whatever happens to the mail).POST Users/{id}/regenerate-invitenow also mails the new link. NewPOST Users/{id}/resend-invite: resends the current link, or creates a new one first when expired.mailis{ sent, error }, or null on a site without mail. Same role-hierarchy rules as the other invitation actions.- Deactivate, reactivate and role change send a notice only on a real change (and not for invitations); a failure never fails the action.
PUT Users/meacceptslanguage(null = unchanged, "" = clear, nl/en, anything else 400).
Frontend: language select in the profile (applied immediately; clearing falls back to the site default), the saved language is applied at sign-in and on the first silent refresh after a page load (not on later refreshes, so a temporary top-bar switch survives); invite dialog gets a language select (default = site language) and shows "mail sent to X" or a failure with a short reason next to the copyable link; users list gets "Uitnodiging opnieuw mailen" and the regenerate action reports the mail result; everything mail-related is hidden when the site has no mail (emailEnabled false).
Tests
- Core.Tests 478:
IdentityMailServiceTests(link, sender, logo, lifetime, language chain, disabled, failure value, exceptions never escape, notices, role names,BuildLink), invitation language (normalised, unsupported ignored, copied to the account), D2 (DeactivatedUserAccessTests: stamp change ends tokens for GET and POST, missing and wrong stamp refused;SessionEndsOnPasswordChangeTests: real Identity password change with real tokens, the old access token is refused, the refresh token gives a working new one, login response carries the language). MariaDB-backed migration test now covers both new migrations up, down, up (verified on a real MariaDB container). - Identity.Tests 115:
UsersControllerMailTests(invite with language and result, failure still succeeds, no mail result without mail, unsupported language, regenerate/resend including expired and failed, hierarchy, notices only on real change, notice failure never fails the action, role change of an invitation sends nothing, profile language set/clear/unchanged/invalid, list shows languages). - Frontend 345: invite dialog (no language field without mail, default site language, chosen language sent, sent/failed/no mail line), resend (hidden without mail, success, failure hands over the link, expired), profile language, language applied at sign-in or left alone. ESLint and tsc clean; asf build ok.
Behaviour change for SlpSoftware (and every host)
- After deploy, access tokens issued before it lack the stamp and are refused once; the silent refresh issues a new one (users stay signed in). 2. A password change now ends earlier access tokens immediately (refresh tokens are not revoked by a plain password change; only the reset flow in U3 revokes them). 3. Two nullable columns are added by migration. 4. Mail only when
Email:Smtp:Hostis set; otherwise nothing changes (the newlanguagefield of the invite request is ignored when mail is off in the UI).