feat: a new account e-mail is confirmed with a code, and the old one is told

Changing the e-mail in Dados da conta took effect at once, with nothing
checking the new address: a typo locked the customer out, and anyone at a
signed-in computer who knew the password could move the account to their own
e-mail and then reset its password. Now the code goes to the new address, the
account changes only once it is entered (same screen and limits as signup,
and only the account that asked can complete it), and the old address gets
"O e-mail da sua conta foi trocado", with the WhatsApp to call if it was not
them. Without e-mail on, it changes at once as before.

Signup and e-mail change share one code check (expiry, five attempts, the
60 s resend wait). Tested: mail_test (wrong password, same and taken e-mail,
wrong code, another account's attempt, resend wait, the notice), the full
suite in a CI-style stack, and the screen in Brave.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-14 16:32:46 -03:00
parent 95be624cca
commit 7383e44ff4
9 changed files with 217 additions and 39 deletions

View File

@@ -297,3 +297,15 @@ CREATE TABLE IF NOT EXISTS dtf_local.account_signups (
done_at timestamptz
);
CREATE INDEX IF NOT EXISTS account_signups_created ON dtf_local.account_signups(created_at);
-- A customer changing the account's e-mail: the change waits for the code sent
-- to the new address, as a signup does, and the old address is told.
CREATE TABLE IF NOT EXISTS dtf_local.email_changes (
id uuid PRIMARY KEY, account_id uuid NOT NULL REFERENCES dtf_local.accounts(id) ON DELETE CASCADE,
new_email text NOT NULL, code_hash text NOT NULL, created_at timestamptz NOT NULL DEFAULT now(),
sent_at timestamptz NOT NULL DEFAULT now(), expires_at timestamptz NOT NULL,
sends int NOT NULL DEFAULT 1, attempts int NOT NULL DEFAULT 0, done_at timestamptz
);
ALTER TABLE dtf_local.mail_queue DROP CONSTRAINT IF EXISTS mail_queue_kind_check;
ALTER TABLE dtf_local.mail_queue ADD CONSTRAINT mail_queue_kind_check
CHECK(kind IN ('reset','code','account','notice','alert','test'));