-
Notifications
You must be signed in to change notification settings - Fork 4
/
signIn.js
50 lines (42 loc) · 1.1 KB
/
signIn.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';
// let baseURL = 'http://localhost: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 signInForm = document.getElementById('signInForm');
signInForm.addEventListener('submit', e => {
e.preventDefault();
let data = new FormData();
for (let i = 0; i < 2; i++) {
data.append(signInForm[i].name, signInForm[i].value);
}
var requestOptions = {
method: 'POST',
mode: 'cors',
credentials: 'include',
body: data
};
fetch(`${baseURL}/user/signIn`, requestOptions)
.then(result => result.json())
.then(res => {
// console.log(res);
if (res.STATUS === 1) {
sessionStorage.setItem('name', res.DATA['USER_NAME']);
window.location = 'dashboard.html';
} else {
alert(res.MESSAGE);
}
})
.catch(error => console.log('error', error));
});