Sub-Task #187
Updated by Bricklou 24 days ago
Server side of the password reset (#186).
**Endpoint**
- `POST /api/v1/authentication/reset-password`, body `{ token, password, confirm_password }`.
- 200 `MessageResponse` on success. 410 for an invalid token (see #185). 422 when the password breaks the security policy or the confirmation differs. 429 on the shared limiter.
**Service `reset(db, bus, token, password, now)`**
- Validates the password with the existing security policy and the confirmation, then hashes it with the existing `PasswordHasher`.
- In one transaction: consume the token, update the password hash, delete all sessions of the user (`delete_by_user(txn, id, None)`), write an audit row.
- After commit: publish `UserPasswordChanged`.
- Modeled on `user/service/password.rs` (`change_password`).
- MFA is not bypassed: the next sign-in still asks the second factor.
**Password changed mail**
- New handler on `UserPasswordChanged` sends `password_changed.mjml` (username, time, "if this was not you" text). Registered next to the other user mail handlers.
**Tests**
- Success: password changed, sessions gone, audit row written, event published, old password refused, new one accepted.
- Policy and confirmation errors keep the token usable.
- Token refused after use.
- Mail handler sends one mail on `UserPasswordChanged`.