myapp_evenfuture 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/Dockerfile +7 -0
- package/app.js +58 -0
- package/bin/www +91 -0
- package/package.json +20 -0
- package/public/css/layui.css +1 -0
- package/public/css/lizhi.webp +0 -0
- package/public/css/modules/code.css +1 -0
- package/public/css/modules/laydate/default/laydate.css +1 -0
- package/public/css/modules/layer/default/icon-ext.png +0 -0
- package/public/css/modules/layer/default/icon.png +0 -0
- package/public/css/modules/layer/default/layer.css +1 -0
- package/public/css/modules/layer/default/loading-0.gif +0 -0
- package/public/css/modules/layer/default/loading-1.gif +0 -0
- package/public/css/modules/layer/default/loading-2.gif +0 -0
- package/public/font/iconfont.eot +0 -0
- package/public/font/iconfont.svg +554 -0
- package/public/font/iconfont.ttf +0 -0
- package/public/font/iconfont.woff +0 -0
- package/public/font/iconfont.woff2 +0 -0
- package/public/layui.js +5 -0
- package/public/stylesheets/style.css +8 -0
- package/routes/api.js +505 -0
- package/routes/datatime.js +17 -0
- package/routes/db.js +158 -0
- package/routes/index.js +28 -0
- package/routes/nppBackup/sql.js.2024-07-08_082213.bak +25 -0
- package/routes/nppBackup/sql.js.2024-07-08_082214.bak +25 -0
- package/routes/sql.js +25 -0
- package/routes/switch.js +28 -0
- package/routes/switch1.js +12 -0
- package/views/addstu.ejs +276 -0
- package/views/error.ejs +4 -0
- package/views/hisinfo.ejs +301 -0
- package/views/hisinfo1.ejs +301 -0
- package/views/login.ejs +203 -0
- package/views/modroom.ejs +405 -0
- package/views/modstu.ejs +327 -0
- package/views/rtinfo.ejs +234 -0
- package/views/rtinfo1.ejs +234 -0
package/routes/api.js
ADDED
@@ -0,0 +1,505 @@
|
|
1
|
+
var express = require('express');
|
2
|
+
var router = express.Router();
|
3
|
+
|
4
|
+
// const bodyParser = require('body-parser');
|
5
|
+
const app = express();
|
6
|
+
app.use(express.json());
|
7
|
+
|
8
|
+
|
9
|
+
const db = require('./sql.js');
|
10
|
+
const EventEmitter = require('events'); //引入事件模块
|
11
|
+
var flag = 0;
|
12
|
+
var flag1 = 0;
|
13
|
+
var mac1;
|
14
|
+
var attend;
|
15
|
+
var bt = '1970-01-01 00:00:00';
|
16
|
+
var et = '2100-01-01 00:00:00';
|
17
|
+
var btrt = '1970-01-01 00:00:00';
|
18
|
+
var etrt = '1970-01-01 00:00:00';
|
19
|
+
var qdt = "";
|
20
|
+
var mem = "%";
|
21
|
+
var rom = "%";
|
22
|
+
var adm = "%";
|
23
|
+
var normal = 0;
|
24
|
+
var late = 0;
|
25
|
+
|
26
|
+
const myEmitter = new EventEmitter.EventEmitter();//创建EventEmitter对象用于监听
|
27
|
+
// const myEmitterRcvJsonData = new EventEmitter.EventEmitter();//创建EventEmitter对象用于监听
|
28
|
+
//注册seen事件用于监视
|
29
|
+
|
30
|
+
myEmitter.on('seen', () => {//签到成功
|
31
|
+
flag = 1;
|
32
|
+
});
|
33
|
+
myEmitter.on('seen1', () => {//重复刷卡
|
34
|
+
flag = 2;
|
35
|
+
});
|
36
|
+
router.get('/check', function (req, res) {
|
37
|
+
res.send({ 'status': 'success', 'flag': flag, 'id': attend, 'flag1': flag1 });
|
38
|
+
flag = 0;
|
39
|
+
flag1 = 1;
|
40
|
+
});
|
41
|
+
|
42
|
+
router.get('/chartcheck', function (req, res) {
|
43
|
+
res.send({ 'status': 'success', 'la': late, 'no': normal });
|
44
|
+
});
|
45
|
+
|
46
|
+
|
47
|
+
// router.post('http://10.1.183.144:8080/', (req, res, next) => {
|
48
|
+
// let data = '';
|
49
|
+
|
50
|
+
// req.on('data', chunk => {
|
51
|
+
// data += chunk;
|
52
|
+
// console.log(data);
|
53
|
+
// });
|
54
|
+
|
55
|
+
// req.on('end', () => {
|
56
|
+
// const jsonData = JSON.parse(data);
|
57
|
+
|
58
|
+
// var mac = jsonData.mac;
|
59
|
+
// console.log('mac::::::' + mac);
|
60
|
+
// var uid = jsonData.uid;
|
61
|
+
// console.log('uid::::::' + uid);
|
62
|
+
// });
|
63
|
+
// });
|
64
|
+
|
65
|
+
router.post('/macroomslist', (req, res, next) => {
|
66
|
+
let dataAccumulator = ''; // 使用累加器变量
|
67
|
+
|
68
|
+
req.on('data', chunk => {
|
69
|
+
dataAccumulator += chunk; // 累加数据块
|
70
|
+
console.log(dataAccumulator);
|
71
|
+
});
|
72
|
+
|
73
|
+
req.on('end', () => {
|
74
|
+
try {
|
75
|
+
const jsonData = JSON.parse(dataAccumulator); // 使用累加器解析JSON
|
76
|
+
var mac = jsonData.mac;
|
77
|
+
|
78
|
+
var aaa = '%' + mac + '%';
|
79
|
+
db.query('SELECT * FROM rooms WHERE mac LIKE ? ORDER BY id DESC;', [aaa], (err, rows) => {
|
80
|
+
if (err) {
|
81
|
+
console.error('Database query error:', err);
|
82
|
+
res.status(500).json({ error: 'Internal server error' }); // 使用res.json()发送错误信息
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
if (!rows || rows.length === 0) {
|
86
|
+
res.json({ msg: "No data found" }); // 使用res.json()发送消息
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
|
90
|
+
let user = {
|
91
|
+
id: rows[0].id.toString(), // 将id转换为字符串
|
92
|
+
num: rows[0].num.toString(), // 将num转换为字符串
|
93
|
+
mac: rows[0].mac
|
94
|
+
};
|
95
|
+
|
96
|
+
res.json(user); // 使用res.json()发送用户信息
|
97
|
+
console.log(user);
|
98
|
+
});
|
99
|
+
} catch (e) {
|
100
|
+
console.error('Error parsing JSON:', e);
|
101
|
+
res.status(400).json({ error: 'Bad request' }); // 使用res.json()发送错误信息
|
102
|
+
}
|
103
|
+
});
|
104
|
+
});
|
105
|
+
router.post('/', (req, res, next) => {
|
106
|
+
let data = '';
|
107
|
+
req.on('data', chunk => {
|
108
|
+
data += chunk;
|
109
|
+
console.log(data);
|
110
|
+
});
|
111
|
+
|
112
|
+
req.on('end', () => {
|
113
|
+
const jsonData = JSON.parse(data);
|
114
|
+
|
115
|
+
var mac = jsonData.mac;
|
116
|
+
var uid = jsonData.uid;
|
117
|
+
|
118
|
+
console.log(mac);
|
119
|
+
console.log(uid);
|
120
|
+
var aaa = '%' + uid + '%';
|
121
|
+
db.query('SELECT * FROM members WHERE cardid LIKE ?;', aaa, (err, rows) => {
|
122
|
+
if (rows[0]) {
|
123
|
+
var bbb = '%' + mac + '%';
|
124
|
+
var ccc = '%' + rows[0].stuid + '%';
|
125
|
+
db.query('SELECT * FROM rooms WHERE mac LIKE ?;', bbb, (err, rooms) => {
|
126
|
+
if (rooms == "") {
|
127
|
+
let user = {
|
128
|
+
result: "failed",
|
129
|
+
mes: "",
|
130
|
+
reason: "wrong room"
|
131
|
+
}
|
132
|
+
console.log(user);
|
133
|
+
res.send(user);
|
134
|
+
}
|
135
|
+
else {
|
136
|
+
var date = new Date();
|
137
|
+
var year = date.getFullYear();
|
138
|
+
var month = date.getMonth() + 1;
|
139
|
+
month = month < 10 ? ('0' + month) : month;
|
140
|
+
var day = date.getDate();
|
141
|
+
day = day < 10 ? ('0' + day) : day;
|
142
|
+
var hour = date.getHours();
|
143
|
+
hour = hour < 10 ? ('0' + hour) : hour;
|
144
|
+
var minute = date.getMinutes();
|
145
|
+
minute = minute < 10 ? ('0' + minute) : minute;
|
146
|
+
var second = date.getSeconds();
|
147
|
+
second = second < 10 ? ('0' + second) : second;
|
148
|
+
var t0 = hour + ':' + minute + ':' + second;
|
149
|
+
var qd;
|
150
|
+
// console.log(qdt);
|
151
|
+
|
152
|
+
if (qdt != "") {
|
153
|
+
// console.log(qdt);
|
154
|
+
// console.log("1111111111111111");
|
155
|
+
|
156
|
+
if (t0 > qdt) {
|
157
|
+
console.log("1111111111111111");
|
158
|
+
var t = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
|
159
|
+
qd="迟到";
|
160
|
+
db.query('INSERT INTO records (stuid,name,type,room,time,qd) VALUES (?,?,?,?,?,?);', [rows[0].stuid, rows[0].name, rows[0].type, rooms[0].num, t, qd], function (err, result) {
|
161
|
+
let user = {
|
162
|
+
result: "failed",
|
163
|
+
mes: req.body.id,
|
164
|
+
reason: "late"
|
165
|
+
}
|
166
|
+
console.log(user);
|
167
|
+
res.send(user);
|
168
|
+
attend = user.idcard + " " + user.name;
|
169
|
+
myEmitter.emit('seen');
|
170
|
+
});
|
171
|
+
}
|
172
|
+
else {
|
173
|
+
console.log("100000000000000000");
|
174
|
+
db.query('SELECT * FROM records WHERE stuid LIKE ?;', ccc, (err, chongf) => {
|
175
|
+
// console.log(chongf[0]);
|
176
|
+
if (chongf[0]) {
|
177
|
+
let user = {
|
178
|
+
result: "failed",
|
179
|
+
mes: "",
|
180
|
+
reason: "duplicate"
|
181
|
+
}
|
182
|
+
myEmitter.emit('seen1');
|
183
|
+
console.log("111111111111");
|
184
|
+
console.log(user);
|
185
|
+
res.send(user);
|
186
|
+
|
187
|
+
|
188
|
+
}
|
189
|
+
else {
|
190
|
+
// console.log("3333333333");
|
191
|
+
var t = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
|
192
|
+
qd="正常";
|
193
|
+
db.query('INSERT INTO records (stuid,name,type,room,time,qd) VALUES (?,?,?,?,?,?);', [rows[0].stuid, rows[0].name, rows[0].type, rooms[0].num, t, qd], function (err, result) {
|
194
|
+
let user = {
|
195
|
+
result: "success",
|
196
|
+
idcard: rows[0].stuid,
|
197
|
+
name: rows[0].name
|
198
|
+
}
|
199
|
+
console.log(user);
|
200
|
+
res.send(user);
|
201
|
+
attend = user.idcard + " " + user.name;
|
202
|
+
myEmitter.emit('seen');
|
203
|
+
});
|
204
|
+
|
205
|
+
}
|
206
|
+
});
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
}
|
213
|
+
});
|
214
|
+
}
|
215
|
+
else {
|
216
|
+
let user = {
|
217
|
+
result: "failed",
|
218
|
+
mes: req.body.id,
|
219
|
+
reason: "not found"
|
220
|
+
}
|
221
|
+
console.log(user);
|
222
|
+
res.send(user);
|
223
|
+
}
|
224
|
+
});
|
225
|
+
});
|
226
|
+
});
|
227
|
+
|
228
|
+
router.get('/', (req, res, next) => {
|
229
|
+
let user = {
|
230
|
+
result: "failed",
|
231
|
+
reason: "not found"
|
232
|
+
}
|
233
|
+
console.log(user);
|
234
|
+
res.send(user);
|
235
|
+
});
|
236
|
+
|
237
|
+
router.post('/login', (req, res, next) => {
|
238
|
+
db.query('SELECT * FROM admins WHERE username = ?;', req.body.usernameinput, (err, row) => {
|
239
|
+
if (row != "") {
|
240
|
+
if (req.body.passwordinput == row[0].password) {
|
241
|
+
if (row[0].type == 0)
|
242
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
243
|
+
else if (row[0].type == 1)
|
244
|
+
res.send({ 'status': 'success', 'sign': 3 });
|
245
|
+
|
246
|
+
}
|
247
|
+
else {
|
248
|
+
res.send({ 'status': 'success', 'sign': 1 });
|
249
|
+
}
|
250
|
+
}
|
251
|
+
else {
|
252
|
+
res.send({ 'status': 'success', 'sign': 2 });
|
253
|
+
}
|
254
|
+
});
|
255
|
+
});
|
256
|
+
|
257
|
+
router.post('/timesearchrt', (req, res, next) => {
|
258
|
+
// console.log("1111111111111111");
|
259
|
+
if (req.body.sign == 0) {
|
260
|
+
btrt = '1970-01-01 00:00:00';
|
261
|
+
etrt = '2100-01-01 00:00:00';
|
262
|
+
}
|
263
|
+
else if (req.body.sign == 1) {
|
264
|
+
btrt = req.body.bt;
|
265
|
+
etrt = req.body.et;
|
266
|
+
qdt = req.body.et;
|
267
|
+
}
|
268
|
+
else if (req.body.sign == 2) {
|
269
|
+
var time = new Date();
|
270
|
+
btrt = time.getFullYear() + '-' + ("0" + (time.getMonth() + 1)).slice(-2) + '-' + ("0" + time.getDate()).slice(-2) + ' 00:00:00';
|
271
|
+
etrt = time.getFullYear() + '-' + ("0" + (time.getMonth() + 1)).slice(-2) + '-' + ("0" + time.getDate()).slice(-2) + ' ' + req.body.et;
|
272
|
+
}
|
273
|
+
qdt = req.body.et;
|
274
|
+
// console.log(qdt);
|
275
|
+
res.send({ 'status': 'success' });
|
276
|
+
});
|
277
|
+
|
278
|
+
router.post('/timesearch', (req, res, next) => {
|
279
|
+
if (req.body.sign == 0) {
|
280
|
+
bt = '1970-01-01 00:00:00';
|
281
|
+
et = '2100-01-01 00:00:00';
|
282
|
+
}
|
283
|
+
else if (req.body.sign == 1) {
|
284
|
+
bt = req.body.bt;
|
285
|
+
et = req.body.et;
|
286
|
+
}
|
287
|
+
|
288
|
+
res.send({ 'status': 'success', 'la': late, 'no': normal });
|
289
|
+
});
|
290
|
+
|
291
|
+
router.post('/qdtime', (req, res, next) => {
|
292
|
+
if (req.body.sign == 0) {
|
293
|
+
qdt = "";
|
294
|
+
}
|
295
|
+
else {
|
296
|
+
qdt = req.body.time_h + ':' + req.body.time_m + ':' + req.body.time_s;
|
297
|
+
}
|
298
|
+
res.send({ 'status': 'success', 'la': late, 'no': normal });
|
299
|
+
});
|
300
|
+
|
301
|
+
router.post('/idsearch', (req, res, next) => {
|
302
|
+
if (req.body.sign == 0) {
|
303
|
+
mem = "%";
|
304
|
+
}
|
305
|
+
else {
|
306
|
+
mem = "%" + req.body.id + "%";
|
307
|
+
}
|
308
|
+
|
309
|
+
res.send({ 'status': 'success' });
|
310
|
+
});
|
311
|
+
|
312
|
+
router.post('/roomsearch', (req, res, next) => {
|
313
|
+
if (req.body.sign == 0) {
|
314
|
+
rom = "%";
|
315
|
+
}
|
316
|
+
else {
|
317
|
+
rom = "%" + req.body.id + "%";
|
318
|
+
}
|
319
|
+
res.send({ 'status': 'success' });
|
320
|
+
});
|
321
|
+
|
322
|
+
router.post('/adminsearch', (req, res, next) => {
|
323
|
+
if (req.body.sign == 0) {
|
324
|
+
adm = "%";
|
325
|
+
}
|
326
|
+
else {
|
327
|
+
adm = "%" + req.body.id + "%";
|
328
|
+
}
|
329
|
+
res.send({ 'status': 'success' });
|
330
|
+
});
|
331
|
+
|
332
|
+
router.post('/inputcheck0', (req, res, next) => {
|
333
|
+
db.query('SELECT * FROM members WHERE stuid = ?;', req.body.idinput, (err, row) => {
|
334
|
+
if (row != "") {
|
335
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
336
|
+
}
|
337
|
+
else res.send({ 'status': 'success', 'sign': 1 });
|
338
|
+
});
|
339
|
+
});
|
340
|
+
|
341
|
+
router.post('/inputcheck1', (req, res, next) => {
|
342
|
+
var idinput = "%" + req.body.idinput + ";%";
|
343
|
+
db.query('SELECT * FROM members WHERE cardid LIKE ? OR cardid = ?;', [idinput, req.body.idinput], (err, row) => {
|
344
|
+
if (row != "") {
|
345
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
346
|
+
}
|
347
|
+
else res.send({ 'status': 'success', 'sign': 1 });
|
348
|
+
});
|
349
|
+
});
|
350
|
+
|
351
|
+
router.post('/inputcheck2', (req, res, next) => {
|
352
|
+
db.query('SELECT * FROM rooms WHERE num = ?;', req.body.idinput, (err, row) => {
|
353
|
+
if (row != "") {
|
354
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
355
|
+
}
|
356
|
+
else res.send({ 'status': 'success', 'sign': 1 });
|
357
|
+
});
|
358
|
+
});
|
359
|
+
|
360
|
+
router.post('/inputcheck3', (req, res, next) => {
|
361
|
+
var idinput = "%" + req.body.idinput + ";%";
|
362
|
+
db.query('SELECT * FROM rooms WHERE mac LIKE ? OR mac = ?;', [idinput, req.body.idinput], (err, row) => {
|
363
|
+
if (row != "") {
|
364
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
365
|
+
}
|
366
|
+
else res.send({ 'status': 'success', 'sign': 1 });
|
367
|
+
});
|
368
|
+
});
|
369
|
+
|
370
|
+
router.post('/inputcheck4', (req, res, next) => {
|
371
|
+
db.query('SELECT * FROM admins WHERE username = ?;', req.body.usernameinput, (err, row) => {
|
372
|
+
if (row != "") {
|
373
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
374
|
+
}
|
375
|
+
else res.send({ 'status': 'success', 'sign': 1 });
|
376
|
+
});
|
377
|
+
});
|
378
|
+
|
379
|
+
router.get('/list', (req, res, next) => {
|
380
|
+
db.query('SELECT * FROM members WHERE stuid LIKE ? ORDER BY id DESC;', mem, (err, rows) => {
|
381
|
+
let rets = [];
|
382
|
+
if (rows) {
|
383
|
+
rows.forEach(row => {
|
384
|
+
let user = {
|
385
|
+
id: row.id,
|
386
|
+
stuid: row.stuid,
|
387
|
+
name: row.name,
|
388
|
+
cardid: row.cardid,
|
389
|
+
type: row.type
|
390
|
+
}
|
391
|
+
rets.push(user);
|
392
|
+
});
|
393
|
+
let retdata = {
|
394
|
+
code: 0,
|
395
|
+
msg: "",
|
396
|
+
count: 10,
|
397
|
+
data: rets
|
398
|
+
}
|
399
|
+
res.send(JSON.stringify(retdata));
|
400
|
+
}
|
401
|
+
});
|
402
|
+
});
|
403
|
+
|
404
|
+
router.get('/recordlistrt', (req, res, next) => {
|
405
|
+
late = 0; normal = 0;
|
406
|
+
sw = 'SELECT * FROM records WHERE time BETWEEN \'' + btrt + '\' AND \'' + etrt + '\' ORDER BY time DESC;'
|
407
|
+
db.query(sw, (err, rows) => {
|
408
|
+
let rets = [];
|
409
|
+
rows.forEach(row => {
|
410
|
+
let user = {
|
411
|
+
id: row.id,
|
412
|
+
stuid: row.stuid,
|
413
|
+
name: row.name,
|
414
|
+
type: row.type,
|
415
|
+
room: row.room,
|
416
|
+
time: row.time
|
417
|
+
}
|
418
|
+
rets.push(user);
|
419
|
+
});
|
420
|
+
let retdata = {
|
421
|
+
code: 0,
|
422
|
+
msg: "",
|
423
|
+
count: 10,
|
424
|
+
data: rets
|
425
|
+
}
|
426
|
+
res.send(JSON.stringify(retdata));
|
427
|
+
});
|
428
|
+
});
|
429
|
+
|
430
|
+
router.get('/recordlist', (req, res, next) => {
|
431
|
+
late = 0; normal = 0;
|
432
|
+
var stuid = req.query.stuid || "%";
|
433
|
+
var room = req.query.room || "%";
|
434
|
+
sw = 'SELECT * FROM records WHERE stuid LIKE ? AND room LIKE ? AND time BETWEEN \'' + bt + '\' AND \'' + et + '\' ORDER BY time DESC;';
|
435
|
+
db.query(sw, [stuid, room], (err, rows) => {
|
436
|
+
let rets = [];
|
437
|
+
rows.forEach(row => {
|
438
|
+
let user = {
|
439
|
+
id: row.id,
|
440
|
+
stuid: row.stuid,
|
441
|
+
name: row.name,
|
442
|
+
type: row.type,
|
443
|
+
room: row.room,
|
444
|
+
time: row.time,
|
445
|
+
qd: row.qd
|
446
|
+
}
|
447
|
+
if (user.qd == '迟到') {
|
448
|
+
late = late + 1;
|
449
|
+
}
|
450
|
+
else normal = normal + 1;
|
451
|
+
rets.push(user);
|
452
|
+
});
|
453
|
+
let retdata = {
|
454
|
+
code: 0,
|
455
|
+
msg: "",
|
456
|
+
count: 10,
|
457
|
+
data: rets
|
458
|
+
}
|
459
|
+
res.send(JSON.stringify(retdata));
|
460
|
+
});
|
461
|
+
});
|
462
|
+
|
463
|
+
router.get('/roomslist', (req, res, next) => {
|
464
|
+
db.query('SELECT * FROM rooms WHERE num LIKE ? ORDER BY id DESC;', rom, (err, rows) => {
|
465
|
+
let rets = [];
|
466
|
+
rows.forEach(row => {
|
467
|
+
let user = {
|
468
|
+
id: row.id,
|
469
|
+
num: row.num,
|
470
|
+
mac: row.mac
|
471
|
+
}
|
472
|
+
rets.push(user);
|
473
|
+
});
|
474
|
+
let retdata = {
|
475
|
+
code: 0,
|
476
|
+
msg: "",
|
477
|
+
count: 10,
|
478
|
+
data: rets
|
479
|
+
}
|
480
|
+
res.send(JSON.stringify(retdata));
|
481
|
+
});
|
482
|
+
});
|
483
|
+
|
484
|
+
router.get('/adminslist', (req, res, next) => {
|
485
|
+
db.query('SELECT * FROM admins WHERE username LIKE ? ORDER BY id DESC;', adm, (err, rows) => {
|
486
|
+
let rets = [];
|
487
|
+
rows.forEach(row => {
|
488
|
+
let user = {
|
489
|
+
id: row.id,
|
490
|
+
username: row.username,
|
491
|
+
password: row.password
|
492
|
+
}
|
493
|
+
rets.push(user);
|
494
|
+
});
|
495
|
+
let retdata = {
|
496
|
+
code: 0,
|
497
|
+
msg: "",
|
498
|
+
count: 10,
|
499
|
+
data: rets
|
500
|
+
}
|
501
|
+
res.send(JSON.stringify(retdata));
|
502
|
+
});
|
503
|
+
});
|
504
|
+
|
505
|
+
module.exports = router;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
var express = require('express');
|
2
|
+
var router = express.Router();
|
3
|
+
|
4
|
+
const app = express();
|
5
|
+
app.use(express.json());
|
6
|
+
|
7
|
+
router.post('/', (req, res, next) => {
|
8
|
+
var datetime = new Date()
|
9
|
+
DT = {
|
10
|
+
date: datetime.toLocaleDateString(),
|
11
|
+
time: datetime.toLocaleTimeString(),
|
12
|
+
}
|
13
|
+
res.send(JSON.stringify(DT))
|
14
|
+
});
|
15
|
+
|
16
|
+
module.exports = router;
|
17
|
+
|
package/routes/db.js
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
var express = require('express');
|
2
|
+
var router = express.Router();
|
3
|
+
const db = require('./sql.js');
|
4
|
+
|
5
|
+
router.get('/init', (req, res, next) => {
|
6
|
+
db.query('DELETE FROM records;', (err, result) => {
|
7
|
+
next();
|
8
|
+
});
|
9
|
+
}, (req, res, next) => {
|
10
|
+
res.redirect(301, '/#tab1=111');
|
11
|
+
});
|
12
|
+
|
13
|
+
// POST 请求来处理用户注册
|
14
|
+
router.post('/register', (req, res, next) => {
|
15
|
+
const { username, password} = req.body; // 从请求体获取用户名和密码
|
16
|
+
console.log({ username, password });
|
17
|
+
// 检查用户名是否已经存在
|
18
|
+
|
19
|
+
// 插入新用户,type 固定为 1
|
20
|
+
db.query('INSERT INTO admins (username, password, type) VALUES (?, ?, 1)', [username, password], (err, result) => {
|
21
|
+
if (err) {
|
22
|
+
console.error('Error inserting new user', err);
|
23
|
+
return res.status(500).send({ status: 'error', message: 'Failed to register user' });
|
24
|
+
}
|
25
|
+
|
26
|
+
// 注册成功
|
27
|
+
res.send({ status: 'success', message: 'User registered successfully' });
|
28
|
+
});
|
29
|
+
|
30
|
+
});
|
31
|
+
|
32
|
+
router.post('/insert_user', (req, res, next) => {
|
33
|
+
db.query('INSERT INTO members (stuid,name,cardid,type) VALUES (?,?,?,?);', [req.body.insertstuid, req.body.insertname, req.body.insertcardid, req.body.inserttype], function (err, result) {
|
34
|
+
if (err == null) {
|
35
|
+
res.send({ 'status': 'ok', 'err': null });
|
36
|
+
} else {
|
37
|
+
console.log('insert user failed, the reason is ' + err);
|
38
|
+
res.send({ 'status': 'error', 'err': err.toString() });
|
39
|
+
}
|
40
|
+
});
|
41
|
+
});
|
42
|
+
|
43
|
+
router.post('/insert_room', (req, res, next) => {
|
44
|
+
db.query('INSERT INTO rooms (num,mac) VALUES (?,?);', [req.body.insertnum, req.body.insertmac], function (err, result) {
|
45
|
+
if (err == null) {
|
46
|
+
res.send({ 'status': 'ok', 'err': null });
|
47
|
+
} else {
|
48
|
+
console.log('insert user failed, the reason is ' + err);
|
49
|
+
res.send({ 'status': 'error', 'err': err.toString() });
|
50
|
+
}
|
51
|
+
});
|
52
|
+
});
|
53
|
+
|
54
|
+
router.post('/insert_admin', (req, res, next) => {
|
55
|
+
db.query('INSERT INTO admins (username,password) VALUES (?,?);', [req.body.insertusername, req.body.insertpassword], function (err, result) {
|
56
|
+
if (err == null) {
|
57
|
+
res.send('ok');
|
58
|
+
} else {
|
59
|
+
console.log('insert user failed, the reason is ' + err);
|
60
|
+
res.send('error');
|
61
|
+
}
|
62
|
+
});
|
63
|
+
});
|
64
|
+
|
65
|
+
router.post('/delete_users', (req, res, next) => {
|
66
|
+
var id = parseInt(req.body.id);
|
67
|
+
db.query('DELETE FROM members WHERE id = ?', id, function (err, result) {
|
68
|
+
if (err) {
|
69
|
+
console.log(err);
|
70
|
+
} else {
|
71
|
+
res.send({ 'status': 'success' });
|
72
|
+
}
|
73
|
+
});
|
74
|
+
});
|
75
|
+
|
76
|
+
router.post('/delete_rooms', (req, res, next) => {
|
77
|
+
var id = parseInt(req.body.id);
|
78
|
+
db.query('DELETE FROM rooms WHERE id = ?', id, function (err, result) {
|
79
|
+
if (err) {
|
80
|
+
console.log(err);
|
81
|
+
} else {
|
82
|
+
res.send({ 'status': 'success' });
|
83
|
+
}
|
84
|
+
});
|
85
|
+
});
|
86
|
+
|
87
|
+
router.post('/delete_admins', (req, res, next) => {
|
88
|
+
var id = parseInt(req.body.id);
|
89
|
+
db.query('DELETE FROM admins WHERE id = ?', id, function (err, result) {
|
90
|
+
if (err) {
|
91
|
+
console.log(err);
|
92
|
+
} else {
|
93
|
+
res.send({ 'status': 'success' });
|
94
|
+
}
|
95
|
+
});
|
96
|
+
});
|
97
|
+
|
98
|
+
router.post('/update_users', (req, res, next) => {
|
99
|
+
var stuid = req.body.stuid;
|
100
|
+
var name = req.body.name;
|
101
|
+
var cardid = req.body.cardid;
|
102
|
+
var type = req.body.type;
|
103
|
+
db.query('SELECT * FROM members WHERE cardid =?', req.body.cardid, function (error, row) {
|
104
|
+
if (error) {
|
105
|
+
console.error(error);
|
106
|
+
}
|
107
|
+
else {
|
108
|
+
if (row.length > 0) {
|
109
|
+
db.query('UPDATE members SET name = ?, type = ? WHERE stuid =?', [name, type, stuid], function (err, result) {
|
110
|
+
if (err == null) {
|
111
|
+
res.send({ 'status': 'ok', 'err': null });
|
112
|
+
} else {
|
113
|
+
console.log('insert user failed, the reason is ' + err);
|
114
|
+
res.send({ 'status': 'error', 'err': err.toString() });
|
115
|
+
}
|
116
|
+
});
|
117
|
+
}
|
118
|
+
else {
|
119
|
+
db.query('UPDATE members SET cardid = ?, name = ?, type = ? WHERE stuid =?', [cardid, name, type, stuid], function (err, result) {
|
120
|
+
if (err == null) {
|
121
|
+
res.send({ 'status': 'ok', 'err': null });
|
122
|
+
} else {
|
123
|
+
console.log('insert user failed, the reason is ' + err);
|
124
|
+
res.send({ 'status': 'error', 'err': err.toString() });
|
125
|
+
}
|
126
|
+
});
|
127
|
+
}
|
128
|
+
}
|
129
|
+
});
|
130
|
+
|
131
|
+
|
132
|
+
});
|
133
|
+
|
134
|
+
router.post('/update_rooms', (req, res, next) => {
|
135
|
+
db.query('UPDATE rooms SET mac = ? WHERE num =?', [req.body.mac, req.body.num]);
|
136
|
+
res.send({ 'status': 'ok' });
|
137
|
+
});
|
138
|
+
|
139
|
+
router.post('/update_admins', (req, res, next) => {
|
140
|
+
db.query('SELECT * FROM admins WHERE username = ?;', req.body.oldusername, (err, row) => {
|
141
|
+
if (req.body.oldpassword == row[0].password) {
|
142
|
+
if (req.body.newpassword == '') {
|
143
|
+
db.query('UPDATE admins SET username = ? WHERE id = ?', [req.body.newusername, req.body.id]);
|
144
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
145
|
+
}
|
146
|
+
else {
|
147
|
+
db.query('UPDATE admins SET username = ?, password = ? WHERE id = ?', [req.body.newusername, req.body.newpassword, req.body.id]);
|
148
|
+
res.send({ 'status': 'success', 'sign': 0 });
|
149
|
+
}
|
150
|
+
}
|
151
|
+
else {
|
152
|
+
res.send({ 'status': 'success', 'sign': 1 });
|
153
|
+
}
|
154
|
+
});
|
155
|
+
});
|
156
|
+
|
157
|
+
|
158
|
+
module.exports = router;
|