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:
@@ -31,6 +31,7 @@ button:disabled{opacity:.6;cursor:default}
|
||||
.bloco input.codigo{height:60px;font-size:30px;font-weight:700;letter-spacing:.45em;text-align:center;font-variant-numeric:tabular-nums;padding-left:.45em}
|
||||
.codigoAcoes{display:flex;flex-wrap:wrap;gap:4px 22px}
|
||||
#fCodigo{max-width:520px}
|
||||
#fEmailCodigo input.codigo{max-width:340px}
|
||||
.nota2 a{color:var(--laranja-escuro)}
|
||||
.bloco label{margin:10px 0 5px;font-size:14px;font-weight:600;color:var(--texto2)}
|
||||
.bloco label .obs{font-weight:400;color:var(--fraco)}
|
||||
|
||||
@@ -166,7 +166,20 @@
|
||||
<h2>E-mail</h2>
|
||||
<label for="dMail">E-mail</label><input id="dMail" type="email" autocomplete="email" required>
|
||||
<label for="dMailSenha">Senha atual, para confirmar</label><input id="dMailSenha" type="password" autocomplete="current-password" required>
|
||||
<button class="bSec">Alterar e-mail</button>
|
||||
<button class="bSec" id="dMailOk">Alterar e-mail</button>
|
||||
</form>
|
||||
<!-- Takes the place of the e-mail form until the new address is confirmed. -->
|
||||
<form class="bloco" id="fEmailCodigo" hidden>
|
||||
<h2>Confirme o novo e-mail</h2>
|
||||
<p class="nota2">Enviamos um código de 6 números para <b id="emailNovo"></b>. O e-mail da conta só muda depois que você digitar o código.</p>
|
||||
<label for="emailCodigo">Código</label>
|
||||
<input id="emailCodigo" class="codigo" inputmode="numeric" autocomplete="one-time-code" pattern="[0-9]{6}" maxlength="6" required>
|
||||
<button class="bSec" id="emailCodigoOk">Confirmar novo e-mail</button>
|
||||
<div class="codigoAcoes">
|
||||
<button type="button" class="bLink" id="emailReenviar" disabled>Reenviar código</button>
|
||||
<button type="button" class="bLink" id="emailCancelar">Cancelar</button>
|
||||
</div>
|
||||
<p class="nota2">Não chegou? Confira a caixa de spam.</p>
|
||||
</form>
|
||||
<form class="bloco" id="fSenha">
|
||||
<h2>Senha</h2>
|
||||
|
||||
@@ -310,12 +310,51 @@ $('fPerfil').onsubmit=async event=>{
|
||||
conta=r.customer;aviso('Dados salvos.');
|
||||
}catch(e){aviso(e.status===422?(algum?'Confira o WhatsApp e o endereço: todos os campos, menos o complemento, são necessários.':'Confira o WhatsApp.'):e.message,true);}
|
||||
};
|
||||
// A new e-mail is confirmed with the code sent to it before the account changes.
|
||||
let troca=null, trocaTimer=null;
|
||||
function emailTrocado(r){
|
||||
conta=r.customer;$('quem').textContent=conta.mail;$('dMail').value=conta.mail;
|
||||
fechaTroca();aviso('E-mail alterado. Use o novo e-mail para entrar.');
|
||||
}
|
||||
function fechaTroca(){
|
||||
clearInterval(trocaTimer);troca=null;$('fEmailCodigo').hidden=true;$('fEmail').hidden=false;
|
||||
}
|
||||
function trocaContagem(segundos){
|
||||
clearInterval(trocaTimer);
|
||||
const b=$('emailReenviar');let falta=segundos;
|
||||
const pinta=()=>{b.disabled=falta>0;b.textContent=falta>0?'Reenviar código ('+falta+' s)':'Reenviar código';};
|
||||
pinta();trocaTimer=setInterval(()=>{falta--;pinta();if(falta<=0)clearInterval(trocaTimer);},1000);
|
||||
}
|
||||
$('fEmail').onsubmit=async event=>{
|
||||
event.preventDefault();
|
||||
try{const r=await api('/account/email',{email:$('dMail').value,password:$('dMailSenha').value});
|
||||
conta=r.customer;$('dMailSenha').value='';$('quem').textContent=conta.mail;aviso('E-mail alterado. Use o novo e-mail para entrar.');}
|
||||
catch(e){aviso(e.status===422?'Confira o e-mail.':e.message,true);}
|
||||
event.preventDefault();$('dMailOk').disabled=true;
|
||||
try{
|
||||
const r=await api('/account/email',{email:$('dMail').value,password:$('dMailSenha').value});
|
||||
$('dMailSenha').value='';
|
||||
if(!r.verify){emailTrocado(r);return;}
|
||||
troca=r.verify;$('emailNovo').textContent=r.email;$('emailCodigo').value='';
|
||||
$('fEmail').hidden=true;$('fEmailCodigo').hidden=false;aviso('');trocaContagem(r.resend_seconds);$('emailCodigo').focus();
|
||||
}catch(e){aviso(e.status===422&&!e.message.startsWith('Este')?'Confira o e-mail.':e.message,true);}
|
||||
finally{$('dMailOk').disabled=false;}
|
||||
};
|
||||
$('emailCodigo').addEventListener('input',e=>{
|
||||
e.target.value=e.target.value.replace(/\D/g,'').slice(0,6);
|
||||
if(e.target.value.length===6&&!$('emailCodigoOk').disabled)$('fEmailCodigo').requestSubmit();
|
||||
});
|
||||
$('fEmailCodigo').onsubmit=async event=>{
|
||||
event.preventDefault();$('emailCodigoOk').disabled=true;
|
||||
try{emailTrocado(await api('/account/email/verify',{change:troca,code:$('emailCodigo').value}));}
|
||||
catch(e){
|
||||
aviso(e.status===422?'O código tem 6 números.':e.message,true);$('emailCodigo').select();
|
||||
if(e.status===410||e.status===429){$('emailReenviar').disabled=false;$('emailReenviar').textContent='Reenviar código';clearInterval(trocaTimer);}
|
||||
}finally{$('emailCodigoOk').disabled=false;}
|
||||
};
|
||||
$('emailReenviar').onclick=async()=>{
|
||||
$('emailReenviar').disabled=true;
|
||||
try{const r=await api('/account/email/resend',{change:troca});aviso('Enviamos um código novo para '+$('emailNovo').textContent+'.');
|
||||
trocaContagem(r.resend_seconds);$('emailCodigo').value='';$('emailCodigo').focus();}
|
||||
catch(e){aviso(e.message,true);if(e.status===410)fechaTroca();else $('emailReenviar').disabled=false;}
|
||||
};
|
||||
$('emailCancelar').onclick=()=>{aviso('');$('dMail').value=conta.mail;fechaTroca();};
|
||||
$('fSenha').onsubmit=async event=>{
|
||||
event.preventDefault();
|
||||
try{await api('/account/password',{current:$('dAtual').value,new:$('dNova').value});
|
||||
|
||||
Reference in New Issue
Block a user