-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.html
61 lines (47 loc) · 1.98 KB
/
verify.html
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
54
55
56
57
58
59
60
61
---
permalink: /verify/index.html
layout: default
---
<h1 class="text-center">Stadfest abonnement</h1>
<p id="instructions" class="text-center">Klikk på lenkja under for å stadfesta abonnementet ditt.</p>
<div class="d-flex justify-content-center">
<a id="verify-button" class="btn btn-outline-primary" href="">Stadfest abonnement</a>
<div class="spinner-border text-primary m-5" role="status" id="verify-spinner" style="display: none;">
<span class="visually-hidden">Lastar...</span>
</div>
</div>
<div id="verify-message" class="text-center mt-3"></div>
<script>
const instructions = document.getElementById('instructions');
const verifyButton = document.getElementById('verify-button');
const message = document.getElementById('verify-message');
const spinner = document.getElementById('verify-spinner');
let ran = false;
document.addEventListener('DOMContentLoaded', () => {
const token = new URLSearchParams(window.location.search).get('token');
verifyButton.href = `{{ site.data.api.baseUrl }}/verify?token=${token}`;
verifyButton.click();
});
verifyButton.addEventListener('click', async (event) => {
event.preventDefault();
if (ran || !verifyButton.href) {
return;
}
ran = true;
message.innerHTML = '';
spinner.style.display = 'block';
instructions.style.display = 'none';
verifyButton.style.display = 'none';
const response = await fetch(verifyButton.href);
spinner.style.display = 'none';
if (response.status === 200) {
message.innerHTML = 'Abonnementet ditt er stadfesta. Du vil motta ein e-post når nytt innlegg blir publisert.';
} else if (response.status === 429) {
message.innerHTML = 'Du har vore for rask. Vennlegst prøv igjen om ei stund.';
} else if (response.status === 404) {
message.innerHTML = 'Stadfestingslenkja er ugyldig. Har du allereie stadfesta abonnementet ditt?';
} else {
message.innerHTML = 'Noko gjekk gale. Vennlegst prøv igjen.';
}
});
</script>