summaryrefslogtreecommitdiff
path: root/static/src
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2021-08-03 16:28:22 -0600
committerBrian Picciano <mediocregopher@gmail.com>2021-08-03 16:28:22 -0600
commit9c3ea8dd803d6f0df768e3ae37f8c4ab2efbcc5c (patch)
tree93f2f3e104a255e4959816ac762b70e7dafd6562 /static/src
parentec4aac24abc35fcf192c13a3fc9b2b65875c3444 (diff)
implement finalize and unsubscribe endpoints
Diffstat (limited to 'static/src')
-rw-r--r--static/src/mailinglist/finalize.md53
-rw-r--r--static/src/mailinglist/unsubscribe.md54
2 files changed, 107 insertions, 0 deletions
diff --git a/static/src/mailinglist/finalize.md b/static/src/mailinglist/finalize.md
new file mode 100644
index 0000000..fe8f741
--- /dev/null
+++ b/static/src/mailinglist/finalize.md
@@ -0,0 +1,53 @@
+---
+layout: page
+title: ""
+nofollow: true
+---
+
+<style>
+#result.success { color: green; }
+#result.fail { color: red; }
+</style>
+
+<span id="result"></span>
+
+<script>
+
+(async () => {
+ const resultSpan = document.getElementById("result");
+
+ function setErr(errStr) {
+ resultSpan.className = "fail";
+ resultSpan.innerHTML = errStr;
+ }
+
+ const urlParams = new URLSearchParams(window.location.search);
+ const subToken = urlParams.get('subToken');
+
+ if (!subToken) {
+ setErr("No subscription token provided");
+ return;
+ }
+
+ const finalizeForm = new FormData();
+ finalizeForm.append('subToken', subToken);
+
+ const finalizeReq = new Request('/api/mailinglist/finalize', {
+ method: 'POST',
+ body: finalizeForm,
+ });
+
+ const res = await fetch(finalizeReq)
+ .then(response => response.json());
+
+ if (res.error) {
+ setErr(res.error);
+ return;
+ }
+
+ resultSpan.className = "success";
+ resultSpan.innerHTML = "Your email subscription has been finalized! Please go on about your day.";
+
+})();
+
+</script>
diff --git a/static/src/mailinglist/unsubscribe.md b/static/src/mailinglist/unsubscribe.md
new file mode 100644
index 0000000..6a118a0
--- /dev/null
+++ b/static/src/mailinglist/unsubscribe.md
@@ -0,0 +1,54 @@
+---
+layout: page
+title: ""
+nofollow: true
+---
+
+<style>
+#result.success { color: green; }
+#result.fail { color: red; }
+</style>
+
+<span id="result"></span>
+
+<script>
+
+(async () => {
+ const resultSpan = document.getElementById("result");
+
+ function setErr(errStr) {
+ resultSpan.className = "fail";
+ resultSpan.innerHTML = errStr;
+ }
+
+ const urlParams = new URLSearchParams(window.location.search);
+ const unsubToken = urlParams.get('unsubToken');
+
+ if (!unsubToken) {
+ setErr("No unsubscribe token provided");
+ return;
+ }
+
+ const unsubscribeForm = new FormData();
+ unsubscribeForm.append('unsubToken', unsubToken);
+
+ const unsubscribeReq = new Request('/api/mailinglist/unsubscribe', {
+ method: 'POST',
+ body: unsubscribeForm,
+ });
+
+ const res = await fetch(unsubscribeReq)
+ .then(response => response.json());
+
+ if (res.error) {
+ setErr(res.error);
+ return;
+ }
+
+ resultSpan.className = "success";
+ resultSpan.innerHTML = "You have been unsubscribed! Please go on about your day.";
+
+})();
+
+</script>
+