-
Notifications
You must be signed in to change notification settings - Fork 4
/
signUp.js
50 lines (45 loc) · 1.21 KB
/
signUp.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
let baseURL = 'http://127.0.0.1:8888';
window.onload = () => {
var requestOptions = {
method: 'GET',
mode: 'cors',
credentials: 'include'
};
fetch(`${baseURL}/user/check`, requestOptions)
.then(result => result.json())
.then(res => {
// console.log(res);
if (res.STATUS === 1) window.location = 'dashboard.html';
})
.catch(error => console.log('error', error));
};
let signUpForm = document.getElementById('signUpForm');
signUpForm.addEventListener('submit', e => {
e.preventDefault();
if (signUpForm[3].value !== signUpForm[4].value) {
alert('PASSWORDS DO NOT MATCH');
} else {
let data = new FormData();
for (let i = 0; i < 5; i++) {
// console.log(signUpForm[i].name, signUpForm[i].value);
data.append(signUpForm[i].name, signUpForm[i].value);
}
// for (let pair of data.entries()) {
// console.log(pair[0] + ', ' + pair[1]);
// }
var requestOptions = {
method: 'POST',
body: data
};
fetch(`${baseURL}/user/signup`, requestOptions)
.then(result => result.json())
.then(res => {
// console.log(res);
alert(res.MESSAGE);
if (res.STATUS === 1) {
window.location = 'signIn.html';
}
})
.catch(error => console.log('error', error));
}
});