forked from Bitcoindefi/OpenAO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail.ts
More file actions
130 lines (119 loc) · 5.07 KB
/
Copy pathemail.ts
File metadata and controls
130 lines (119 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { SESv2Client, SendEmailCommand } from "@aws-sdk/client-sesv2";
import config from "../config";
type PasswordResetEmailInput = {
to: string;
displayName: string;
resetUrl: string;
};
let sesClient: SESv2Client | null = null;
function getSesClient(): SESv2Client {
if (!config.sesRegion || !config.sesAccessKeyId || !config.sesSecretAccessKey || !config.sesFromEmail) {
throw new Error("Amazon SES no esta configurado");
}
if (!sesClient) {
sesClient = new SESv2Client({
region: config.sesRegion,
credentials: {
accessKeyId: config.sesAccessKeyId,
secretAccessKey: config.sesSecretAccessKey,
},
});
}
return sesClient;
}
function escapeHtml(value: string): string {
return value
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/\"/g, """)
.replace(/'/g, "'");
}
function buildPasswordResetHtml({ displayName, resetUrl }: PasswordResetEmailInput): string {
const safeName = escapeHtml(displayName);
const safeUrl = escapeHtml(resetUrl);
return `
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Recuperar contraseña</title>
</head>
<body style="margin:0;padding:0;background:#09090b;font-family:Arial,sans-serif;color:#e7e5e4;">
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="background:radial-gradient(circle at top,#1f293755,transparent 35%),linear-gradient(180deg,#0c0a09,#111827);padding:32px 16px;">
<tr>
<td align="center">
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="max-width:620px;background:#111827;border:1px solid rgba(255,255,255,0.08);border-radius:28px;overflow:hidden;box-shadow:0 24px 80px rgba(0,0,0,0.45);">
<tr>
<td style="padding:28px 28px 20px;background:radial-gradient(circle at top,#f59e0b33,transparent 55%),linear-gradient(135deg,#1c1917,#0f172a);">
<div style="font-size:11px;letter-spacing:0.34em;text-transform:uppercase;color:#fde68a;opacity:0.85;">AOWeb</div>
<h1 style="margin:14px 0 8px;font-size:30px;line-height:1.2;color:#fafaf9;">Recupera tu acceso</h1>
<p style="margin:0;font-size:15px;line-height:1.7;color:#d6d3d1;">Hola ${safeName}, recibimos un pedido para cambiar la contraseña de tu cuenta.</p>
</td>
</tr>
<tr>
<td style="padding:28px;">
<p style="margin:0 0 18px;font-size:15px;line-height:1.7;color:#d6d3d1;">El enlace vence en 30 minutos y solo sirve una vez.</p>
<table role="presentation" cellspacing="0" cellpadding="0" style="margin:0 0 20px;">
<tr>
<td align="center" bgcolor="#fde68a" style="border-radius:16px;">
<a href="${safeUrl}" style="display:inline-block;padding:14px 22px;font-size:15px;font-weight:700;color:#111827;text-decoration:none;">Cambiar contraseña</a>
</td>
</tr>
</table>
<p style="margin:0 0 10px;font-size:13px;line-height:1.7;color:#a8a29e;">Si el boton no funciona, copia y pega este link en tu navegador:</p>
<p style="margin:0 0 20px;word-break:break-word;font-size:13px;line-height:1.7;color:#67e8f9;">${safeUrl}</p>
<div style="border-radius:18px;border:1px solid rgba(255,255,255,0.08);background:rgba(255,255,255,0.03);padding:16px;">
<p style="margin:0 0 8px;font-size:13px;font-weight:700;color:#fef3c7;">Seguridad</p>
<p style="margin:0;font-size:13px;line-height:1.7;color:#d6d3d1;">Si no fuiste vos, ignora este mensaje. Tu contraseña actual seguira funcionando hasta que completes el cambio.</p>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>`.trim();
}
function buildPasswordResetText({ displayName, resetUrl }: PasswordResetEmailInput): string {
return [
`Hola ${displayName},`,
"",
"Recibimos un pedido para cambiar la password de tu cuenta de AOWeb.",
"",
"Abre este link para elegir una nueva password:",
resetUrl,
"",
"El enlace vence en 30 minutos y solo se puede usar una vez.",
"Si no fuiste vos, ignora este email.",
].join("\n");
}
export async function sendPasswordResetEmail(input: PasswordResetEmailInput): Promise<void> {
const client = getSesClient();
await client.send(new SendEmailCommand({
FromEmailAddress: `${config.sesFromName} <${config.sesFromEmail}>`,
Destination: {
ToAddresses: [input.to],
},
Content: {
Simple: {
Subject: {
Data: "AOWeb | Recuperacion de contraseña",
Charset: "UTF-8",
},
Body: {
Html: {
Data: buildPasswordResetHtml(input),
Charset: "UTF-8",
},
Text: {
Data: buildPasswordResetText(input),
Charset: "UTF-8",
},
},
},
},
}));
}