@nocobase/plugin-users 0.13.0-alpha.4 → 0.13.0-alpha.6
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/dist/client/index.js +1 -11
- package/dist/index.js +37 -16
- package/dist/locale/en-US.js +22 -4
- package/dist/locale/es-ES.js +22 -4
- package/dist/locale/fr-FR.js +22 -4
- package/dist/locale/ja-JP.js +22 -4
- package/dist/locale/pt-BR.js +22 -4
- package/dist/locale/zh-CN.js +22 -4
- package/dist/server/actions/users.js +60 -25
- package/dist/server/authenticators/index.js +35 -12
- package/dist/server/authenticators/password.js +26 -9
- package/dist/server/collections/users.js +22 -4
- package/dist/server/index.js +39 -17
- package/dist/server/jwt-service.js +39 -12
- package/dist/server/locale/en-US.js +22 -4
- package/dist/server/locale/es-ES.js +22 -4
- package/dist/server/locale/fr-FR.js +22 -4
- package/dist/server/locale/index.js +41 -24
- package/dist/server/locale/ja-JP.js +22 -4
- package/dist/server/locale/pt-BR.js +22 -4
- package/dist/server/locale/zh-CN.js +22 -4
- package/dist/server/middlewares/check.js +26 -4
- package/dist/server/middlewares/index.js +28 -13
- package/dist/server/middlewares/parseToken.js +26 -4
- package/dist/server/migrations/20220818072639-add-users-phone.js +24 -7
- package/dist/server/migrations/20230802170800-add-username.js +24 -7
- package/dist/server/migrations/20230802183100-update-username.js +24 -7
- package/dist/server/server.js +58 -54
- package/dist/swagger/index.json +117 -0
- package/package.json +2 -2
- package/dist/swagger/index.js +0 -131
package/dist/server/server.js
CHANGED
|
@@ -1,48 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (e && e.__esModule) return e;
|
|
17
|
-
var n = Object.create(null);
|
|
18
|
-
if (e) {
|
|
19
|
-
Object.keys(e).forEach(function (k) {
|
|
20
|
-
if (k !== 'default') {
|
|
21
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get: function () { return e[k]; }
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
});
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
16
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
default: () => UsersPlugin
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(server_exports);
|
|
33
|
+
var import_database = require("@nocobase/database");
|
|
34
|
+
var import_server = require("@nocobase/server");
|
|
35
|
+
var import_utils = require("@nocobase/utils");
|
|
36
|
+
var import_path = require("path");
|
|
37
|
+
var import__ = require("./");
|
|
38
|
+
var actions = __toESM(require("./actions/users"));
|
|
39
|
+
var import_authenticators = __toESM(require("./authenticators"));
|
|
40
|
+
var import_jwt_service = require("./jwt-service");
|
|
41
|
+
var import_locale = require("./locale");
|
|
42
|
+
class UsersPlugin extends import_server.Plugin {
|
|
37
43
|
jwtService;
|
|
38
|
-
authenticators = new
|
|
44
|
+
authenticators = new import_utils.Registry();
|
|
39
45
|
constructor(app, options) {
|
|
40
46
|
super(app, options);
|
|
41
|
-
this.jwtService = new
|
|
47
|
+
this.jwtService = new import_jwt_service.JwtService((options == null ? void 0 : options.jwt) || {});
|
|
42
48
|
}
|
|
43
49
|
async beforeLoad() {
|
|
44
|
-
this.app.i18n.addResources("zh-CN",
|
|
45
|
-
this.app.i18n.addResources("en-US",
|
|
50
|
+
this.app.i18n.addResources("zh-CN", import__.namespace, import_locale.zhCN);
|
|
51
|
+
this.app.i18n.addResources("en-US", import__.namespace, import_locale.enUS);
|
|
46
52
|
const cmd = this.app.findCommand("install");
|
|
47
53
|
if (cmd) {
|
|
48
54
|
cmd.requiredOption("-u, --root-username <rootUsername>", "", process.env.INIT_ROOT_USERNAME);
|
|
@@ -54,20 +60,20 @@ class UsersPlugin extends server.Plugin {
|
|
|
54
60
|
$isCurrentUser(_, ctx) {
|
|
55
61
|
var _a, _b, _c, _d;
|
|
56
62
|
return {
|
|
57
|
-
[
|
|
63
|
+
[import_database.Op.eq]: ((_d = (_c = (_b = (_a = ctx == null ? void 0 : ctx.app) == null ? void 0 : _a.ctx) == null ? void 0 : _b.state) == null ? void 0 : _c.currentUser) == null ? void 0 : _d.id) || -1
|
|
58
64
|
};
|
|
59
65
|
},
|
|
60
66
|
$isNotCurrentUser(_, ctx) {
|
|
61
67
|
var _a, _b, _c, _d;
|
|
62
68
|
return {
|
|
63
|
-
[
|
|
69
|
+
[import_database.Op.ne]: ((_d = (_c = (_b = (_a = ctx == null ? void 0 : ctx.app) == null ? void 0 : _a.ctx) == null ? void 0 : _b.state) == null ? void 0 : _c.currentUser) == null ? void 0 : _d.id) || -1
|
|
64
70
|
};
|
|
65
71
|
},
|
|
66
72
|
$isVar(val, ctx) {
|
|
67
73
|
var _a, _b;
|
|
68
|
-
const obj =
|
|
74
|
+
const obj = (0, import_utils.parse)({ val: `{{${val}}}` })(JSON.parse(JSON.stringify((_b = (_a = ctx == null ? void 0 : ctx.app) == null ? void 0 : _a.ctx) == null ? void 0 : _b.state)));
|
|
69
75
|
return {
|
|
70
|
-
[
|
|
76
|
+
[import_database.Op.eq]: obj.val
|
|
71
77
|
};
|
|
72
78
|
}
|
|
73
79
|
});
|
|
@@ -105,7 +111,7 @@ class UsersPlugin extends server.Plugin {
|
|
|
105
111
|
});
|
|
106
112
|
}
|
|
107
113
|
});
|
|
108
|
-
for (const [key, action] of Object.entries(
|
|
114
|
+
for (const [key, action] of Object.entries(actions)) {
|
|
109
115
|
this.app.resourcer.registerActionHandler(`users:${key}`, action);
|
|
110
116
|
}
|
|
111
117
|
this.app.acl.addFixedParams("users", "destroy", () => {
|
|
@@ -130,16 +136,16 @@ class UsersPlugin extends server.Plugin {
|
|
|
130
136
|
}
|
|
131
137
|
async load() {
|
|
132
138
|
await this.db.import({
|
|
133
|
-
directory:
|
|
139
|
+
directory: (0, import_path.resolve)(__dirname, "collections")
|
|
134
140
|
});
|
|
135
141
|
this.db.addMigrations({
|
|
136
142
|
namespace: "users",
|
|
137
|
-
directory:
|
|
143
|
+
directory: (0, import_path.resolve)(__dirname, "migrations"),
|
|
138
144
|
context: {
|
|
139
145
|
plugin: this
|
|
140
146
|
}
|
|
141
147
|
});
|
|
142
|
-
|
|
148
|
+
(0, import_authenticators.default)(this);
|
|
143
149
|
}
|
|
144
150
|
getInstallingData(options = {}) {
|
|
145
151
|
var _a;
|
|
@@ -163,7 +169,7 @@ class UsersPlugin extends server.Plugin {
|
|
|
163
169
|
if (await User.repository.findOne({ filter: { email: rootEmail } })) {
|
|
164
170
|
return;
|
|
165
171
|
}
|
|
166
|
-
await User.repository.create({
|
|
172
|
+
const user = await User.repository.create({
|
|
167
173
|
values: {
|
|
168
174
|
email: rootEmail,
|
|
169
175
|
password: rootPassword,
|
|
@@ -204,7 +210,7 @@ class UsersPlugin extends server.Plugin {
|
|
|
204
210
|
}
|
|
205
211
|
});
|
|
206
212
|
if (!exists) {
|
|
207
|
-
throw new Error(ctx.t("The phone number is not registered, please register first", { ns:
|
|
213
|
+
throw new Error(ctx.t("The phone number is not registered, please register first", { ns: import__.namespace }));
|
|
208
214
|
}
|
|
209
215
|
return true;
|
|
210
216
|
}
|
|
@@ -216,7 +222,7 @@ class UsersPlugin extends server.Plugin {
|
|
|
216
222
|
expiresIn: 120,
|
|
217
223
|
validate: async (ctx, phone) => {
|
|
218
224
|
if (!phone) {
|
|
219
|
-
throw new Error(ctx.t("Not a valid cellphone number, please re-enter", { ns:
|
|
225
|
+
throw new Error(ctx.t("Not a valid cellphone number, please re-enter", { ns: import__.namespace }));
|
|
220
226
|
}
|
|
221
227
|
const User = this.db.getCollection("users");
|
|
222
228
|
const exists = await User.model.count({
|
|
@@ -225,7 +231,7 @@ class UsersPlugin extends server.Plugin {
|
|
|
225
231
|
}
|
|
226
232
|
});
|
|
227
233
|
if (exists) {
|
|
228
|
-
throw new Error(ctx.t("The phone number has been registered, please login directly", { ns:
|
|
234
|
+
throw new Error(ctx.t("The phone number has been registered, please login directly", { ns: import__.namespace }));
|
|
229
235
|
}
|
|
230
236
|
return true;
|
|
231
237
|
}
|
|
@@ -241,7 +247,7 @@ class UsersPlugin extends server.Plugin {
|
|
|
241
247
|
}
|
|
242
248
|
});
|
|
243
249
|
if (!user) {
|
|
244
|
-
return ctx.throw(404, ctx.t("The phone number is incorrect, please re-enter", { ns:
|
|
250
|
+
return ctx.throw(404, ctx.t("The phone number is incorrect, please re-enter", { ns: import__.namespace }));
|
|
245
251
|
}
|
|
246
252
|
ctx.state.currentUser = user;
|
|
247
253
|
return next();
|
|
@@ -249,5 +255,3 @@ class UsersPlugin extends server.Plugin {
|
|
|
249
255
|
);
|
|
250
256
|
}
|
|
251
257
|
}
|
|
252
|
-
|
|
253
|
-
module.exports = UsersPlugin;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.0.2",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "NocoBase API - Users plugin"
|
|
5
|
+
},
|
|
6
|
+
"tags": [],
|
|
7
|
+
"paths": {
|
|
8
|
+
"/users:list": {
|
|
9
|
+
"get": {
|
|
10
|
+
"tags": ["users"],
|
|
11
|
+
"description": "",
|
|
12
|
+
"parameters": [],
|
|
13
|
+
"responses": {
|
|
14
|
+
"200": {
|
|
15
|
+
"description": "OK"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"/users:get": {
|
|
21
|
+
"get": {
|
|
22
|
+
"tags": ["users"],
|
|
23
|
+
"description": "",
|
|
24
|
+
"parameters": [],
|
|
25
|
+
"responses": {
|
|
26
|
+
"200": {
|
|
27
|
+
"description": "OK"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"/users:create": {
|
|
33
|
+
"post": {
|
|
34
|
+
"tags": ["users"],
|
|
35
|
+
"description": "",
|
|
36
|
+
"parameters": [],
|
|
37
|
+
"responses": {
|
|
38
|
+
"200": {
|
|
39
|
+
"description": "OK"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"/users:update": {
|
|
45
|
+
"post": {
|
|
46
|
+
"tags": ["users"],
|
|
47
|
+
"description": "",
|
|
48
|
+
"parameters": [],
|
|
49
|
+
"responses": {
|
|
50
|
+
"200": {
|
|
51
|
+
"description": "OK"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"/users:updateProfile": {
|
|
57
|
+
"post": {
|
|
58
|
+
"tags": ["users"],
|
|
59
|
+
"description": "",
|
|
60
|
+
"parameters": [],
|
|
61
|
+
"responses": {
|
|
62
|
+
"200": {
|
|
63
|
+
"description": "OK"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"/users:changePassword": {
|
|
69
|
+
"post": {
|
|
70
|
+
"tags": ["users"],
|
|
71
|
+
"description": "",
|
|
72
|
+
"parameters": [],
|
|
73
|
+
"responses": {
|
|
74
|
+
"200": {
|
|
75
|
+
"description": "OK"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"/users:destroy": {
|
|
81
|
+
"post": {
|
|
82
|
+
"tags": ["users"],
|
|
83
|
+
"description": "",
|
|
84
|
+
"parameters": [],
|
|
85
|
+
"responses": {
|
|
86
|
+
"200": {
|
|
87
|
+
"description": "OK"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"/{collectionName}/{collectionIndex}/createdBy:get": {
|
|
93
|
+
"post": {
|
|
94
|
+
"tags": ["$collection.createdBy"],
|
|
95
|
+
"description": "",
|
|
96
|
+
"parameters": [],
|
|
97
|
+
"responses": {
|
|
98
|
+
"200": {
|
|
99
|
+
"description": "OK"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"/{collectionName}/{collectionIndex}/updatedBy:get": {
|
|
105
|
+
"post": {
|
|
106
|
+
"tags": ["$collection.updatedBy"],
|
|
107
|
+
"description": "",
|
|
108
|
+
"parameters": [],
|
|
109
|
+
"responses": {
|
|
110
|
+
"200": {
|
|
111
|
+
"description": "OK"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "用户",
|
|
5
5
|
"description": "Provide a basic user model and a password-based user authentication type, and extended the createdBy and updatedBy field types",
|
|
6
6
|
"description.zh-CN": "提供了基础的用户模型和基于密码的用户认证方式,并拓展了创建人和最后更新人字段类型",
|
|
7
|
-
"version": "0.13.0-alpha.
|
|
7
|
+
"version": "0.13.0-alpha.6",
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"main": "./dist/server/index.js",
|
|
10
10
|
"devDependencies": {
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"@nocobase/test": "0.x",
|
|
23
23
|
"@nocobase/utils": "0.x"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "49ef71c8bdaab986f47c8a84bcf15e2123ba9b59"
|
|
26
26
|
}
|
package/dist/swagger/index.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var openapi = "3.0.2";
|
|
6
|
-
var info = {
|
|
7
|
-
title: "NocoBase API - Users plugin"
|
|
8
|
-
};
|
|
9
|
-
var tags = [];
|
|
10
|
-
var paths = {
|
|
11
|
-
"/users:list": {
|
|
12
|
-
get: {
|
|
13
|
-
tags: ["users"],
|
|
14
|
-
description: "",
|
|
15
|
-
parameters: [],
|
|
16
|
-
responses: {
|
|
17
|
-
"200": {
|
|
18
|
-
description: "OK"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"/users:get": {
|
|
24
|
-
get: {
|
|
25
|
-
tags: ["users"],
|
|
26
|
-
description: "",
|
|
27
|
-
parameters: [],
|
|
28
|
-
responses: {
|
|
29
|
-
"200": {
|
|
30
|
-
description: "OK"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
"/users:create": {
|
|
36
|
-
post: {
|
|
37
|
-
tags: ["users"],
|
|
38
|
-
description: "",
|
|
39
|
-
parameters: [],
|
|
40
|
-
responses: {
|
|
41
|
-
"200": {
|
|
42
|
-
description: "OK"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"/users:update": {
|
|
48
|
-
post: {
|
|
49
|
-
tags: ["users"],
|
|
50
|
-
description: "",
|
|
51
|
-
parameters: [],
|
|
52
|
-
responses: {
|
|
53
|
-
"200": {
|
|
54
|
-
description: "OK"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
"/users:updateProfile": {
|
|
60
|
-
post: {
|
|
61
|
-
tags: ["users"],
|
|
62
|
-
description: "",
|
|
63
|
-
parameters: [],
|
|
64
|
-
responses: {
|
|
65
|
-
"200": {
|
|
66
|
-
description: "OK"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
"/users:changePassword": {
|
|
72
|
-
post: {
|
|
73
|
-
tags: ["users"],
|
|
74
|
-
description: "",
|
|
75
|
-
parameters: [],
|
|
76
|
-
responses: {
|
|
77
|
-
"200": {
|
|
78
|
-
description: "OK"
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
"/users:destroy": {
|
|
84
|
-
post: {
|
|
85
|
-
tags: ["users"],
|
|
86
|
-
description: "",
|
|
87
|
-
parameters: [],
|
|
88
|
-
responses: {
|
|
89
|
-
"200": {
|
|
90
|
-
description: "OK"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
"/{collectionName}/{collectionIndex}/createdBy:get": {
|
|
96
|
-
post: {
|
|
97
|
-
tags: ["$collection.createdBy"],
|
|
98
|
-
description: "",
|
|
99
|
-
parameters: [],
|
|
100
|
-
responses: {
|
|
101
|
-
"200": {
|
|
102
|
-
description: "OK"
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
"/{collectionName}/{collectionIndex}/updatedBy:get": {
|
|
108
|
-
post: {
|
|
109
|
-
tags: ["$collection.updatedBy"],
|
|
110
|
-
description: "",
|
|
111
|
-
parameters: [],
|
|
112
|
-
responses: {
|
|
113
|
-
"200": {
|
|
114
|
-
description: "OK"
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
var swagger_default = {
|
|
121
|
-
openapi,
|
|
122
|
-
info,
|
|
123
|
-
tags,
|
|
124
|
-
paths
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
exports.default = swagger_default;
|
|
128
|
-
exports.info = info;
|
|
129
|
-
exports.openapi = openapi;
|
|
130
|
-
exports.paths = paths;
|
|
131
|
-
exports.tags = tags;
|