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
86
87
88
89
import { html } from "https://esm.town/v/lbb00/html";
export async function LoginRegistryExample(request: Request): Promise<Response> {
return new Response(
html`
<html>
<style>
form {
display: none;
}
input[type='radio']:checked + label + form {
display: block;
}
</style>
<body>
<input name="method" id="login" type="radio" checked />
<label for="login">Log in</label>
<form id="loginForm">
<div>
<label for="account">Account</label>
<input name="account" type="email" autocomplete="email" placeholder="Email" required />
</div>
<div>
<label for="password">Password</label>
<input
name="password"
type="password"
name="password"
autocomplete="password"
placeholder="Password"
required
/>
</div>
<button>Log in</button>
</form>
<input name="method" id="signup" type="radio" />
<label for="signup">Sign up</label>
<form id="signupForm">
<div>
<label for="account">Account</label>
<input name="account" type="email" autocomplete="email" placeholder="Email" required />
</div>
<div>
<label for="password">Password</label>
<input
name="password"
type="password"
name="password"
autocomplete="new-password"
placeholder="Password"
required
/>
</div>
<div>
<label for="retype-password">Confirm password</label>
<input
name="retype-password"
type="password"
autocomplete="new-password"
placeholder="Retype password"
required
/>
</div>
<button>Sign up</button>
</form>
<div id="content"></div>
</body>
<script>
const forms = document.querySelectorAll('form')
forms.forEach((form) => {
form.addEventListener('submit', (e) => {
e.preventDefault()
const formData = new FormData(form)
const data = {}
for (const [key, value] of formData.entries()) {
data[key] = value
}
const div = document.querySelector('#content')
div.innerHTML = JSON.stringify(data, null, 2)
})
})
</script>
</html>
`,
{ headers: { "Content-Type": "text/html" } },
);
}