forked from peas-dev/peas
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
const form = document.querySelector("form");
|
|
form.addEventListener("submit", async (e) => {
|
|
e.preventDefault();
|
|
|
|
document.getElementsByName("code")[0].disable = "";
|
|
document.getElementsByName("submit")[0].disable = "";
|
|
|
|
let error = "";
|
|
|
|
const infoReq = await fetch("/api/info", {
|
|
method: "POST",
|
|
cache: "no-store",
|
|
});
|
|
if (!infoReq.ok) {
|
|
error = "通信エラーが発生しました";
|
|
}
|
|
const infoRes = await infoReq.json();
|
|
|
|
const code = document.getElementsByName("code")[0].value;
|
|
let turnstile;
|
|
if (infoRes.botprotection.turnstile === true) {
|
|
turnstile = document.getElementsByName("cf-turnstile-response")[0].value;
|
|
}
|
|
|
|
const req = await fetch("/api/mailverify", {
|
|
method: "POST",
|
|
cache: "no-store",
|
|
headers: {
|
|
'Content-Type': "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
code: code,
|
|
turnstile: turnstile ?? undefined,
|
|
}),
|
|
});
|
|
if (!req.ok) {
|
|
error = "通信エラーが発生しました";
|
|
}
|
|
const res = await req.json();
|
|
if (res.success === true) {
|
|
location.href = "/signin";
|
|
} else {
|
|
location.replace(`/mailverify?error=${res.error}&code=${document.getElementsByName("code")[0].value}`);
|
|
}
|
|
})
|