@shun-js/user 0.4.6 → 0.4.7

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.4.6",
3
+ "version": "0.4.7",
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": "a3707c20f4632d54ba051ff2431e667128bc9782"
37
+ "gitHead": "20a5ae6b1ee92ec8088d4cb65848ee8a0754e807"
38
38
  }
@@ -22,15 +22,15 @@ exports.isUserInfoExists = async (req, res, id) => {
22
22
  };
23
23
 
24
24
  /**
25
- * addUserInfo
25
+ * addUserInfoByGithub
26
26
  * @param {*} req
27
27
  * @param {*} res
28
28
  * @param {*} userItemId
29
29
  * @param {*} githubUserinfo
30
30
  * @returns
31
31
  */
32
- exports.addUserInfo = async (req, res, userItemId, githubUserinfo) => {
33
- const methodName = 'addUserInfo';
32
+ exports.addUserInfoByGithub = async (req, res, userItemId, githubUserinfo) => {
33
+ const methodName = 'addUserInfoByGithub';
34
34
 
35
35
  // add user item
36
36
  try {
@@ -47,6 +47,32 @@ exports.addUserInfo = async (req, res, userItemId, githubUserinfo) => {
47
47
  }
48
48
  };
49
49
 
50
+ /**
51
+ * addUserInfoByGoogle
52
+ * @param {*} req
53
+ * @param {*} res
54
+ * @param {*} userItemId
55
+ * @param {*} googleUserinfo
56
+ * @returns
57
+ */
58
+ exports.addUserInfoByGoogle = async (req, res, userItemId, googleUserinfo) => {
59
+ const methodName = 'addUserInfoByGoogle';
60
+
61
+ // add user item
62
+ try {
63
+ // add user
64
+ const params = [userItemId, googleUserinfo.name, googleUserinfo.picture, googleUserinfo.email];
65
+ await req.db.query(sql.addUserInfo, params);
66
+
67
+ // r
68
+ return true;
69
+ } catch (error) {
70
+ const msg = '添加用户失败!';
71
+ req.logger.error(methodName, msg, error.name, error.message);
72
+ res.jsonFail(msg);
73
+ }
74
+ };
75
+
50
76
  /**
51
77
  * getUserInfoById
52
78
  * @param {*} req
@@ -1,5 +1,5 @@
1
1
  // model
2
- const { addUserInfo, isUserInfoExists } = require('../model/UserInfoModel.js');
2
+ const { addUserInfoByGithub, isUserInfoExists } = require('../model/UserInfoModel.js');
3
3
 
4
4
  // github
5
5
  const { getGithubUserinfo } = require('../util/github.js');
@@ -45,7 +45,7 @@ exports.userGithub = async (req, res) => {
45
45
  const isUserInfoExistsRes = await isUserInfoExists(req, res, userItem.id);
46
46
  if (!isUserInfoExistsRes) return;
47
47
  if (isUserInfoExistsRes.length === 0) {
48
- const addUserInfoRes = await addUserInfo(req, res, userItem.id, githubUserinfo);
48
+ const addUserInfoRes = await addUserInfoByGithub(req, res, userItem.id, githubUserinfo);
49
49
  if (!addUserInfoRes) return;
50
50
  }
51
51
 
@@ -1,5 +1,5 @@
1
1
  // model
2
- const { addUserInfo, isUserInfoExists } = require('../model/UserInfoModel.js');
2
+ const { addUserInfoByGoogle, isUserInfoExists } = require('../model/UserInfoModel.js');
3
3
 
4
4
  // google
5
5
  const { getGoogleUserinfo } = require('../util/google.js');
@@ -45,7 +45,7 @@ exports.userGoogle = async (req, res) => {
45
45
  const isUserInfoExistsRes = await isUserInfoExists(req, res, userItem.id);
46
46
  if (!isUserInfoExistsRes) return;
47
47
  if (isUserInfoExistsRes.length === 0) {
48
- const addUserInfoRes = await addUserInfo(req, res, userItem.id, googleUserinfo);
48
+ const addUserInfoRes = await addUserInfoByGoogle(req, res, userItem.id, googleUserinfo);
49
49
  if (!addUserInfoRes) return;
50
50
  }
51
51
 
@@ -76,50 +76,11 @@ exports.getGoogleUserinfo = async (req, code) => {
76
76
  };
77
77
 
78
78
  // {
79
- // login: 'uikoo9',
80
- // id: 10345351,
81
- // node_id: 'MDQ6VXNlcjEwMzQ1MzUx',
82
- // avatar_url: 'https://avatars.githubusercontent.com/u/10345351?v=4',
83
- // gravatar_id: '',
84
- // url: 'https://api.github.com/users/uikoo9',
85
- // html_url: 'https://github.com/uikoo9',
86
- // followers_url: 'https://api.github.com/users/uikoo9/followers',
87
- // following_url: 'https://api.github.com/users/uikoo9/following{/other_user}',
88
- // gists_url: 'https://api.github.com/users/uikoo9/gists{/gist_id}',
89
- // starred_url: 'https://api.github.com/users/uikoo9/starred{/owner}{/repo}',
90
- // subscriptions_url: 'https://api.github.com/users/uikoo9/subscriptions',
91
- // organizations_url: 'https://api.github.com/users/uikoo9/orgs',
92
- // repos_url: 'https://api.github.com/users/uikoo9/repos',
93
- // events_url: 'https://api.github.com/users/uikoo9/events{/privacy}',
94
- // received_events_url: 'https://api.github.com/users/uikoo9/received_events',
95
- // type: 'User',
96
- // user_view_type: 'private',
97
- // site_admin: false,
98
- // name: null,
99
- // company: null,
100
- // blog: '',
101
- // location: null,
102
- // email: 'uikoo9@qq.com',
103
- // hireable: null,
104
- // bio: null,
105
- // twitter_username: null,
106
- // notification_email: 'uikoo9@qq.com',
107
- // public_repos: 27,
108
- // public_gists: 0,
109
- // followers: 91,
110
- // following: 4,
111
- // created_at: '2014-12-30T03:11:05Z',
112
- // updated_at: '2026-01-29T09:08:41Z',
113
- // private_gists: 0,
114
- // total_private_repos: 33,
115
- // owned_private_repos: 33,
116
- // disk_usage: 1026748,
117
- // collaborators: 4,
118
- // two_factor_authentication: true,
119
- // plan: {
120
- // name: 'free',
121
- // space: 976562499,
122
- // collaborators: 0,
123
- // private_repos: 10000
124
- // }
79
+ // sub: '113888573080949768314',
80
+ // name: 'vincent v',
81
+ // given_name: 'vincent',
82
+ // family_name: 'v',
83
+ // picture: 'https://lh3.googleusercontent.com/a/ACg8ocIeChCoXJwZ4Yqsa9g3wn7iw54hF1qEg6Aqm4p3QiBjBRJV5mD6=s96-c',
84
+ // email: 'uikoo9@gmail.com',
85
+ // email_verified: true
125
86
  // }