2023-09-07 23:36:07 +00:00
|
|
|
export async function onRequestPost({ request, env }) {
|
2023-09-08 00:00:29 +00:00
|
|
|
const origin = new URL(request.url).origin;
|
|
|
|
const { username, password, discordID } = Object.fromEntries(await request.formData().then((f) => f.entries()));
|
2023-09-07 23:36:07 +00:00
|
|
|
|
2023-09-08 00:00:29 +00:00
|
|
|
const login = await fetch("https://eactivities.union.ic.ac.uk/user/login", {
|
2023-09-07 23:36:07 +00:00
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({ username: username, password: password, }),
|
|
|
|
headers: { "content-type": "application/json", },
|
|
|
|
}).catch(console.error);
|
|
|
|
|
|
|
|
if (login == undefined || login.status != 200) {
|
2023-09-08 00:00:29 +00:00
|
|
|
console.log(`😢 Login verification failed for discord user [${discordID}] with shortcode [${username}]`);
|
|
|
|
return Response.redirect(`${origin}/verify/failure`, 301);
|
2023-09-07 23:36:07 +00:00
|
|
|
} else {
|
2023-09-08 00:00:29 +00:00
|
|
|
console.log(`🚀 Login verification succeeded for discord user [${discordID}] with shortcode [${username}]`);
|
|
|
|
// TODO: Send username and discordID to Nanobot
|
|
|
|
return Response.redirect(`${origin}/verify/success`, 301);
|
2023-09-07 23:36:07 +00:00
|
|
|
}
|
|
|
|
}
|