feat(newsletter): implement sovereign double opt-in confirmation and welcome workflow
This commit is contained in:
1 parent
080faa5ffc
commit
9792a403cb
5 files changed
+566
-24
No files matched your search
@@ -0,0 +1,271 @@
|
||||
// Aira Corporate Email Templates
|
||||
// Aesthetic: Pure Corporate Luxury matching airaaigroup.in
|
||||
// Palette: Deep Royal Navy (#0a2342), Crisp Slate (#f1f5f9), Royal Blue (#1d4ed8), Pure White (#ffffff)
|
||||
|
||||
export function getConfirmationEmailHtml(name, confirmUrl) {
|
||||
const safeName = name ? escapeHtml(name) : "Colleague";
|
||||
const safeUrl = escapeHtml(confirmUrl);
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Confirm Your Subscription — Aira Group of Technology</title>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0; background-color: #f1f5f9; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; color: #0f172a;">
|
||||
<div style="display: none; font-size: 1px; color: #f1f5f9; line-height: 1px; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden;">
|
||||
Please verify your email address to complete your subscription to Aira Group Sovereign Engineering Dispatches.
|
||||
</div>
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: #f1f5f9;">
|
||||
<tr>
|
||||
<td align="center" style="padding: 40px 16px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 580px; background-color: #ffffff; border: 1px solid #e2e8f0; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 20px rgba(10, 35, 66, 0.05);">
|
||||
<!-- Top Header -->
|
||||
<tr>
|
||||
<td style="background-color: #0a2342; padding: 26px 32px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td>
|
||||
<div style="font-size: 20px; font-weight: 800; color: #ffffff; letter-spacing: -0.5px;">
|
||||
Aira<span style="color: #60a5fa;">Group</span>
|
||||
</div>
|
||||
<div style="font-size: 9px; font-weight: 700; color: #93c5fd; letter-spacing: 2px; text-transform: uppercase; margin-top: 3px;">
|
||||
TECHNOLOGY • SOVEREIGN ENGINEERING
|
||||
</div>
|
||||
</td>
|
||||
<td align="right">
|
||||
<span style="font-size: 11px; font-weight: 600; color: #cbd5e1; border: 1px solid rgba(255, 255, 255, 0.2); padding: 4px 10px; border-radius: 6px;">
|
||||
Verification
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Body -->
|
||||
<tr>
|
||||
<td style="padding: 36px 32px 28px;">
|
||||
<div style="font-size: 12px; font-weight: 700; color: #1d4ed8; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px;">
|
||||
SUBSCRIPTION CONFIRMATION
|
||||
</div>
|
||||
<h1 style="margin: 0 0 16px; font-size: 24px; font-weight: 800; color: #0a2342; line-height: 1.3;">
|
||||
Confirm Your Subscription to Aira Group Dispatches
|
||||
</h1>
|
||||
<p style="margin: 0 0 16px; font-size: 15px; line-height: 1.6; color: #334155;">
|
||||
Hello <strong>${safeName}</strong>,
|
||||
</p>
|
||||
<p style="margin: 0 0 20px; font-size: 15px; line-height: 1.6; color: #475569;">
|
||||
Thank you for requesting to join the official <strong>Aira Group of Technology</strong> engineering dispatch list. We publish verified deep-tech architectural analyses on sovereign AI models, bare-metal kernels, and cellular mesh communication directly from Founder & CEO Er. Adam Eehan.
|
||||
</p>
|
||||
<p style="margin: 0 0 28px; font-size: 15px; line-height: 1.6; color: #475569;">
|
||||
To complete your subscription and verify that this email belongs to you, please click the button below:
|
||||
</p>
|
||||
<!-- Action Button -->
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin-bottom: 28px;">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<a href="${safeUrl}" target="_blank" style="display: inline-block; background-color: #1d4ed8; color: #ffffff; font-size: 15px; font-weight: 700; text-decoration: none; padding: 14px 32px; border-radius: 8px; box-shadow: 0 2px 10px rgba(29, 78, 216, 0.3);">
|
||||
Confirm Subscription →
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div style="background-color: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 14px 18px; margin-bottom: 24px;">
|
||||
<div style="font-size: 12px; color: #64748b; line-height: 1.5;">
|
||||
<strong>Button not working?</strong> Copy and paste this URL into your browser:<br/>
|
||||
<a href="${safeUrl}" style="color: #1d4ed8; word-break: break-all; font-size: 11px;">${safeUrl}</a>
|
||||
</div>
|
||||
</div>
|
||||
<p style="margin: 0; font-size: 13px; color: #64748b; line-height: 1.5;">
|
||||
🔒 If you did not request this subscription, no action is required. You will never be added without explicit confirmation.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Footer -->
|
||||
<tr>
|
||||
<td style="background-color: #f8fafc; border-top: 1px solid #e2e8f0; padding: 24px 32px; text-align: center;">
|
||||
<p style="margin: 0 0 8px; font-size: 12px; font-weight: 700; color: #0a2342;">
|
||||
Aira Group of Technology
|
||||
</p>
|
||||
<p style="margin: 0 0 12px; font-size: 11px; color: #64748b;">
|
||||
Sovereign Deep-Tech & AI Engineering • Kerala, India
|
||||
</p>
|
||||
<p style="margin: 0; font-size: 11px; color: #94a3b8;">
|
||||
<a href="https://www.airaaigroup.in/privacy" style="color: #64748b; text-decoration: underline;">Privacy Policy</a> •
|
||||
<a href="https://www.airaaigroup.in/terms" style="color: #64748b; text-decoration: underline;">Terms of Service</a> •
|
||||
<a href="https://www.airaaigroup.in" style="color: #64748b; text-decoration: underline;">Official Portal</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
export function getWelcomeEmailHtml(name) {
|
||||
const safeName = name ? escapeHtml(name) : "Colleague";
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Welcome to Aira Group — Sovereign Engineering</title>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0; background-color: #f1f5f9; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; color: #0f172a;">
|
||||
<div style="display: none; font-size: 1px; color: #f1f5f9; line-height: 1px; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden;">
|
||||
Your subscription is confirmed. Welcome to Aira Group of Technology — Sovereign Engineering. Zero Dependency.
|
||||
</div>
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: #f1f5f9;">
|
||||
<tr>
|
||||
<td align="center" style="padding: 40px 16px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 580px; background-color: #ffffff; border: 1px solid #e2e8f0; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 20px rgba(10, 35, 66, 0.05);">
|
||||
<!-- Top Header -->
|
||||
<tr>
|
||||
<td style="background-color: #0a2342; padding: 26px 32px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td>
|
||||
<div style="font-size: 20px; font-weight: 800; color: #ffffff; letter-spacing: -0.5px;">
|
||||
Aira<span style="color: #60a5fa;">Group</span>
|
||||
</div>
|
||||
<div style="font-size: 9px; font-weight: 700; color: #93c5fd; letter-spacing: 2px; text-transform: uppercase; margin-top: 3px;">
|
||||
TECHNOLOGY • SOVEREIGN ENGINEERING
|
||||
</div>
|
||||
</td>
|
||||
<td align="right">
|
||||
<span style="font-size: 11px; font-weight: 600; color: #34d399; background-color: rgba(16, 185, 129, 0.15); border: 1px solid rgba(52, 211, 153, 0.4); padding: 4px 10px; border-radius: 6px;">
|
||||
✓ Verified Member
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Body -->
|
||||
<tr>
|
||||
<td style="padding: 36px 32px 28px;">
|
||||
<div style="font-size: 12px; font-weight: 700; color: #1d4ed8; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px;">
|
||||
OFFICIAL WELCOME
|
||||
</div>
|
||||
<h1 style="margin: 0 0 16px; font-size: 24px; font-weight: 800; color: #0a2342; line-height: 1.3;">
|
||||
Sovereign Engineering.<br/>Zero Dependency.
|
||||
</h1>
|
||||
<p style="margin: 0 0 16px; font-size: 15px; line-height: 1.6; color: #334155;">
|
||||
Hello <strong>${safeName}</strong>,
|
||||
</p>
|
||||
<p style="margin: 0 0 18px; font-size: 15px; line-height: 1.6; color: #475569;">
|
||||
Welcome to <strong>Aira Group of Technology</strong>. We don't just build consumer software; we engineer deep-tech sovereignty from the bare metal up.
|
||||
</p>
|
||||
<p style="margin: 0 0 24px; font-size: 15px; line-height: 1.6; color: #475569;">
|
||||
As a confirmed subscriber to our Dispatches, you get direct, early insights into our active research and open deployments:
|
||||
</p>
|
||||
|
||||
<!-- Feature Highlights -->
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin-bottom: 28px;">
|
||||
<tr>
|
||||
<td style="padding: 14px 16px; background-color: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td width="32" valign="top" style="font-size: 18px;">⚡</td>
|
||||
<td style="padding-left: 10px;">
|
||||
<div style="font-size: 14px; font-weight: 700; color: #0a2342;">Aira Sovereign Models Hub</div>
|
||||
<div style="font-size: 12px; color: #64748b; margin-top: 2px;">
|
||||
Zero rate-limit OpenAI-compatible AI API gateway and interactive playground.
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td height="10"></td></tr>
|
||||
<tr>
|
||||
<td style="padding: 14px 16px; background-color: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td width="32" valign="top" style="font-size: 18px;">🌐</td>
|
||||
<td style="padding-left: 10px;">
|
||||
<div style="font-size: 14px; font-weight: 700; color: #0a2342;">AiraLang & Bare-Metal Kernel</div>
|
||||
<div style="font-size: 12px; color: #64748b; margin-top: 2px;">
|
||||
High-performance SIMD execution engine engineered without foreign frameworks.
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td height="10"></td></tr>
|
||||
<tr>
|
||||
<td style="padding: 14px 16px; background-color: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td width="32" valign="top" style="font-size: 18px;">📡</td>
|
||||
<td style="padding-left: 10px;">
|
||||
<div style="font-size: 14px; font-weight: 700; color: #0a2342;">Cellular Mesh & Hardened Comms</div>
|
||||
<div style="font-size: 12px; color: #64748b; margin-top: 2px;">
|
||||
Decentralized off-grid mesh protocols for mission-critical infrastructure.
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- Action Button -->
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin-bottom: 28px;">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<a href="https://www.airaaigroup.in" target="_blank" style="display: inline-block; background-color: #1d4ed8; color: #ffffff; font-size: 15px; font-weight: 700; text-decoration: none; padding: 14px 32px; border-radius: 8px; box-shadow: 0 2px 10px rgba(29, 78, 216, 0.3);">
|
||||
Explore Aira Ecosystem →
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div style="border-top: 1px solid #e2e8f0; padding-top: 20px;">
|
||||
<p style="margin: 0; font-size: 14px; font-weight: 700; color: #0a2342;">
|
||||
Er. Adam Eehan
|
||||
</p>
|
||||
<p style="margin: 2px 0 0; font-size: 12px; color: #64748b;">
|
||||
Founder & CEO, Aira Group of Technology
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Footer -->
|
||||
<tr>
|
||||
<td style="background-color: #f8fafc; border-top: 1px solid #e2e8f0; padding: 24px 32px; text-align: center;">
|
||||
<p style="margin: 0 0 8px; font-size: 12px; font-weight: 700; color: #0a2342;">
|
||||
Aira Group of Technology
|
||||
</p>
|
||||
<p style="margin: 0 0 12px; font-size: 11px; color: #64748b;">
|
||||
Sovereign Deep-Tech & AI Engineering • Kerala, India
|
||||
</p>
|
||||
<p style="margin: 0; font-size: 11px; color: #94a3b8;">
|
||||
<a href="https://www.airaaigroup.in/privacy" style="color: #64748b; text-decoration: underline;">Privacy Policy</a> •
|
||||
<a href="https://www.airaaigroup.in/terms" style="color: #64748b; text-decoration: underline;">Terms of Service</a> •
|
||||
<a href="https://www.airaaigroup.in" style="color: #64748b; text-decoration: underline;">Official Portal</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
function escapeHtml(str) {
|
||||
return String(str)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// Aira Sovereign Mail Dispatcher
|
||||
// Engineered for Aira Group of Technology (airaaigroup.in)
|
||||
|
||||
export async function sendEmail({ to, toName, subject, html }) {
|
||||
const RESEND_KEY = process.env.RESEND_API_KEY || "";
|
||||
const SENDER_EMAIL = process.env.SENDER_EMAIL || "noreply@airaaigroup.in";
|
||||
const SENDER_NAME = process.env.SENDER_NAME || "Aira Group of Technology";
|
||||
|
||||
// 1. Try Resend API
|
||||
if (RESEND_KEY) {
|
||||
try {
|
||||
const resendRes = await fetch("https://api.resend.com/emails", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${RESEND_KEY}`,
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": "AiraGroup-Portal/1.0"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
from: `${SENDER_NAME} <${SENDER_EMAIL}>`,
|
||||
to: [to],
|
||||
subject: subject,
|
||||
html: html
|
||||
})
|
||||
});
|
||||
|
||||
const resendData = await resendRes.json();
|
||||
if (resendRes.ok) {
|
||||
console.log(`[Resend Success] Email sent to ${to}:`, resendData.id);
|
||||
return { success: true, provider: "resend", id: resendData.id };
|
||||
} else {
|
||||
console.warn(`[Resend Warning] (${resendRes.status}):`, JSON.stringify(resendData));
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("[Resend Exception]:", err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Try SMTP if environment credentials exist
|
||||
if (process.env.SMTP_HOST && process.env.SMTP_USER && process.env.SMTP_PASS) {
|
||||
try {
|
||||
const nodemailer = await import("nodemailer");
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: process.env.SMTP_HOST,
|
||||
port: parseInt(process.env.SMTP_PORT || "465", 10),
|
||||
secure: process.env.SMTP_SECURE !== "false",
|
||||
auth: {
|
||||
user: process.env.SMTP_USER,
|
||||
pass: process.env.SMTP_PASS
|
||||
}
|
||||
});
|
||||
|
||||
const info = await transporter.sendMail({
|
||||
from: `"${SENDER_NAME}" <${process.env.SMTP_USER}>`,
|
||||
to: to,
|
||||
subject: subject,
|
||||
html: html
|
||||
});
|
||||
|
||||
console.log(`[SMTP Success] Email sent to ${to}:`, info.messageId);
|
||||
return { success: true, provider: "smtp", id: info.messageId };
|
||||
} catch (err) {
|
||||
console.error("[SMTP Exception]:", err.message);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
error: "No active email dispatch provider succeeded."
|
||||
};
|
||||
}
|
||||
+41
-24
@@ -1,8 +1,15 @@
|
||||
// Vercel Serverless Function: Automated Hostinger Reach Subscription
|
||||
// Vercel Serverless Function: Automated Double Opt-In Subscription
|
||||
// Engineered for Aira Group of Technology (airaaigroup.in)
|
||||
|
||||
import { generateVerifyToken } from "./verify.js";
|
||||
import { getConfirmationEmailHtml } from "./_emailTemplates.js";
|
||||
import { sendEmail } from "./_mailer.js";
|
||||
|
||||
const HOSTINGER_TOKEN = process.env.HOSTINGER_API_TOKEN || "QVeJgNyXciHezaw5fsjAJeTiEXJfBfd4FqwUifna8cfab21c";
|
||||
const PROFILE_UUID = "623e0772-031e-44fc-8a18-d225af88bad6";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
// Set CORS headers
|
||||
// CORS headers
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
|
||||
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
@@ -22,38 +29,48 @@ export default async function handler(req, res) {
|
||||
return res.status(400).json({ error: "Valid email address is required." });
|
||||
}
|
||||
|
||||
const HOSTINGER_TOKEN = process.env.HOSTINGER_API_TOKEN || "QVeJgNyXciHezaw5fsjAJeTiEXJfBfd4FqwUifna8cfab21c";
|
||||
const PROFILE_UUID = "623e0772-031e-44fc-8a18-d225af88bad6";
|
||||
const REACH_URL = `https://developers.hostinger.com/api/reach/v1/profiles/${PROFILE_UUID}/contacts`;
|
||||
const cleanEmail = email.trim().toLowerCase();
|
||||
const cleanName = name ? name.trim() : "";
|
||||
|
||||
const payload = {
|
||||
email: email.trim().toLowerCase(),
|
||||
name: name ? name.trim() : null
|
||||
};
|
||||
// 1. Generate secure cryptographic verification link
|
||||
const token = generateVerifyToken(cleanEmail);
|
||||
const host = req.headers["x-forwarded-host"] || req.headers.host || "www.airaaigroup.in";
|
||||
const proto = req.headers["x-forwarded-proto"] || "https";
|
||||
const verifyUrl = `${proto}://${host}/api/verify?email=${encodeURIComponent(cleanEmail)}&token=${token}${cleanName ? `&name=${encodeURIComponent(cleanName)}` : ""}`;
|
||||
|
||||
const hostingerRes = await fetch(REACH_URL, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${HOSTINGER_TOKEN}`,
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": "AiraGroup-Portal/1.0"
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
// 2. Dispatch Confirmation Email
|
||||
const confirmHtml = getConfirmationEmailHtml(cleanName, verifyUrl);
|
||||
const mailResult = await sendEmail({
|
||||
to: cleanEmail,
|
||||
toName: cleanName,
|
||||
subject: "Verify Your Subscription — Aira Group of Technology",
|
||||
html: confirmHtml
|
||||
});
|
||||
|
||||
const responseText = await hostingerRes.text();
|
||||
console.log("[Confirmation Mail Dispatch Result]:", mailResult);
|
||||
|
||||
if (!hostingerRes.ok) {
|
||||
console.error("[Hostinger Reach Error]:", hostingerRes.status, responseText);
|
||||
return res.status(hostingerRes.status).json({
|
||||
error: "Failed to sync subscription with Hostinger.",
|
||||
details: responseText
|
||||
// 3. Register contact with Hostinger Reach
|
||||
try {
|
||||
const reachRes = await fetch(`https://developers.hostinger.com/api/reach/v1/profiles/${PROFILE_UUID}/contacts`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${HOSTINGER_TOKEN}`,
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": "AiraGroup-Portal/1.0"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
email: cleanEmail,
|
||||
name: cleanName || null
|
||||
})
|
||||
});
|
||||
console.log("[Hostinger Reach Contact Sync]:", reachRes.status);
|
||||
} catch (err) {
|
||||
console.warn("[Hostinger Sync Warning]:", err.message);
|
||||
}
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: "Subscription confirmed! Please check your email to verify your subscription."
|
||||
message: "Confirmation email sent! Please check your inbox and click the verification button."
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("[Subscribe API Exception]:", err);
|
||||
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
// Vercel Serverless Function: Double Opt-In Email Verification
|
||||
// Engineered for Aira Group of Technology (airaaigroup.in)
|
||||
|
||||
import crypto from "crypto";
|
||||
import { getWelcomeEmailHtml } from "./_emailTemplates.js";
|
||||
import { sendEmail } from "./_mailer.js";
|
||||
|
||||
const SECRET = process.env.VERIFY_SECRET || "aira-sovereign-secret-token-key-2026";
|
||||
const HOSTINGER_TOKEN = process.env.HOSTINGER_API_TOKEN || "QVeJgNyXciHezaw5fsjAJeTiEXJfBfd4FqwUifna8cfab21c";
|
||||
const PROFILE_UUID = "623e0772-031e-44fc-8a18-d225af88bad6";
|
||||
|
||||
export function generateVerifyToken(email) {
|
||||
return crypto.createHmac("sha256", SECRET).update(email.trim().toLowerCase()).digest("hex");
|
||||
}
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { email, token, name } = req.query || {};
|
||||
|
||||
if (!email || !token) {
|
||||
return res.status(400).send(renderStatusHtml(false, "Invalid Verification Link", "The confirmation link is missing required parameters. Please subscribe again from our portal."));
|
||||
}
|
||||
|
||||
const cleanEmail = email.trim().toLowerCase();
|
||||
const displayName = name ? decodeURIComponent(name).trim() : "";
|
||||
const expectedToken = generateVerifyToken(cleanEmail);
|
||||
|
||||
if (token !== expectedToken) {
|
||||
return res.status(403).send(renderStatusHtml(false, "Verification Link Invalid", "This confirmation link is invalid or has expired. Please subscribe again from our portal."));
|
||||
}
|
||||
|
||||
// 1. Sync confirmed subscriber with Hostinger Reach
|
||||
try {
|
||||
const reachRes = await fetch(`https://developers.hostinger.com/api/reach/v1/profiles/${PROFILE_UUID}/contacts`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${HOSTINGER_TOKEN}`,
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": "AiraGroup-Portal/1.0"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
email: cleanEmail,
|
||||
name: displayName || null,
|
||||
subscription_status: "subscribed"
|
||||
})
|
||||
});
|
||||
console.log("[Hostinger Reach Confirmed Sync]:", reachRes.status);
|
||||
} catch (err) {
|
||||
console.error("[Hostinger Reach Sync Error]:", err.message);
|
||||
}
|
||||
|
||||
// 2. Dispatch Welcome Email
|
||||
try {
|
||||
const welcomeHtml = getWelcomeEmailHtml(displayName);
|
||||
await sendEmail({
|
||||
to: cleanEmail,
|
||||
toName: displayName,
|
||||
subject: "Welcome to Aira Group — Sovereign Engineering. Zero Dependency",
|
||||
html: welcomeHtml
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("[Welcome Email Dispatch Error]:", err.message);
|
||||
}
|
||||
|
||||
// 3. Render Clean Corporate Success Page
|
||||
return res.status(200).send(renderStatusHtml(
|
||||
true,
|
||||
"Subscription Confirmed! 🎉",
|
||||
`Thank you for confirming your email (${escapeHtml(cleanEmail)}). You are now an active member of Aira Group Sovereign Engineering Dispatches. Your official welcome dispatch has been sent to your inbox.`
|
||||
));
|
||||
}
|
||||
|
||||
function renderStatusHtml(isSuccess, title, message) {
|
||||
const accentColor = isSuccess ? "#10b981" : "#ef4444";
|
||||
const icon = isSuccess ? "✓" : "!";
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>${escapeHtml(title)} — Aira Group of Technology</title>
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||
<style>
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body {
|
||||
background-color: #07090e;
|
||||
color: #f8fafc;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
.card {
|
||||
background-color: #0d121c;
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
border-radius: 16px;
|
||||
max-width: 520px;
|
||||
width: 100%;
|
||||
padding: 40px 32px;
|
||||
text-align: center;
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
.badge-icon {
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
border-radius: 50%;
|
||||
background: ${isSuccess ? "rgba(16, 185, 129, 0.15)" : "rgba(239, 68, 68, 0.15)"};
|
||||
border: 2px solid ${accentColor};
|
||||
color: ${accentColor};
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
font-weight: 800;
|
||||
color: #ffffff;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
p {
|
||||
font-size: 15px;
|
||||
line-height: 1.6;
|
||||
color: #94a3b8;
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
.btn {
|
||||
display: inline-block;
|
||||
background-color: #1d4ed8;
|
||||
color: #ffffff;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
padding: 12px 28px;
|
||||
border-radius: 8px;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
.btn:hover {
|
||||
background-color: #2563eb;
|
||||
}
|
||||
.footer-text {
|
||||
margin-top: 24px;
|
||||
font-size: 12px;
|
||||
color: #64748b;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="card">
|
||||
<div class="badge-icon">${icon}</div>
|
||||
<h1>${escapeHtml(title)}</h1>
|
||||
<p>${message}</p>
|
||||
<a href="https://www.airaaigroup.in" class="btn">← Return to Aira Group Homepage</a>
|
||||
<div class="footer-text">
|
||||
Aira Group of Technology • Sovereign Engineering • Zero Dependency
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
function escapeHtml(str) {
|
||||
return String(str)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "aira-company-website",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"description": "Official Website & Serverless Endpoints for Aira Group of Technology",
|
||||
"dependencies": {
|
||||
"nodemailer": "^6.9.16"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user