summaryrefslogtreecommitdiffstats
path: root/templates/register/register.html.template
blob: 3b4d959d54d22b2b6f50797385ad999696149798 (plain) (blame)
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
<!-- Copyright 2026 Rose Hogenson <r@roseh.moe>
  --
  -- This file is part of roseh.moe.
  --
  -- roseh.moe is free software: you can redistribute it and/or modify
  -- it under the terms of the GNU Affero General Public License
  -- as published by the Free Software Foundation, either version 3 of
  -- the License, or (at your option) any later version.
  --
  -- roseh.moe is distributed in the hope that it will be useful,
  -- but WITHOUT ANY WARRANTY; without even the implied warranty
  -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  -- GNU Affero General Public License for more details.
  --
  -- You should have received a copy of the GNU Affero General Public
  -- License along with roseh.moe. If not, see
  -- <https://www.gnu.org/licenses/>.
  -->

<title>Register</title>

<section>
	<form id="form" class="password-form" method="post">
		<input id="id" type="hidden" name="id" value="{{.ID}}">
		<input id="key" type="hidden" name="key">
		<table>
			<tr class="password-form-row">
				<td><label class="password-label" for="name">Enter a name for this passkey</label>
				<td><input id="name" class="password" name="name">
			<tr>
				<td>
				<td>
					<img width="100" height="71" class="submit" src="/static/point.webp" alt="Submit"
							onClick="generateKey()">
		</table>
	</form>
</section>

<script>
async function generateKey() {
	const name = document.getElementById("name").value;
	const publicKeyCredential = await navigator.credentials.create({publicKey: {
		challenge: Uint8Array.fromBase64("{{.Challenge}}").buffer,
		pubKeyCredParams: [
			{alg: -9,   type: "public-key"},
			{alg: -257, type: "public-key"},
			{alg: -7,   type: "public-key"},
			{alg: -8,   type: "public-key"},
		],
		rp: {
			name: "roseh.moe",
		},
		user: {
			displayName: name,
			id: Uint8Array.fromBase64(document.getElementById("id").value).buffer,
			name: name,
		},
	}});
	document.getElementById("key").value = new Uint8Array(publicKeyCredential.response.getPublicKey()).toBase64();
	document.getElementById("form").submit();
}
</script>