feat: password recovery by e-mail, team alerts, and a price for files opened by hand
Pilot customers had no way to reset a forgotten password, and the 7 October meeting asked for two things that only needed the client's inputs to go live. Password recovery: "Esqueci minha senha" in Minha conta sends a link that works once, for an hour (/conta/redefinir#token, in the fragment so it never reaches a server or a Referer). Only the token's hash is stored, the e-mail's text is erased once sent, the answer never says whether an account exists, and a reset signs out every other session. Limited per address and source. Team alerts: Kanban users who tick "Receber alertas por e-mail" in Usuários get one when an order is paid, a cart waits for review, or a payment needs attention. Messages are queued in the transaction that caused them and sent by the worker with retries (app/mail.py). Integrações shows an E-mail row with "Enviar teste". E-mail is off in production (MAIL_ADAPTER=off; recovery keeps offering WhatsApp) until the client's SMTP account exists; then it is only settings (docs/PORTAINER.md). The local stack keeps messages in the database and log. Files opened by hand: a finished sheet in CDR, AI, PSD or TIFF (or with a length the customer typed) pays the full price plus MANUAL_FILE_EXTRA_CENTS per metre, to steer customers to PNG as the meeting asked. It is 0 until Marcus gives the amount. The Site shows it before checkout, the server charges it, Tiny gets it in the unit price, and the Kanban says it. Tested: new tests/mail_test (reset flow, SMTP delivery against a local SMTP server, retry, who gets alerts), pricing unit tests, and the browser test now checks the Site total equals the server's, run with the charge at 0 and at R$ 5,00. The full CI suite passes in a CI-style stack. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -42,6 +42,7 @@ function forgetCheckout(){for(const k of ['dtf-quote','dtf-request-key','dtf-req
|
||||
function vista(){
|
||||
const p=location.pathname.replace(/\/+$/,'');
|
||||
if(p==='/conta/entrar') return 'entrar';
|
||||
if(p==='/conta/redefinir') return 'redefinir';
|
||||
if(p==='/conta/dados') return 'dados';
|
||||
if(p==='/conta') return 'geral';
|
||||
return 'pedidos'; // /conta/pedidos, and the old /portal.html
|
||||
@@ -61,12 +62,14 @@ async function mostra(){
|
||||
if((v==='geral'||v==='dados')&&!conta){history.replaceState({},'','/conta/entrar?next='+encodeURIComponent(location.pathname));return mostra();}
|
||||
if(v==='entrar'&&conta){history.replaceState({},'',proximo&&/^\/conta(\/[a-z]+)?$/.test(proximo)?proximo:'/conta');return mostra();}
|
||||
$('auth').hidden=v!=='entrar';
|
||||
$('area').hidden=v==='entrar';
|
||||
$('redefinir').hidden=v!=='redefinir';
|
||||
$('area').hidden=v==='entrar'||v==='redefinir';
|
||||
if(v==='redefinir'&&!resetToken)aviso('Este link está incompleto. Peça outro em “Esqueci minha senha”.',true);
|
||||
$('vGeral').hidden=v!=='geral';$('vPedidos').hidden=v!=='pedidos';$('vDados').hidden=v!=='dados';
|
||||
for(const a of document.querySelectorAll('.lateral a'))a.classList.toggle('on',a.dataset.view===v);
|
||||
for(const a of document.querySelectorAll('.lateral [data-conta]'))a.hidden=!conta;
|
||||
$('navEntrar').hidden=!!conta;$('logout').hidden=!conta;
|
||||
document.title=({entrar:'Entrar',geral:'Minha conta',pedidos:'Pedidos',dados:'Dados da conta'})[v]+' · DTF Dropstar';
|
||||
document.title=({entrar:'Entrar',redefinir:'Criar nova senha',geral:'Minha conta',pedidos:'Pedidos',dados:'Dados da conta'})[v]+' · DTF Dropstar';
|
||||
if(v==='geral')await geral();
|
||||
else if(v==='pedidos')await pedidos();
|
||||
else if(v==='dados')dados();
|
||||
@@ -328,23 +331,51 @@ async function migrateGuestCart(previous,next){
|
||||
await new Promise((resolve,reject)=>{const tx=database.transaction('cart','readwrite'),store=tx.objectStore('cart'),req=store.get(previous);req.onsuccess=()=>{if(req.result){store.put(req.result,next);store.delete(previous);}};tx.oncomplete=resolve;tx.onerror=()=>reject(tx.error);});
|
||||
database.close();
|
||||
}
|
||||
async function authenticate(path,body){
|
||||
async function authenticate(path,body,destino){
|
||||
const previous=scope,guest=!conta;
|
||||
const r=await api(path,body);forgetCheckout();
|
||||
const next=(await api('/session')).cart_scope;scope=next;
|
||||
if(guest)try{await migrateGuestCart(previous,next);}catch{aviso('Não foi possível transferir o carrinho salvo neste navegador.',true);}
|
||||
conta=r.customer;$('quem').textContent=conta.mail;
|
||||
$('password').value='';$('register-password').value='';
|
||||
if(destino)history.replaceState({},'',destino);
|
||||
await mostra();
|
||||
}
|
||||
$('login').onsubmit=async event=>{event.preventDefault();try{await authenticate('/account/login',{email:$('email').value,password:$('password').value});}catch(e){aviso(e.message,true);}};
|
||||
$('register').onsubmit=async event=>{event.preventDefault();try{await authenticate('/account/register',{customer:{cnpj:$('cnpj').value,zap:$('phone').value,mail:$('register-email').value},password:$('register-password').value});}catch(e){aviso(e.status===422?'Confira o CNPJ, o WhatsApp e o e-mail. A senha precisa ter 12 caracteres ou mais.':e.message,true);}};
|
||||
$('esqueci').onclick=()=>{$('esqueciTx').hidden=!$('esqueciTx').hidden;};
|
||||
// Password recovery: a link by e-mail when the server sends e-mail,
|
||||
// otherwise the WhatsApp. The link arrives in the address's fragment.
|
||||
let recovery=false, resetToken='';
|
||||
if(location.pathname.replace(/\/+$/,'')==='/conta/redefinir'&&location.hash.length>1){
|
||||
resetToken=location.hash.slice(1);history.replaceState({},'','/conta/redefinir');
|
||||
}
|
||||
function esqueci(abrir){
|
||||
$('login').hidden=abrir;$('fEsqueci').hidden=!abrir;
|
||||
$('esqueciMailBox').hidden=!recovery;$('esqueciZap').hidden=recovery;
|
||||
if(abrir){$('esqueciMail').value=$('email').value;(recovery?$('esqueciMail'):$('voltarEntrar')).focus();}
|
||||
else $('email').focus();
|
||||
}
|
||||
$('esqueci').onclick=()=>esqueci(true);
|
||||
$('voltarEntrar').onclick=()=>{aviso('');esqueci(false);};
|
||||
$('fEsqueci').onsubmit=async event=>{
|
||||
event.preventDefault();$('esqueciEnviar').disabled=true;
|
||||
try{const r=await api('/account/forgot',{email:$('esqueciMail').value});aviso(r.message);}
|
||||
catch(e){aviso(e.status===422?'Confira o e-mail.':e.message,true);}
|
||||
finally{$('esqueciEnviar').disabled=false;}
|
||||
};
|
||||
$('fRedefinir').onsubmit=async event=>{
|
||||
event.preventDefault();
|
||||
if($('rNova').value!==$('rRepete').value){aviso('A nova senha e a repetição não conferem.',true);return;}
|
||||
try{await authenticate('/account/reset',{token:resetToken,password:$('rNova').value},'/conta');
|
||||
resetToken='';$('rNova').value='';$('rRepete').value='';aviso('Senha criada. Você já está na sua conta.');}
|
||||
catch(e){aviso(e.status===422?(resetToken?'A nova senha precisa ter 12 caracteres ou mais.':'Este link está incompleto. Peça outro em “Esqueci minha senha”.'):e.message,true);}
|
||||
};
|
||||
$('logout').onclick=async()=>{try{await window.dtfForgetPrivateData();await api('/account/logout',{});location.assign('/conta/entrar');}catch(error){aviso('Não foi possível limpar os dados deste navegador. Feche as abas do Site e limpe os dados do site nas configurações do navegador.',true);}};
|
||||
|
||||
(async()=>{
|
||||
try{
|
||||
const session=await api('/session');scope=session.cart_scope;environment=session.environment;
|
||||
recovery=!!session.password_recovery;
|
||||
$('dev-notice').hidden=environment!=='local';
|
||||
conta=(await api('/account/me')).customer;
|
||||
if(conta)$('quem').textContent=conta.mail;
|
||||
|
||||
Reference in New Issue
Block a user