Project

General

Profile

Sub-Task #184

Updated by Bricklou 24 days ago

Server side of the reset request (#183). 

 **Endpoint** 
 - `POST /api/v1/authentication/forgot-password`, body `{ email }`. 
 - Always answers 202 with a `MessageResponse`, whether the account exists or not. 
 - Rate limited: 3 requests per hour per email (lowercased), plus the per-IP login limiter. 429 with `Retry-After` when exceeded. 

 **Flow** 
 - The route publishes a `PasswordResetRequested { email }` event and returns. The token never travels on the event bus. 
 - The worker looks the user up by email. It sends a mail only if the account has a password and a verified email; otherwise it does nothing. 
 - Token: 32 random bytes, base64url. Only its SHA-256 hash is stored. 
 - Table `password_resets`: `user_id` (PK, FK to users, cascade), `token_hash` (unique), `created_at`, `expires_at`. One row per user: a new request deletes the previous one in the same transaction. 
 - Link: `{base_url}/auth/reset-password#token=...` (fragment, not query string). 
 - Template `password_reset.mjml`, same layout as `email_verification.mjml`. 
 - A failed send returns an error so the bus retries. 

 **Implementation** 
 - New feature `features/password_reset/`, same layout as `features/email_verification/` (db, service, events, event_handlers, mail, error). Handlers registered in `worker/register.rs`. 
 - Migration and entity through the `db-migration` skill. 
 - OpenAPI response schemas through the `openapi-response-schema` skill. 

 **Tests** 
 - Service: token issued, previous token replaced, no token for unknown email, no password, or unverified email. 
 - Route: same 202 for known and unknown emails, 429 after the limit. 
 - Mail: recording sender receives one mail with the link.

Back