@abtnode/blocklet-services 1.16.11-next-a4e155ae → 1.16.11-next-a9ab0bad
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/api/routes/user.js +23 -4
- package/package.json +17 -17
package/api/routes/user.js
CHANGED
|
@@ -4,6 +4,7 @@ const { fromAppDid } = require('@arcblock/did-ext');
|
|
|
4
4
|
const { extractUserAvatar } = require('@abtnode/util/lib/user');
|
|
5
5
|
const formatContext = require('@abtnode/util/lib/format-context');
|
|
6
6
|
const logger = require('@abtnode/logger')('blocklet-services:user');
|
|
7
|
+
const { isFromPublicKey } = require('@arcblock/did');
|
|
7
8
|
|
|
8
9
|
const { generateTranslate } = require('../libs/translate');
|
|
9
10
|
const { isInvitedUserOnly } = require('../util');
|
|
@@ -14,6 +15,14 @@ const { loginWalletSchema, loginOAuthSchema } = require('../validators/login');
|
|
|
14
15
|
const verifySig = require('../middlewares/verify-sig');
|
|
15
16
|
const { getAvatarByEmail } = require('../libs/auth/utils');
|
|
16
17
|
|
|
18
|
+
const validateUser = (user) => {
|
|
19
|
+
try {
|
|
20
|
+
return user && user.did && user.pk && isFromPublicKey(user.did, user.pk);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
17
26
|
const PREFIX = WELLKNOWN_SERVICE_PATH_PREFIX;
|
|
18
27
|
|
|
19
28
|
const prefix = `${PREFIX}/user`;
|
|
@@ -22,11 +31,13 @@ const translations = {
|
|
|
22
31
|
needInviteToLogin: '你需要被邀请才可以登录此应用',
|
|
23
32
|
notAllowed: '你没有权限登录该节点',
|
|
24
33
|
needComponentId: '缺少登录参数: componentId',
|
|
34
|
+
userInfoError: '登录用户信息有误',
|
|
25
35
|
},
|
|
26
36
|
en: {
|
|
27
37
|
needInviteToLogin: 'You need to be invited to sign in to this app',
|
|
28
38
|
notAllowed: 'You are not allowed to login to this node',
|
|
29
39
|
needComponentId: 'componentId is required when login user',
|
|
40
|
+
userInfoError: 'Login user info is invalid',
|
|
30
41
|
},
|
|
31
42
|
};
|
|
32
43
|
|
|
@@ -111,7 +122,7 @@ async function loginWallet({ did, pk, avatar, email, fullName }, { node, req, lo
|
|
|
111
122
|
}
|
|
112
123
|
|
|
113
124
|
const lastLoginIp = req.get('x-real-ip');
|
|
114
|
-
const
|
|
125
|
+
const loginParams = {
|
|
115
126
|
teamDid,
|
|
116
127
|
user: {
|
|
117
128
|
did: currentUser?.did || did,
|
|
@@ -121,7 +132,11 @@ async function loginWallet({ did, pk, avatar, email, fullName }, { node, req, lo
|
|
|
121
132
|
connectedAccount: { provider, did, pk },
|
|
122
133
|
...profile,
|
|
123
134
|
},
|
|
124
|
-
}
|
|
135
|
+
};
|
|
136
|
+
if (!validateUser(loginParams.user) || !validateUser(loginParams.user.connectedAccount)) {
|
|
137
|
+
throw new ApiError(400, t('userInfoError', locale));
|
|
138
|
+
}
|
|
139
|
+
const doc = await node.loginUser(loginParams);
|
|
125
140
|
|
|
126
141
|
// NOTICE: 使用 provider: wallet 登录的账号,其账号是由 wallet 产生的,所以不需要到链上 declare 了
|
|
127
142
|
return doc;
|
|
@@ -166,7 +181,7 @@ async function loginOAuth(
|
|
|
166
181
|
|
|
167
182
|
const lastLoginIp = req.get('x-real-ip');
|
|
168
183
|
|
|
169
|
-
const
|
|
184
|
+
const loginParams = {
|
|
170
185
|
teamDid,
|
|
171
186
|
user: {
|
|
172
187
|
did: currentUser?.did || userDid,
|
|
@@ -176,7 +191,11 @@ async function loginOAuth(
|
|
|
176
191
|
connectedAccount: { provider, id, did: userDid, pk: userPk },
|
|
177
192
|
...profile,
|
|
178
193
|
},
|
|
179
|
-
}
|
|
194
|
+
};
|
|
195
|
+
if (!validateUser(loginParams.user) || !validateUser(loginParams.user.connectedAccount)) {
|
|
196
|
+
throw new ApiError(400, t('userInfoError', locale));
|
|
197
|
+
}
|
|
198
|
+
const doc = await node.loginUser(loginParams);
|
|
180
199
|
return doc;
|
|
181
200
|
}
|
|
182
201
|
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.11-next-
|
|
6
|
+
"version": "1.16.11-next-a9ab0bad",
|
|
7
7
|
"description": "Provide unified services for every blocklet",
|
|
8
8
|
"main": "api/index.js",
|
|
9
9
|
"files": [
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
34
34
|
"license": "Apache-2.0",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@abtnode/auth": "1.16.11-next-
|
|
37
|
-
"@abtnode/client": "1.16.11-next-
|
|
38
|
-
"@abtnode/connect-storage": "1.16.11-next-
|
|
39
|
-
"@abtnode/constant": "1.16.11-next-
|
|
40
|
-
"@abtnode/core": "1.16.11-next-
|
|
41
|
-
"@abtnode/cron": "1.16.11-next-
|
|
42
|
-
"@abtnode/logger": "1.16.11-next-
|
|
43
|
-
"@abtnode/models": "1.16.11-next-
|
|
44
|
-
"@abtnode/router-adapter": "1.16.11-next-
|
|
45
|
-
"@abtnode/router-templates": "1.16.11-next-
|
|
46
|
-
"@abtnode/util": "1.16.11-next-
|
|
36
|
+
"@abtnode/auth": "1.16.11-next-a9ab0bad",
|
|
37
|
+
"@abtnode/client": "1.16.11-next-a9ab0bad",
|
|
38
|
+
"@abtnode/connect-storage": "1.16.11-next-a9ab0bad",
|
|
39
|
+
"@abtnode/constant": "1.16.11-next-a9ab0bad",
|
|
40
|
+
"@abtnode/core": "1.16.11-next-a9ab0bad",
|
|
41
|
+
"@abtnode/cron": "1.16.11-next-a9ab0bad",
|
|
42
|
+
"@abtnode/logger": "1.16.11-next-a9ab0bad",
|
|
43
|
+
"@abtnode/models": "1.16.11-next-a9ab0bad",
|
|
44
|
+
"@abtnode/router-adapter": "1.16.11-next-a9ab0bad",
|
|
45
|
+
"@abtnode/router-templates": "1.16.11-next-a9ab0bad",
|
|
46
|
+
"@abtnode/util": "1.16.11-next-a9ab0bad",
|
|
47
47
|
"@arcblock/did": "^1.18.80",
|
|
48
48
|
"@arcblock/did-auth": "1.18.80",
|
|
49
49
|
"@arcblock/did-ext": "^1.18.80",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"@arcblock/jwt": "1.18.80",
|
|
53
53
|
"@arcblock/validator": "^1.18.80",
|
|
54
54
|
"@arcblock/ws": "1.18.80",
|
|
55
|
-
"@blocklet/constant": "1.16.11-next-
|
|
55
|
+
"@blocklet/constant": "1.16.11-next-a9ab0bad",
|
|
56
56
|
"@blocklet/form-builder": "^0.1.11",
|
|
57
57
|
"@blocklet/form-collector": "^0.1.6",
|
|
58
|
-
"@blocklet/meta": "1.16.11-next-
|
|
59
|
-
"@blocklet/sdk": "1.16.11-next-
|
|
58
|
+
"@blocklet/meta": "1.16.11-next-a9ab0bad",
|
|
59
|
+
"@blocklet/sdk": "1.16.11-next-a9ab0bad",
|
|
60
60
|
"@did-connect/authenticator": "^2.1.59",
|
|
61
61
|
"@did-connect/relay-adapter-express": "^2.1.59",
|
|
62
62
|
"@did-connect/storage-nedb": "^2.1.59",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"@nedb/core": "^2.1.2"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
|
-
"@abtnode/ux": "1.16.11-next-
|
|
96
|
+
"@abtnode/ux": "1.16.11-next-a9ab0bad",
|
|
97
97
|
"@arcblock/did-connect": "^2.5.48",
|
|
98
98
|
"@arcblock/icons": "^2.5.48",
|
|
99
99
|
"@arcblock/ux": "^2.5.48",
|
|
@@ -161,5 +161,5 @@
|
|
|
161
161
|
"url": "https://github.com/ArcBlock/blocklet-server/issues",
|
|
162
162
|
"email": "shijun@arcblock.io"
|
|
163
163
|
},
|
|
164
|
-
"gitHead": "
|
|
164
|
+
"gitHead": "55bb74175d9c30db5157e911cb88a226a307d734"
|
|
165
165
|
}
|