main ← captcha-before-login-code
With email-code signup, the CAPTCHA was shown only after the emailed code had be…en verified. Bots could therefore send login-code emails to any address without ever being challenged, which hurts email deliverability. The old signup flow challenged before sending any email. Reported on Meta: https://meta.discourse.org/t/418119
The CAPTCHA now sits on the email step, and `/session/login-code` refuses to send a code until it's solved.
**Server (`discourse-captcha`)**
- `create_login_code` verifies the CAPTCHA token before calling core. A successful solve is stored in the server session for that address (hashed) for an hour, along with the reCAPTCHA v3 score.
- Resending a code to the same address reuses that solve, and verifying the code and creating the account don't challenge again. The stored score is still recorded on the new user.
- Logins and signups are challenged alike, so the response doesn't reveal whether an address has an account.
- Invitations, password resets and API requests are not challenged, as before.
**Client**
- A new `request-login-code` behavior transformer wraps the request that sends the code. The CAPTCHA plugin uses it to attach the token, and skips it for invitations and resends.
- The CAPTCHA fields move from the `code-login-after-code` outlet to `code-login-email-step-fields`. They're hidden for invitations and password resets.
- `create-account` gets a `codeLogin` context, so the plugin doesn't ask for a second CAPTCHA on the details step of a code signup. Password signups are unchanged.
**Testing**
- Request specs cover a missing or rejected token sending no email, existing accounts being challenged too, the solve being reused for resends and signup but not for a different address, reCAPTCHA v3 scores carried through to the new user, and invitations skipping the challenge.
- System specs now expect the CAPTCHA before the email is sent and no second challenge afterwards.