-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.html
85 lines (68 loc) · 2.08 KB
/
login.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/build/pure-min.css" integrity="sha384-cg6SkqEOCV1NbJoCu11+bm0NvBRc8IYLRGXkmNrqUBfTjmMYwNKPWBTIKyw9mHNJ" crossorigin="anonymous">
<style>
html, body, main {
height: 100%;
}
main {
display: flex;
justify-content: center;
align-items: center;
}
.content {
padding: 20px;
border: 1px solid #ccc;
}
#check-email-text {
font-size: 22px;
}
</style>
</head>
<body>
<main>
<div class='content'>
<h1>Login</h1>
<form class='pure-form'>
<input id='email-text' type='email' placeholder='Email' />
<button id='submit-btn' class='pure-button pure-button-primary'>Submit</button>
</form>
<div id='check-email-text' hidden>Check your email to confirm login</div>
</div>
</main>
<script>
const form = document.querySelector('form');
const emailEl = document.querySelector('#email-text');
const submitEl = document.querySelector('#submit-btn');
const checkEmailText = document.querySelector('#check-email-text');
submitEl.addEventListener('click', (e) => {
e.preventDefault();
if (emailEl.value.length < 4) {
return;
}
form.setAttribute('hidden', true);
checkEmailText.removeAttribute('hidden');
fetch(`/?pauth-method=login&email=${emailEl.value}`)
.then(response => {
console.log(response);
if (response.status !== 200) {
throw new Error("Invalid response code");
}
return response.text();
})
.then(token => {
location.reload();
})
.catch(e => {
console.error(e);
alert("Login failed. Please try again");
form.removeAttribute('hidden');
checkEmailText.setAttribute('hidden', true);
});
});
</script>
</body>
</html>