-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCadmin.js
More file actions
51 lines (42 loc) · 1.75 KB
/
Copy pathCadmin.js
File metadata and controls
51 lines (42 loc) · 1.75 KB
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
document.addEventListener('DOMContentLoaded', () => {
const newEmailInput = document.getElementById('newEmail');
const newPasswordInput = document.getElementById('newPassword');
const waktuInput = document.getElementById('waktu');
const addUserBtn = document.getElementById('addUserBtn');
const messageDiv = document.getElementById('message');
const logoutBtn = document.getElementById('logoutBtn');
const REGISTER_API_URL = 'http://206.189.93.164:2011/register';
logoutBtn.addEventListener('click', () => {
sessionStorage.clear();
window.location.href = 'index.html';
});
addUserBtn.addEventListener('click', async () => {
const email = newEmailInput.value;
const password = newPasswordInput.value;
const waktu = waktuInput.value;
if (!email || !password || !waktu) {
showMessage('Semua kolom harus diisi!', 'error');
return;
}
try {
const response = await fetch(REGISTER_API_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password, waktu })
});
const data = await response.json();
showMessage(data.msg, data.success ? 'success' : 'error');
if(data.success){
newEmailInput.value = '';
newPasswordInput.value = '';
waktuInput.value = '';
}
} catch (error) {
showMessage('Gagal terhubung ke server.', 'error');
}
});
function showMessage(message, type) {
messageDiv.textContent = message;
messageDiv.className = type;
}
});