-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
68 lines (62 loc) · 2.27 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>User Login and Points Query</title>
</head>
<body>
<h1>User Login and Points Query</h1>
<div id="loginForm">
<input type="text" id="username" placeholder="Username">
<input type="password" id="password" placeholder="Password">
<button id="loginBtn">Login</button>
</div>
<div id="queryForm" style="display: none;">
<button id="queryBtn">Query Points</button>
<div id="userInfo" style="display: none;"></div> <!-- 新增显示用户信息的区域 -->
<div id="points"></div>
</div>
<script>
document.getElementById('loginBtn').addEventListener('click', function() {
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
fetch('https://breezy-assorted-dish.glitch.me:6060/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password })
})
.then(response => response.json())
.then(data => {
console.log(data);
if (data.message === 'Login successful') {
// 获取服务器返回的Session ID
const sessionId = data.sessionId;
// 存储Session ID,这里使用LocalStorage
localStorage.setItem('sessionId', sessionId);
document.getElementById('loginForm').style.display = 'none';
document.getElementById('queryForm').style.display = 'block';
document.getElementById('userInfo').style.display = 'block';
document.getElementById('userInfo').innerText = `Welcome, ${username}! `; // 显示用户信息
} else {
alert('Invalid username or password');
}
});
});
document.getElementById('queryBtn').addEventListener('click', function() {
//console.log(document.cookie);
fetch('https://breezy-assorted-dish.glitch.me:6060/points',{
headers: {
'Content-Type': 'application/json',
'session-id': localStorage.sessionId
}
})
.then(response => response.json())
.then(data => {
document.getElementById('points').innerText = `Points: ${data.points}`;
});
});
</script>
</body>
</html>