zengyicheng 1 tahun lalu
induk
melakukan
41b2dca168
1 mengubah file dengan 62 tambahan dan 35 penghapusan
  1. 62 35
      ssti.js

+ 62 - 35
ssti.js

@@ -614,47 +614,74 @@ router.get("/getProjectBookData", (req, res) => {
     QMysql(req, res, "select_ProjectBookData")
 })
 
+function getUid(str) {
+    const variables = str.split(";");
+    const values = {}
+
+    for (var i = 0; i < variables.length; i++) {
+        const noSpace = variables[i].trim(); // 去变量两端的空格
+        const [key, value] = noSpace.split("="); //将变量分割成健和值
+        values[key] = value;
+    }
+
+    return values['vue_admin_template_token'];
+}
+
 //qgt 用户登录后获取数据,如果数据库没有这个人则添加数据
 router.post('/userLogin', (req, res) => {
     let data = GetData(req);
-    //查询用户的数据
-    mysql.usselect([_mysqlLabor[0], _mysqlLabor[1], 'select_UserByUserId', data['id']], function(ret) {
-        if (ret[0].length == 0) { //数据库没有这个人的数据,查询学生表或者老师表获取数据
-            mysql.usselect([_mysqlLabor[0], _mysqlLabor[1], 'select_UserMessageById', data['id']], (ret2) => {
-                let userData = {};
-                // console.log(ret2);
-                if (ret2[0].length) {
-                    userData = ret2[0][0];
-                    userData['type'] = 2
-                } //学生数据
-                else if (ret2[1].length) {
-                    userData = ret2[1][0]
-                    userData['zymc'] = '';
-                    userData['type'] = 1; //老师数据
-                };
-                // console.log(userData);
-                // console.log();
-                let bm = '';
-                if (userData['type'] == 1) bm = userData['bm'] //因为老师部门和学生专业不一样,所以要判断用户类型进行填充user中的bm
-                if (userData['type'] == 2) bm = userData['xy']
-
-                //数据库用户表添加用户
-                mysql.usselect([_mysqlLabor[0], _mysqlLabor[1], 'insert_User', userData['id'], userData['xm'], userData['type'], bm, userData['zymc']], (ret3) => {
-                    console.log(ret3);
-                    if (ret3 == 1) {
-                        res.end(JSON.stringify({ userid: userData['id'] }))
-                    } else {
-                        res.end('ERROR')
-                    }
-
-                })
-            })
+    const str = req.headers;
+    const getUserid = getUid(str);
+
+    if (getUserid) {
+
+        if (data['id'] == getUserid) {
+
+            //查询用户的数据
+            mysql.usselect([_mysqlLabor[0], _mysqlLabor[1], 'select_UserByUserId', data['id']], function(ret) {
+                if (ret[0].length == 0) { //数据库没有这个人的数据,查询学生表或者老师表获取数据
+                    mysql.usselect([_mysqlLabor[0], _mysqlLabor[1], 'select_UserMessageById', data['id']], (ret2) => {
+                        let userData = {};
+                        // console.log(ret2);
+                        if (ret2[0].length) {
+                            userData = ret2[0][0];
+                            userData['type'] = 2
+                        } //学生数据
+                        else if (ret2[1].length) {
+                            userData = ret2[1][0]
+                            userData['zymc'] = '';
+                            userData['type'] = 1; //老师数据
+                        };
+                        // console.log(userData);
+                        // console.log();
+                        let bm = '';
+                        if (userData['type'] == 1) bm = userData['bm'] //因为老师部门和学生专业不一样,所以要判断用户类型进行填充user中的bm
+                        if (userData['type'] == 2) bm = userData['xy']
+
+                        //数据库用户表添加用户
+                        mysql.usselect([_mysqlLabor[0], _mysqlLabor[1], 'insert_User', userData['id'], userData['xm'], userData['type'], bm, userData['zymc']], (ret3) => {
+                            console.log(ret3);
+                            if (ret3 == 1) {
+                                res.end(JSON.stringify({ userid: userData['id'] }))
+                            } else {
+                                res.end('ERROR')
+                            }
+
+                        })
+                    })
+                } else {
+                    //数据库有数据
+                    res.end(JSON.stringify({...ret[0][0], remoteUser: req.headers, a: 111 }));
+                }
+
+            });
         } else {
-            //数据库有数据
-            res.end(JSON.stringify({...ret[0][0], remoteUser: req.headers, a: 111 }));
+            res.end(JSON.stringify({ a: "身份认证失败!" }));
         }
+    } else {
+        res.end(JSON.stringify({ a: "身份认证失败!" }));
+    }
 
-    });
 })
 
 //zyc 用户登录后获取数据,如果数据库没有这个人则添加数据(防止修改uid能直接获取到其他老师信息)