feat: app de alumnos sin contraseña (invitación de un solo uso, avisos de falta y pagos informados)
- Acceso del alumno o tutor con link de un solo uso (hash SHA-256, consumo atómico, el GET no consume), sesión propia de 90 días deslizante, passkeys opcionales (SimpleWebAuthn) y mail de recuperación con rate limit. - Lado alumno (/i/:token, /acceso, /alumno/*): inicio, clases, avisar falta, pagos, informar pago con comprobante (S3 privado, magic bytes) y perfil. - Lado profe: acceso a la app en la ficha del alumno (invitar/reinvitar), "Pagos para verificar" en Cobros con badge, faltas avisadas en la ficha de grupo y datos para transferir en Ajustes. - "Requiere atención" y el recordatorio de WhatsApp excluyen cuotas informadas. - Zona horaria por defecto: Buenos Aires. - Migración add_student_access, tests contra Postgres real (test:db) y docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,15 @@ import nodemailer, { type Transporter } from 'nodemailer'
|
||||
type VerificationEmailData = { email: string; url: string; name?: string }
|
||||
type PasswordResetEmailData = { email: string; url: string; name?: string }
|
||||
type InvitationEmailData = { email: string; url: string; organizationName: string }
|
||||
type StudentEmailConfirmationData = { email: string; url: string; name: string }
|
||||
type StudentRecoveryEmailData = { email: string; links: { name: string; url: string }[] }
|
||||
type StudentPaymentReviewedData = {
|
||||
email: string
|
||||
name: string
|
||||
confirmed: boolean
|
||||
amount: string
|
||||
reason?: string | null
|
||||
}
|
||||
|
||||
// Brand colors (same system as the web app: index.css in apps/web).
|
||||
const BRAND_600 = '#2544ea'
|
||||
@@ -26,10 +35,27 @@ function loadLogoTypoDataUri(): string {
|
||||
|
||||
const LOGO_DATA_URI = loadLogoTypoDataUri()
|
||||
|
||||
interface EmailProvider {
|
||||
export interface EmailProvider {
|
||||
sendVerificationEmail(data: VerificationEmailData): Promise<void>
|
||||
sendPasswordResetEmail(data: PasswordResetEmailData): Promise<void>
|
||||
sendOrganizationInvitation(data: InvitationEmailData): Promise<void>
|
||||
sendStudentEmailConfirmation(data: StudentEmailConfirmationData): Promise<void>
|
||||
sendStudentRecoveryLinks(data: StudentRecoveryEmailData): Promise<void>
|
||||
sendStudentPaymentReviewed(data: StudentPaymentReviewedData): Promise<void>
|
||||
}
|
||||
|
||||
// Names come from what teachers and students type: never raw into the HTML.
|
||||
function escapeHtml(value: string): string {
|
||||
return value
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
}
|
||||
|
||||
function button(url: string, label: string): string {
|
||||
return `<a href="${escapeHtml(url)}" style="display:inline-block;background:${LINK_BG};color:${ON_ACCENT};text-decoration:none;padding:12px 24px;border-radius:12px;font-weight:600;">${escapeHtml(label)}</a>`
|
||||
}
|
||||
|
||||
class SMTPEmailProvider implements EmailProvider {
|
||||
@@ -109,6 +135,47 @@ class SMTPEmailProvider implements EmailProvider {
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
async sendStudentEmailConfirmation({ email, url, name }: StudentEmailConfirmationData) {
|
||||
await this.send(
|
||||
email,
|
||||
'Confirmá tu mail de recuperación en Gruperly',
|
||||
this.layout(
|
||||
'Confirmá tu mail',
|
||||
`Hola ${escapeHtml(name)}, confirmá este mail para poder pedir un link de ingreso si perdés el acceso a la app (el enlace vence en 24 horas). Si no fuiste vos, ignorá este mail.<br/><br/>${button(url, 'Confirmar mail')}`,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
async sendStudentRecoveryLinks({ email, links }: StudentRecoveryEmailData) {
|
||||
// A guardian may have one account per child with the same email: one button each.
|
||||
const buttons = links
|
||||
.map((link) =>
|
||||
links.length > 1
|
||||
? `<p style="margin:12px 0 4px;">${escapeHtml(link.name)}</p>${button(link.url, 'Ingresar')}`
|
||||
: button(link.url, 'Ingresar'),
|
||||
)
|
||||
.join('<br/>')
|
||||
await this.send(
|
||||
email,
|
||||
'Tu link para ingresar a Gruperly',
|
||||
this.layout(
|
||||
'Tu link de ingreso',
|
||||
`Pediste un link para volver a entrar. Sirve una sola vez y vence en 15 minutos. Si no fuiste vos, ignorá este mail.<br/><br/>${buttons}`,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
async sendStudentPaymentReviewed({ email, name, confirmed, amount, reason }: StudentPaymentReviewedData) {
|
||||
const body = confirmed
|
||||
? `Hola ${escapeHtml(name)}, tu profe confirmó el pago de ${escapeHtml(amount)}. ¡Gracias!`
|
||||
: `Hola ${escapeHtml(name)}, tu profe no pudo confirmar el pago de ${escapeHtml(amount)}.${reason ? `<br/><br/>Motivo: ${escapeHtml(reason)}` : ''}<br/><br/>Podés volver a informarlo desde la app.`
|
||||
await this.send(
|
||||
email,
|
||||
confirmed ? 'Tu pago fue confirmado' : 'Tu pago no fue confirmado',
|
||||
this.layout(confirmed ? 'Pago confirmado' : 'Pago rechazado', body),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Future: transactional providers (Resend, SendGrid, Postmark).
|
||||
|
||||
Reference in New Issue
Block a user