Skip to content
Permalink
056c6b84f3
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Latest commit 026d1ca Oct 19, 2023 History
1 contributor

Users who have contributed to this file

34 lines (29 sloc) 1 KB
export async function onRequest(context: RequestContext) {
const { current_user: currentUser } = context.data;
if (!currentUser.email)
return new Response(null, {
status: 204,
});
const deliveryDate = new Date(
Date.now() + 86400000 + Math.round(Math.random() * 172800000),
)
.toUTCString()
.replace("GMT", "+0000");
const emailData = new FormData();
emailData.append("from", "totallyrealadminapplication@mail.carcrushers.cc");
emailData.append("to", currentUser.email);
emailData.append("subject", "Your admin application has been approved");
emailData.append("o:deliverytime", deliveryDate);
emailData.append("v:username", currentUser.username);
emailData.append("template", "admin_application");
await fetch("https://api.mailgun.net/v3/mail.carcrushers.cc/messages", {
body: emailData,
headers: {
authorization: `Basic ${btoa(`api:${context.env.MAILGUN_API_KEY}`)}`,
},
method: "POST",
});
return new Response(null, {
status: 204,
});
}