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:
@@ -884,7 +884,7 @@ function itemCard(order,item,index){
|
||||
const spec=item.production;
|
||||
const title=node('div',undefined,'title');title.append(node('b',PRODUCT[item.mode]),gradePill(item.grade),node('span',metres(item.billed_metres),'mono'));
|
||||
body.append(title,facts([['Folha',sheetSize(spec)],['Peças',spec?String(spec.placements.length):null],
|
||||
['Metro',item.unit_cents?money(item.unit_cents):null],['Arquivos',spec&&spec.sources.length>1?String(spec.sources.length):null]]));
|
||||
['Metro',item.unit_cents?money(item.unit_cents)+manualExtra(item):null],['Arquivos',spec&&spec.sources.length>1?String(spec.sources.length):null]]));
|
||||
if(item.quality_status==='warning')body.append(badge('! Ressalva de resolução aceita','warn'));
|
||||
// After a customer correction, that file is the artwork: the generated
|
||||
// print file, or the reason it could not be made, no longer applies.
|
||||
@@ -991,7 +991,7 @@ function renderUsers(){
|
||||
const machineName=id=>machines.find(m=>m.id===id)?.name||'—';
|
||||
const rows=users.map(u=>{
|
||||
const tr=node('tr');if(!u.active)tr.classList.add('off');
|
||||
const who=node('td');who.append(node('b',u.name||u.email),node('span',u.email,'faint block'));
|
||||
const who=node('td');who.append(node('b',u.name||u.email),node('span',u.email+(u.alerts?' · recebe alertas':''),'faint block'));
|
||||
const machinesTd=node('td',u.machines.length?u.machines.map(machineName).join(', '):(u.role==='operador'?'Todas':'—'));
|
||||
const seen=node('td',u.last_login_at?when(u.last_login_at):'nunca entrou','faint');
|
||||
const actions=node('td',undefined,'actions');
|
||||
@@ -1037,14 +1037,16 @@ function userForm(u){
|
||||
pass.required=!editing;pass.placeholder=editing?'Deixe em branco para manter':'12 caracteres ou mais';
|
||||
const active=node('input');active.type='checkbox';active.checked=u?u.active:true;active.disabled=u?.email===ME.email;
|
||||
const activeLabel=node('label',undefined,'check');activeLabel.append(active,'Ativo (pode entrar no Kanban)');
|
||||
const alerts=node('input');alerts.type='checkbox';alerts.checked=!!u?.alerts;
|
||||
const alertsLabel=node('label',undefined,'check');alertsLabel.append(alerts,'Receber alertas por e-mail (pedido pago, cotação para revisar, pagamento com problema)');
|
||||
const boxes=usersData.machines.map(m=>{const c=node('input');c.type='checkbox';c.value=m.id;c.checked=!!u?.machines.includes(m.id);
|
||||
const l=node('label',undefined,'check');l.append(c,m.name);return l;});
|
||||
const machinesField=node('div',undefined,'mfield');
|
||||
machinesField.append('Máquinas (só para operadores; nenhuma = todas)',...(boxes.length?boxes:[node('span','Nenhuma máquina cadastrada.','faint')]));
|
||||
const syncMachines=()=>{machinesField.hidden=role.value!=='operador';};role.onchange=syncMachines;syncMachines();
|
||||
dialog(editing?'Editar usuário':'Novo usuário',[field('Nome',name),field('E-mail',email),field('Perfil',role),
|
||||
field(editing?'Nova senha':'Senha inicial',pass),machinesField,activeLabel],async()=>{
|
||||
const body={name:name.value,email:email.value,role:role.value==='superadmin'?'admin':role.value,active:active.checked,
|
||||
field(editing?'Nova senha':'Senha inicial',pass),machinesField,activeLabel,alertsLabel],async()=>{
|
||||
const body={name:name.value,email:email.value,role:role.value==='superadmin'?'admin':role.value,active:active.checked,alerts:alerts.checked,
|
||||
machines:role.value==='operador'?boxes.map(l=>l.querySelector('input')).filter(c=>c.checked).map(c=>c.value):[],
|
||||
password:pass.value||null};
|
||||
await api(editing?'/users/'+u.id:'/users',body);
|
||||
@@ -1311,7 +1313,7 @@ function quoteItem(item,fields,priced){
|
||||
const title=node('div',undefined,'title');
|
||||
title.append(node('b',PRODUCT[item.mode]),gradePill(item.grade),...(priced?[node('span',money(priced.total_cents),'mono')]:[]));
|
||||
body.append(title,facts([['Folha',sheetSize(spec)],['Cobrado',priced?metres(priced.billed_metres):null],
|
||||
['Metro',priced?money(priced.unit_cents):null],['Peças',spec?String(spec.placements.length):null],
|
||||
['Metro',priced?money(priced.unit_cents)+manualExtra(priced):null],['Peças',spec?String(spec.placements.length):null],
|
||||
['Arquivos',spec?String(spec.sources.length):null]]));
|
||||
const chips=node('div',undefined,'flags');
|
||||
chips.append(item.quality_status==='ok'?badge('✓ Qualidade conferida','ok'):item.quality_status==='warning'?
|
||||
@@ -1330,6 +1332,9 @@ function quoteItem(item,fields,priced){
|
||||
body.append(buttons);box.append(preview,body);return box;
|
||||
}
|
||||
|
||||
// A finished sheet someone opens by hand pays this per metre on top (app/core/pricing.py).
|
||||
const manualExtra=item=>item?.manual_extra_cents?' (com '+money(item.manual_extra_cents)+' de arquivo manual)':'';
|
||||
|
||||
// ---- Payments and integrations ------------------------------------------
|
||||
|
||||
const tinyResult=new URLSearchParams(location.search).get('tiny');
|
||||
@@ -1561,6 +1566,7 @@ function renderIntegrations(){
|
||||
node('p',fr.box_cm?'A Jadlog cobra o maior entre o peso real e o cubado.':'Sem a caixa, a cotação usa só o peso real.')]})
|
||||
: integration({name:'Frete',state:'Não configurado',tone:'off',summary:'Somente retirada.'}));
|
||||
rows.push(integration({name:'WhatsApp',state:'Não configurado',tone:'off',summary:'Mensagens registradas, sem envio.'}));
|
||||
rows.push(mailRow(board.providers?.mail||{}));
|
||||
const bk=board.providers?.backup||{};
|
||||
const ontem=bk.last_ok&&Date.now()-new Date(bk.last_ok)<26*3600e3;
|
||||
const tam=bk.bytes?(bk.bytes<1048576?Math.max(1,Math.round(bk.bytes/1024))+' KB':(bk.bytes/1048576).toFixed(1).replace('.',',')+' MB'):'';
|
||||
@@ -1573,6 +1579,23 @@ function renderIntegrations(){
|
||||
$('integrations').replaceChildren(...rows);
|
||||
eventFilters();
|
||||
}
|
||||
// E-mail: customers' password recovery and the team's alerts (app/mail.py).
|
||||
function mailRow(m){
|
||||
const name='E-mail';
|
||||
if(m.adapter!=='smtp'&&m.adapter!=='log')return integration({name,state:'Não configurado',tone:'off',
|
||||
summary:'Sem recuperação de senha por e-mail: o cliente é orientado a chamar no WhatsApp.'});
|
||||
const local=m.adapter==='log';
|
||||
const who=m.alerts?m.alerts+(m.alerts>1?' pessoas recebem':' pessoa recebe')+' os alertas':'ninguém recebe os alertas ainda';
|
||||
return integration({name,state:m.error?'Verificar':local?'Só registro':'Ativo',tone:m.error?'warn':local?'off':'ok',
|
||||
summary:m.error?'Falhou o envio para '+m.error.to+': '+m.error.error:'Recuperação de senha e alertas · '+who+'.',
|
||||
actions:[button('Enviar teste',async()=>{const r=await api('/mail/test',{});
|
||||
say(local?'Teste registrado. Neste ambiente os e-mails ficam só no registro do servidor.':'Teste enviado para '+r.to+'. Confira a caixa de entrada (e o spam).');})],
|
||||
details:[...(local?[node('p','Ambiente local: os e-mails não saem do servidor, ficam no registro do worker.')]:[]),
|
||||
['Remetente',m.from||'—'],...(m.host?[['Servidor',m.host]]:[]),
|
||||
['Último envio',m.last_sent?when(m.last_sent):'Nenhum ainda'],['Na fila',String(m.pending||0)],
|
||||
...(m.error?[['Último erro',when(m.error.at)+' · '+m.error.error]]:[]),
|
||||
node('p','Quem recebe os alertas se escolhe em Usuários → Editar → “Receber alertas por e-mail”.')]});
|
||||
}
|
||||
function mercadoPagoCheck(r){
|
||||
const w=r.webhooks||{};
|
||||
return [['Credencial',r.token==='test'?'De teste':'De produção'],
|
||||
|
||||
Reference in New Issue
Block a user