-
Notifications
You must be signed in to change notification settings - Fork 1
/
createaccount.js
53 lines (49 loc) · 1.65 KB
/
createaccount.js
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
const makePostRequest = async (data, endpoint, callback) => {
const sent = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
try {
const response = await sent.json();
callback(response);
} catch (error) {
console.log(error);
callback(error);
}
};
document.addEventListener('DOMContentLoaded', function() {
const btnCreate = document.getElementById('btnLogin');
btnCreate.addEventListener('click', async function() {
const form = document.getElementById('login');
const username = form.username.value;
const name = form.name.value;
const lastname = form.lastname.value;
const telephone = form.telephone.value;
const email = form.email.value;
const password = form.password.value;
if (username && name && lastname && telephone && email && password) {
const registrationData = {
username,
name,
lastname,
telephone,
email,
password
};
makePostRequest(registrationData, 'https://your-api-endpoint/register', (response) => {
if (response.success) {
alert('User registered successfully');
// Redirect to a confirmation page or login page
window.location.href = 'confirmation.html';
} else {
alert('Registration failed');
}
});
} else {
alert('Please fill out all fields');
}
});
});