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:
Cauê Faleiros
2026-10-13 11:48:24 -03:00
parent 86507ed7b5
commit 3664fe827e
35 changed files with 834 additions and 52 deletions

View File

@@ -16,6 +16,7 @@ from uuid import UUID, uuid4
from psycopg.types.json import Jsonb
from . import mail
from .core.auth import audit
from .printjobs import queue as queue_print_files
from .runtime import enqueue, upload_row
@@ -102,6 +103,8 @@ def create_order(c, quote, payment):
enqueue(c, f"{order['id']}:paid:{provider}", provider,
{'order_id': str(order['id']), 'number': order['number'],
'event': 'payment_approved', 'order': approved})
mail.alert(c, f"Pedido #{order['number']} pago · {mail.money(approved['total_cents'])}",
['Um pedido novo foi pago e está em Arte recebida.', '', *mail.summary(approved)], '/')
return order, True
@@ -120,8 +123,19 @@ def apply(c, event):
Outcomes starting 'refused' (money arrived, no order) or 'attention' (an
order exists but its payment was reversed) stay on the Kanban until an
operator records a resolution.
operator records a resolution, and the team is told by e-mail.
"""
outcome = _apply(c, event)
if outcome.startswith(('refused', 'attention')):
paid = mail.money(event.amount_cents) if type(event.amount_cents) is int else 'valor não informado'
mail.alert(c, f'Pagamento precisa de atenção · {paid}',
['O Mercado Pago avisou de um pagamento que não virou pedido, ou que foi estornado depois.',
'Abra Pagamentos no Kanban para ver o que aconteceu e registrar a resolução.', '',
f'Situação: {event.status} · cotação {event.reference or "—"}', f'Registro: {outcome}'], '/')
return outcome
def _apply(c, event):
provider_id = event.raw.get('payment_id')
if provider_id:
c.execute('''UPDATE dtf_local.payment_intents SET status=%s, updated_at=now()