The API lets a signed-in user change their own e-mail address, at once or after confirming a link #66

Closed
opened 2026-10-31 12:42:00 -04:00 by claude · 0 comments
Owner
  • Draft: BUG-56
  • Priority: medium
  • Agent: coder
  • Depends on: #64, #65
  • Decisions: Q-BUG-13, Q-BUG-15, Q-BUG-16, R2-EMAIL-SIGNOUT

Why

See #63.

What changes

  • POST /api/users/me/email (UsersController, [Authorize]), body { newEmail, currentPassword }:
    • A wrong password gives 400 with Identity's PasswordMismatch, as ChangeMyPassword does. An invalid or taken address gives 400 with Identity's error.
    • Confirmation required (the default): SMTP (EmailSenderOptions.SmtpHost) and PublicBaseUrl must be configured, otherwise 400 naming what is missing (as the administrator's e-mailed reset does, UsersController.cs:517-530). It sends the link (#65) and returns 202 with { confirmationSent: true }. Nothing on the account changes yet.
    • Not required: the address changes at once (#63 rules), the security stamp is updated so every session ends, UserAccountChangedEvent is published, the notice goes to the old address when SMTP is configured, and the response is 200 with the profile.
  • POST /api/auth/confirm-email-change (anonymous, in AuthController next to ResetPassword, with the same rate limiting), body { userId, email, token }: UserManager.ChangeEmailAsync (which sets EmailConfirmed and the security stamp, so every session ends), then the event and the notice to the old address. A bad or expired token gives 400 without saying whether the user exists.
  • UserProfileDetail (GET /api/users/me) gains emailChangeRequiresConfirmation, so the console can say what will happen before the user submits.
  • /api/identity-settings GET and PATCH gain requireEmailChangeConfirmation, written through PresetConfigurationFileApplier like the controller's other sections (IdentitySettingsController.cs:64,71).
  • PatchMine keeps ignoring email; its summary points at the new action. Update the class summary at UsersController.cs:31-40.
  • Examples for every new request and response.
  • README account section.

Acceptance

  • Web.Tests, red first: with confirmation on (the default), the POST returns 202, the address is unchanged, and the captured link confirms the change; after it the address and EmailConfirmed are set, the old address got the notice, and an old access token gets 401.
  • With confirmation off, the POST changes the address at once; the old address gets the notice; the caller's own access token then gets 401.
  • Wrong password, taken address, missing SMTP or base URL, reused or tampered token: each gives 400.
  • PATCH /api/identity-settings {"requireEmailChangeConfirmation":false} then GET returns false; 403 without the write permission.
  • dotnet test src/dotnet/tests/Ninlil.Web.Tests passes except OpenApiSnapshotTests (#67, same PR); src/dotnet/tests/Ninlil.Dns.Server.ClusterSync.Tests passes.

Source

#63.
Owner decisions 2026-10-31, round 2: Q-BUG-15, Q-BUG-16, R2-EMAIL-SIGNOUT.

- **Draft:** BUG-56 - **Priority:** medium - **Agent:** coder - **Depends on:** #64, #65 - **Decisions:** Q-BUG-13, Q-BUG-15, Q-BUG-16, R2-EMAIL-SIGNOUT ### Why See #63. ### What changes - `POST /api/users/me/email` (`UsersController`, `[Authorize]`), body `{ newEmail, currentPassword }`: - A wrong password gives 400 with Identity's `PasswordMismatch`, as `ChangeMyPassword` does. An invalid or taken address gives 400 with Identity's error. - Confirmation required (the default): SMTP (`EmailSenderOptions.SmtpHost`) and `PublicBaseUrl` must be configured, otherwise 400 naming what is missing (as the administrator's e-mailed reset does, `UsersController.cs:517-530`). It sends the link (#65) and returns 202 with `{ confirmationSent: true }`. Nothing on the account changes yet. - Not required: the address changes at once (#63 rules), the security stamp is updated so every session ends, `UserAccountChangedEvent` is published, the notice goes to the old address when SMTP is configured, and the response is 200 with the profile. - `POST /api/auth/confirm-email-change` (anonymous, in `AuthController` next to `ResetPassword`, with the same rate limiting), body `{ userId, email, token }`: `UserManager.ChangeEmailAsync` (which sets `EmailConfirmed` and the security stamp, so every session ends), then the event and the notice to the old address. A bad or expired token gives 400 without saying whether the user exists. - `UserProfileDetail` (`GET /api/users/me`) gains `emailChangeRequiresConfirmation`, so the console can say what will happen before the user submits. - `/api/identity-settings` GET and PATCH gain `requireEmailChangeConfirmation`, written through `PresetConfigurationFileApplier` like the controller's other sections (`IdentitySettingsController.cs:64,71`). - `PatchMine` keeps ignoring `email`; its summary points at the new action. Update the class summary at `UsersController.cs:31-40`. - Examples for every new request and response. - README account section. ### Acceptance - [ ] Web.Tests, red first: with confirmation on (the default), the POST returns 202, the address is unchanged, and the captured link confirms the change; after it the address and `EmailConfirmed` are set, the old address got the notice, and an old access token gets 401. - [ ] With confirmation off, the POST changes the address at once; the old address gets the notice; the caller's own access token then gets 401. - [ ] Wrong password, taken address, missing SMTP or base URL, reused or tampered token: each gives 400. - [ ] PATCH `/api/identity-settings` `{"requireEmailChangeConfirmation":false}` then GET returns false; 403 without the write permission. - [ ] `dotnet test src/dotnet/tests/Ninlil.Web.Tests` passes except `OpenApiSnapshotTests` (#67, same PR); `src/dotnet/tests/Ninlil.Dns.Server.ClusterSync.Tests` passes. ### Source #63. Owner decisions 2026-10-31, round 2: Q-BUG-15, Q-BUG-16, R2-EMAIL-SIGNOUT.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#66
No description provided.