f332fc39ca
- lib/mail.ts: transporte SMTP (nodemailer, mismas creds Gmail que Django). - lib/register.ts: registerAccount (valida, comprueba email existente, crea fila en home_accountactivation reutilizando la tabla de Django, envía email de activación); activateAccount (crea battlenet_accounts con SRP6 v2 + account con SRP6 Grunt, como activate_account_view: expansion=2, battlenet_index=1; borra la activación). - Route handlers /api/auth/register y /api/auth/activate. - Páginas app/[locale]/register (RegisterForm cliente) y app/[locale]/activate-account (ActivateClient auto-POST al abrir el enlace). Textos en messages (Register, Activate). Validado: validaciones (missingFields/passwordMismatch/invalidEmail/passwordTooLong); ciclo completo activación->crea bnet+account->login OK con la cuenta creada (needsSelection=false), password mala->invalidCredentials. Todo en TS, crypto validada. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
35 lines
942 B
TypeScript
35 lines
942 B
TypeScript
import nodemailer from 'nodemailer'
|
|
|
|
// Transporte SMTP (mismas credenciales que usaba Django: Gmail por defecto).
|
|
let transporter: nodemailer.Transporter | null = null
|
|
|
|
function getTransporter(): nodemailer.Transporter {
|
|
if (!transporter) {
|
|
transporter = nodemailer.createTransport({
|
|
host: process.env.EMAIL_HOST,
|
|
port: Number(process.env.EMAIL_PORT || 587),
|
|
secure: process.env.EMAIL_USE_SSL === 'True', // true para 465, false para 587 (STARTTLS)
|
|
auth: {
|
|
user: process.env.EMAIL_HOST_USER,
|
|
pass: process.env.EMAIL_HOST_PASSWORD,
|
|
},
|
|
})
|
|
}
|
|
return transporter
|
|
}
|
|
|
|
export async function sendMail(to: string, subject: string, html: string): Promise<boolean> {
|
|
try {
|
|
await getTransporter().sendMail({
|
|
from: process.env.EMAIL_HOST_USER,
|
|
to,
|
|
subject,
|
|
html,
|
|
})
|
|
return true
|
|
} catch (e) {
|
|
console.error('sendMail error:', e)
|
|
return false
|
|
}
|
|
}
|