@shun-js/user 0.3.8 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shun-js/user",
3
- "version": "0.3.8",
3
+ "version": "0.4.0",
4
4
  "description": "user",
5
5
  "keywords": [
6
6
  "shun.js",
@@ -34,5 +34,5 @@
34
34
  "access": "public",
35
35
  "registry": "https://registry.npmjs.org/"
36
36
  },
37
- "gitHead": "47da7a9c11787350795ddd69747acc5fc2437134"
37
+ "gitHead": "7e605c386a8e569bac8d94872603e2fcda2b3ae0"
38
38
  }
@@ -0,0 +1,48 @@
1
+ // sql
2
+ const sql = require('../sql/UserInfoSQL.js');
3
+
4
+ /**
5
+ * getUserInfoById
6
+ * @param {*} req
7
+ * @param {*} res
8
+ * @param {*} id
9
+ * @returns
10
+ */
11
+ exports.getUserInfoById = async (req, res, id) => {
12
+ const methodName = 'getUserInfoById';
13
+
14
+ // get user item
15
+ try {
16
+ return await req.db.query(sql.getUserInfoById, [id]);
17
+ } catch (error) {
18
+ const msg = '获取用户信息失败!';
19
+ req.logger.error(methodName, msg, error.name, error.message);
20
+ res.jsonFail(msg);
21
+ }
22
+ };
23
+
24
+ /**
25
+ * addUserInfo
26
+ * @param {*} req
27
+ * @param {*} res
28
+ * @param {*} userItemId
29
+ * @param {*} githubUserinfo
30
+ * @returns
31
+ */
32
+ exports.addUserInfo = async (req, res, userItemId, githubUserinfo) => {
33
+ const methodName = 'addUserInfo';
34
+
35
+ // add user item
36
+ try {
37
+ // add user
38
+ const params = [userItemId, githubUserinfo.login, githubUserinfo.avatar_url, githubUserinfo.email];
39
+ await req.db.query(sql.addUserInfo, params);
40
+
41
+ // r
42
+ return true;
43
+ } catch (error) {
44
+ const msg = '添加用户失败!';
45
+ req.logger.error(methodName, msg, error.name, error.message);
46
+ res.jsonFail(msg);
47
+ }
48
+ };
@@ -43,7 +43,7 @@ exports.addUserItem = async (req, res, mobile) => {
43
43
  req.logger.info(methodName, 'encryptPassword', encryptPassword);
44
44
 
45
45
  // add user
46
- const addUserItemRes = await req.db.query(sql.addUserItem, [mobile, encryptPassword, global.QZ_CONFIG.user.from]);
46
+ const addUserItemRes = await req.db.query(sql.addUserItem, [mobile, encryptPassword, req.body.from || 'null']);
47
47
 
48
48
  // userItem
49
49
  const userItem = {
@@ -1,3 +1,6 @@
1
+ // model
2
+ const { getUserInfoById, addUserInfo } = require('../model/UserInfoModel.js');
3
+
1
4
  // github
2
5
  const { getGithubUserinfo } = require('../util/github.js');
3
6
 
@@ -38,6 +41,14 @@ exports.userGithub = async (req, res) => {
38
41
  if (!userItem) return;
39
42
  req.logger.info(methodName, 'github login or reg ok');
40
43
 
44
+ // user info
45
+ const getUserInfoByIdRes = await getUserInfoById(req, res, userItem.id);
46
+ if (!getUserInfoByIdRes) return;
47
+ if (getUserInfoByIdRes.length === 0) {
48
+ const addUserInfoRes = await addUserInfo(req, res, userItem.id, githubUserinfo);
49
+ if (!addUserInfoRes) return;
50
+ }
51
+
41
52
  // r
42
53
  const finalUser = {
43
54
  userid: userItem.id,
@@ -0,0 +1,17 @@
1
+ exports.getUserInfoById = `
2
+ select
3
+ *
4
+ from
5
+ t_user_info
6
+ where
7
+ user_item_id=1
8
+ and
9
+ del_tag='0'
10
+ `;
11
+
12
+ exports.addUserInfo = `
13
+ insert into
14
+ t_user_info
15
+ values
16
+ (null, ?, ?, ?, ?, now(), '0')
17
+ `;