summaryrefslogtreecommitdiff
path: root/static/src/mailinglist/finalize.md
blob: fe8f741aa9f1ea121551133479ec7b8bccda1254 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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>