mirror of
https://github.com/supleed2/ICAS.git
synced 2024-12-22 22:05:49 +00:00
Update submit function to send data to bot
This commit is contained in:
parent
1e3011b6e4
commit
7af1bb8df0
|
@ -5,15 +5,34 @@ export async function onRequestPost({ request, env }) {
|
||||||
const login = await fetch("https://eactivities.union.ic.ac.uk/user/login", {
|
const login = await fetch("https://eactivities.union.ic.ac.uk/user/login", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({ username: username, password: password, }),
|
body: JSON.stringify({ username: username, password: password, }),
|
||||||
headers: { "content-type": "application/json", },
|
headers: { accept: "text/html", "content-type": "application/json", },
|
||||||
}).catch(console.error);
|
});
|
||||||
|
|
||||||
if (login == undefined || login.status != 200) {
|
if (login.ok == false) {
|
||||||
console.log(`😢 Login verification failed for discord user [${discordID}] with shortcode [${username}]`);
|
console.log(`😢 FAILURE ${discordID}: ${username}`);
|
||||||
return Response.redirect(`${origin}/verify/failure`, 301);
|
return Response.redirect(`${origin}/verify/failure`, 301);
|
||||||
} else {
|
} else {
|
||||||
console.log(`🚀 Login verification succeeded for discord user [${discordID}] with shortcode [${username}]`);
|
const ck = login.headers.getSetCookie().at(0).split(";").at(0);
|
||||||
// TODO: Send username and discordID to Nanobot
|
await fetch("https://eactivities.union.ic.ac.uk/details", {
|
||||||
return Response.redirect(`${origin}/verify/success`, 301);
|
method: "GET",
|
||||||
|
headers: { accept: "text/html", cookie: ck },
|
||||||
|
});
|
||||||
|
const info = await fetch("https://eactivities.union.ic.ac.uk/ajax/863/activatetabs", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { accept: "application/xml, text/xml", cookie: ck }
|
||||||
|
}).then(r => r.text());
|
||||||
|
const firstname = info.match(/alias="First Name">(.*?)<\/info/)[1];
|
||||||
|
const surname = info.match(/alias="Surname">(.*?)<\/info/)[1];
|
||||||
|
console.log(`🚀 SUCCESS ${discordID}: ${username}, ${firstname} ${surname}`);
|
||||||
|
const submit = await fetch(env.BOT_URL, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ id: discordID, shortcode: username, fullname: `${firstname} ${surname}`, key: env.BOT_KEY }),
|
||||||
|
});
|
||||||
|
if (submit.ok) {
|
||||||
|
return Response.redirect(`${origin}/verify/success`, 301);
|
||||||
|
} else {
|
||||||
|
return Response.redirect(`${origin}/verify/error`, 301);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue