feat(identity): confirm the email address with a six-digit code from the message

This commit is contained in:
shira committed 2026-10-10 00:52:46 +03:00
1 parent c94434cd09
commit d365a05c96
87 files changed
+4764 -224

No files matched your search

@@ -170,6 +170,41 @@ func (UnimplementedHandler) ConfirmEmail(ctx context.Context, req *EmailVerifica
return r, ht.ErrNotImplemented
}
// ConfirmEmailByCode implements ConfirmEmailByCode operation.
//
// Public operation without a session. The verification message carries a six-digit code next to the
// link. The client sends the address, the code, and the password chosen for the registration that
// issued the code, so the user types only the code after registration. A reloaded page has no password
// in memory, so it asks for the address, the password, and the code together.
//
// The server finds the newest open verification token of the unverified account with this normalized
// address, whose registration is current and which carries a code. It compares the keyed digest of the
// code with the stored digest, checks the password against the token's pending password hash, and
// checks that the code has not expired. The code lives 30 minutes, or until the token ends if the
// token ends sooner. When all three checks pass, the server consumes the token, verifies the email,
// and applies the pending credentials in one transaction, exactly as the link confirmation does, and
// answers 200 with the same body. Success does not start a session.
//
// Each refusal answers 400 `verification_token_invalid` with the same body, whatever the cause: an
// unknown address, an address without an open code, a wrong code, an expired code, a wrong password,
// or a code that was burned. This keeps the answer from showing which addresses have a pending
// registration. Every failed attempt of an open code counts against that token. The fifth failed
// attempt burns the token: the code and the link stop working, and the user must request a new
// message. A refused attempt changes nothing else.
//
// The same refusal is returned after the rate limits are checked. The operation is limited per client
// address (`IDENTITY_CLIENT_HOURLY_LIMIT`) and per normalized email
// (`IDENTITY_LOGIN_EMAIL_HOURLY_LIMIT`, shared with login); a refused request answers 429 with
// Retry-After. A body that does not match the contract, such as a code that is not six digits, answers
// 400 `validation_failed` before any lookup. Like every unsafe public identity operation, it requires
// an Origin equal to the configured public application origin and answers 403 `csrf_check_failed`
// otherwise.
//
// POST /api/v1/identity/email-verifications/code
func (UnimplementedHandler) ConfirmEmailByCode(ctx context.Context, req *EmailVerificationCodeRequest, params ConfirmEmailByCodeParams) (r ConfirmEmailByCodeRes, _ error) {
return r, ht.ErrNotImplemented
}
// CreateMyAssessmentAttempt implements CreateMyAssessmentAttempt operation.
//
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,