mirror of
https://github.com/supleed2/ICAS.git
synced 2024-12-22 22:05:49 +00:00
Dynamic origin in submission redirect URLs
This commit is contained in:
parent
693ad7477f
commit
fe57b5b06f
|
@ -1,17 +1,19 @@
|
||||||
export async function onRequestPost({ request, env }) {
|
export async function onRequestPost({ request, env }) {
|
||||||
let { username, password, discordID } = Object.fromEntries(await request.formData().then((f) => f.entries()));
|
const origin = new URL(request.url).origin;
|
||||||
|
const { username, password, discordID } = Object.fromEntries(await request.formData().then((f) => f.entries()));
|
||||||
|
|
||||||
let 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: { "content-type": "application/json", },
|
||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
|
|
||||||
if (login == undefined || login.status != 200) {
|
if (login == undefined || login.status != 200) {
|
||||||
console.log(`Login verification failed 😢 for discord user [${discordID}] with shortcode [${username}]`);
|
console.log(`😢 Login verification failed for discord user [${discordID}] with shortcode [${username}]`);
|
||||||
return Response.redirect("http://127.0.0.1:8788/verify/failure", 301);
|
return Response.redirect(`${origin}/verify/failure`, 301);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Login verification succeeded 🚀 for discord user [${discordID}] with shortcode [${username}]`);
|
console.log(`🚀 Login verification succeeded for discord user [${discordID}] with shortcode [${username}]`);
|
||||||
return Response.redirect("http://127.0.0.1:8788/verify/success", 301);
|
// TODO: Send username and discordID to Nanobot
|
||||||
|
return Response.redirect(`${origin}/verify/success`, 301);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue