fix finalize and unsubscribe pages by making them use new api module
This commit is contained in:
parent
15ae483fad
commit
3e9a17abb9
@ -4,6 +4,8 @@ title: ""
|
|||||||
nofollow: true
|
nofollow: true
|
||||||
---
|
---
|
||||||
|
|
||||||
|
<script async type="module" src="/assets/api.js"></script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
#result.success { color: green; }
|
#result.success { color: green; }
|
||||||
#result.fail { color: red; }
|
#result.fail { color: red; }
|
||||||
@ -14,40 +16,30 @@ nofollow: true
|
|||||||
<script>
|
<script>
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
||||||
const resultSpan = document.getElementById("result");
|
const resultSpan = document.getElementById("result");
|
||||||
|
|
||||||
function setErr(errStr) {
|
try {
|
||||||
resultSpan.className = "fail";
|
|
||||||
resultSpan.innerHTML = errStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const subToken = urlParams.get('subToken');
|
const subToken = urlParams.get('subToken');
|
||||||
|
|
||||||
if (!subToken) {
|
if (!subToken) throw "No subscription token provided";
|
||||||
setErr("No subscription token provided");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const finalizeForm = new FormData();
|
const api = await import("/assets/api.js");
|
||||||
finalizeForm.append('subToken', subToken);
|
|
||||||
|
|
||||||
const finalizeReq = new Request('/api/mailinglist/finalize', {
|
await api.call('POST', '/api/mailinglist/finalize', {
|
||||||
method: 'POST',
|
body: { subToken },
|
||||||
body: finalizeForm,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await fetch(finalizeReq)
|
|
||||||
.then(response => response.json());
|
|
||||||
|
|
||||||
if (res.error) {
|
|
||||||
setErr(res.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
resultSpan.className = "success";
|
resultSpan.className = "success";
|
||||||
resultSpan.innerHTML = "Your email subscription has been finalized! Please go on about your day.";
|
resultSpan.innerHTML = "Your email subscription has been finalized! Please go on about your day.";
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
resultSpan.className = "fail";
|
||||||
|
resultSpan.innerHTML = e;
|
||||||
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -4,6 +4,8 @@ title: ""
|
|||||||
nofollow: true
|
nofollow: true
|
||||||
---
|
---
|
||||||
|
|
||||||
|
<script async type="module" src="/assets/api.js"></script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
#result.success { color: green; }
|
#result.success { color: green; }
|
||||||
#result.fail { color: red; }
|
#result.fail { color: red; }
|
||||||
@ -14,40 +16,29 @@ nofollow: true
|
|||||||
<script>
|
<script>
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
||||||
const resultSpan = document.getElementById("result");
|
const resultSpan = document.getElementById("result");
|
||||||
|
|
||||||
function setErr(errStr) {
|
try {
|
||||||
resultSpan.className = "fail";
|
|
||||||
resultSpan.innerHTML = errStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const unsubToken = urlParams.get('unsubToken');
|
const unsubToken = urlParams.get('unsubToken');
|
||||||
|
|
||||||
if (!unsubToken) {
|
if (!unsubToken) throw "No unsubscribe token provided";
|
||||||
setErr("No unsubscribe token provided");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const unsubscribeForm = new FormData();
|
const api = await import("/assets/api.js");
|
||||||
unsubscribeForm.append('unsubToken', unsubToken);
|
|
||||||
|
|
||||||
const unsubscribeReq = new Request('/api/mailinglist/unsubscribe', {
|
await api.call('POST', '/api/mailinglist/unsubscribe', {
|
||||||
method: 'POST',
|
body: { unsubToken },
|
||||||
body: unsubscribeForm,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await fetch(unsubscribeReq)
|
|
||||||
.then(response => response.json());
|
|
||||||
|
|
||||||
if (res.error) {
|
|
||||||
setErr(res.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
resultSpan.className = "success";
|
resultSpan.className = "success";
|
||||||
resultSpan.innerHTML = "You have been unsubscribed! Please go on about your day.";
|
resultSpan.innerHTML = "You have been unsubscribed! Please go on about your day.";
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
resultSpan.className = "fail";
|
||||||
|
resultSpan.innerHTML = e;
|
||||||
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user