-
Notifications
You must be signed in to change notification settings - Fork 0
/
keydb.html
101 lines (101 loc) · 3.31 KB
/
keydb.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>KeyDB Demo</title>
<script src="main.js"></script>
</head>
<body>
<h1>KeyDB Demo</h1>
<p>
<label for="app-name">What is your app's name (max. 15 characters)?</label><br>
<input type="text" id="app-name" maxlength="15">
<button onclick="generateAppId()">Generate unique AppID</button>
</p>
<p>
<label for="app-ID">This is your AppID:</label><br>
<input type="text" id="app-ID" size="40" readonly>
</p>
<hr>
<p>
<label for="key">Enter new username:</label>
<input type="text" id="key" maxlength="31">
<button id="sign-up" onclick="enterKey()">Sign up</button>
</p>
<p id="result" style="visibility: hidden">placeholder</p>
<hr>
<p>Note: Adding first user takes much longer, because the database needs to be created.</p>
<p>If you experience errors, try increasing the timeout value (ms):</p>
<input type="number" id="timeout" value="3000">
<button onclick="setTimeout()">Set</button>
<p>Be careful, though: if you set this value too high, your request will take forever!</p>
<script>
window.setDefaultPortal('https://skyportal.xyz');
window.setDefaultTimeout(3000); var to = 3000;
const res = document.getElementById('result');
function setTimeout() {
const t = document.getElementById('timeout').value;
if (t <= 0) {
document.getElementById('timeout').value = to;
return;
}
window.setDefaultTimeout(t);
to = t;
}
function generateAppId() {
const name = document.getElementById('app-name').value;
if (name == '') { return; }
document.getElementById('app-ID').value = window.createAppId(name);
document.getElementById('key').value = '';
res.style.visibility = 'hidden';
res.innerText = 'placeholder';
}
async function enterKey() {
const appId = document.getElementById('app-ID').value;
const key = document.getElementById('key').value;
if ((appId == '') || (key == '')) { return; }
document.getElementById('sign-up').innerText = '...';
document.getElementById('sign-up').disabled = true;
res.style.visibility = 'hidden';
let exists, result;
try {
exists = await window.keyExists(key, appId);
} catch (error) {
res.style.color = '#af0000';
res.innerText = 'Error adding user!';
res.style.visibility = 'visible';
document.getElementById('sign-up').innerText = 'Sign up';
document.getElementById('sign-up').disabled = false;
return;
};
if (exists) {
res.style.color = '#af0000';
res.innerText = 'This user name is already occupied.';
res.style.visibility = 'visible';
} else {
try {
result = await window.appendRegistryKey(key, appId);
} catch (error) {
res.style.color = '#af0000';
res.innerText = 'Error adding user!';
res.style.visibility = 'visible';
document.getElementById('sign-up').innerText = 'Sign up';
document.getElementById('sign-up').disabled = false;
return;
};
if (result) {
res.style.color = '#00af00';
res.innerText = 'New user added successfully!';
res.style.visibility = 'visible';
} else {
res.style.color = '#af0000';
res.innerText = 'Error adding user!';
res.style.visibility = 'visible';
}
}
document.getElementById('sign-up').innerText = 'Sign up';
document.getElementById('sign-up').disabled = false;
}
</script>
</body>
</html>