|
@@ -630,55 +630,50 @@ function getUid(str) {
|
|
|
//qgt 用户登录后获取数据,如果数据库没有这个人则添加数据
|
|
|
router.post('/userLogin', (req, res) => {
|
|
|
let data = GetData(req);
|
|
|
- const str = req.headers.cookie;
|
|
|
+ const str = req.headers.cookie ? req.headers.cookie : '';
|
|
|
console.log(req.headers.cookie)
|
|
|
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')
|
|
|
- }
|
|
|
-
|
|
|
- })
|
|
|
+
|
|
|
+ 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({ a: "身份认证失败!" }));
|
|
|
- }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ //数据库有数据
|
|
|
+ res.end(JSON.stringify({...ret[0][0], remoteUser: req.headers, a: 111 }));
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
} else {
|
|
|
res.end(JSON.stringify({ a: "身份认证失败!" }));
|
|
|
}
|