@nocobase/plugin-users 0.5.0-alpha.38 → 0.7.0-alpha.2
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/LICENSE +201 -21
- package/esm/actions/users.d.ts +11 -0
- package/esm/actions/users.js +165 -0
- package/esm/actions/users.js.map +1 -0
- package/esm/collections/roles-users.d.ts +3 -0
- package/esm/collections/roles-users.js +5 -0
- package/esm/collections/roles-users.js.map +1 -0
- package/esm/collections/users.d.ts +3 -0
- package/esm/collections/users.js +86 -0
- package/esm/collections/users.js.map +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -0
- package/esm/jwt-service.d.ts +12 -0
- package/esm/jwt-service.js +26 -0
- package/esm/jwt-service.js.map +1 -0
- package/esm/middlewares/check.d.ts +1 -0
- package/esm/middlewares/check.js +22 -0
- package/esm/middlewares/check.js.map +1 -0
- package/esm/middlewares/index.d.ts +2 -0
- package/esm/middlewares/index.js +3 -0
- package/esm/middlewares/index.js.map +1 -0
- package/esm/middlewares/parseToken.d.ts +6 -0
- package/esm/middlewares/parseToken.js +64 -0
- package/esm/middlewares/parseToken.js.map +1 -0
- package/esm/models/UserModel.d.ts +4 -0
- package/esm/models/UserModel.js +53 -0
- package/esm/models/UserModel.js.map +1 -0
- package/esm/server.d.ts +23 -0
- package/esm/server.js +133 -0
- package/esm/server.js.map +1 -0
- package/lib/actions/users.d.ts +1 -0
- package/lib/actions/users.js +145 -241
- package/lib/actions/users.js.map +1 -1
- package/lib/collections/roles-users.d.ts +3 -0
- package/lib/collections/roles-users.js +7 -0
- package/lib/collections/roles-users.js.map +1 -0
- package/lib/collections/users.d.ts +2 -2
- package/lib/collections/users.js +85 -112
- package/lib/collections/users.js.map +1 -1
- package/lib/index.js +5 -30
- package/lib/index.js.map +1 -1
- package/lib/jwt-service.d.ts +12 -0
- package/lib/jwt-service.js +33 -0
- package/lib/jwt-service.js.map +1 -0
- package/lib/middlewares/check.d.ts +1 -1
- package/lib/middlewares/check.js +22 -60
- package/lib/middlewares/check.js.map +1 -1
- package/lib/middlewares/index.d.ts +2 -2
- package/lib/middlewares/index.js +6 -41
- package/lib/middlewares/index.js.map +1 -1
- package/lib/middlewares/parseToken.d.ts +6 -1
- package/lib/middlewares/parseToken.js +62 -63
- package/lib/middlewares/parseToken.js.map +1 -1
- package/lib/models/UserModel.d.ts +4 -0
- package/lib/models/UserModel.js +57 -0
- package/lib/models/UserModel.js.map +1 -0
- package/lib/server.d.ts +23 -3
- package/lib/server.js +147 -159
- package/lib/server.js.map +1 -1
- package/package.json +17 -6
- package/tsconfig.build.json +9 -0
- package/lib/actions/users.d.ts.map +0 -1
- package/lib/collections/users.d.ts.map +0 -1
- package/lib/fields/CreatedBy.d.ts +0 -11
- package/lib/fields/CreatedBy.d.ts.map +0 -1
- package/lib/fields/CreatedBy.js +0 -66
- package/lib/fields/CreatedBy.js.map +0 -1
- package/lib/fields/UpdatedBy.d.ts +0 -16
- package/lib/fields/UpdatedBy.d.ts.map +0 -1
- package/lib/fields/UpdatedBy.js +0 -87
- package/lib/fields/UpdatedBy.js.map +0 -1
- package/lib/fields/index.d.ts +0 -2
- package/lib/fields/index.d.ts.map +0 -1
- package/lib/fields/index.js +0 -43
- package/lib/fields/index.js.map +0 -1
- package/lib/fields/utils.d.ts +0 -4
- package/lib/fields/utils.d.ts.map +0 -1
- package/lib/fields/utils.js +0 -51
- package/lib/fields/utils.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/middlewares/check.d.ts.map +0 -1
- package/lib/middlewares/index.d.ts.map +0 -1
- package/lib/middlewares/parseToken.d.ts.map +0 -1
- package/lib/server.d.ts.map +0 -1
package/lib/collections/users.js
CHANGED
|
@@ -1,115 +1,88 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
function _react() {
|
|
4
|
-
const data = _interopRequireDefault(require("react"));
|
|
5
|
-
|
|
6
|
-
_react = function _react() {
|
|
7
|
-
return data;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
Object.defineProperty(exports, "__esModule", {
|
|
16
|
-
value: true
|
|
17
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.default = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
hidden: true,
|
|
103
|
-
privilege: 'undelete',
|
|
104
|
-
state: 0
|
|
105
|
-
}, {
|
|
106
|
-
interface: 'password',
|
|
107
|
-
type: 'string',
|
|
108
|
-
name: 'reset_token',
|
|
109
|
-
unique: true,
|
|
110
|
-
hidden: true,
|
|
111
|
-
privilege: 'undelete',
|
|
112
|
-
state: 0
|
|
113
|
-
}]
|
|
4
|
+
name: 'users',
|
|
5
|
+
title: '{{t("Users")}}',
|
|
6
|
+
sortable: 'sort',
|
|
7
|
+
model: 'UserModel',
|
|
8
|
+
createdBy: true,
|
|
9
|
+
updatedBy: true,
|
|
10
|
+
fields: [
|
|
11
|
+
{
|
|
12
|
+
name: 'id',
|
|
13
|
+
type: 'integer',
|
|
14
|
+
autoIncrement: true,
|
|
15
|
+
primaryKey: true,
|
|
16
|
+
allowNull: false,
|
|
17
|
+
uiSchema: { type: 'number', title: '{{t("ID")}}', 'x-component': 'InputNumber', 'x-read-pretty': true },
|
|
18
|
+
interface: 'id',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
interface: 'input',
|
|
22
|
+
type: 'string',
|
|
23
|
+
name: 'nickname',
|
|
24
|
+
uiSchema: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
title: '{{t("Nickname")}}',
|
|
27
|
+
'x-component': 'Input',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
interface: 'email',
|
|
32
|
+
type: 'string',
|
|
33
|
+
name: 'email',
|
|
34
|
+
unique: true,
|
|
35
|
+
uiSchema: {
|
|
36
|
+
type: 'string',
|
|
37
|
+
title: '{{t("Email")}}',
|
|
38
|
+
'x-component': 'Input',
|
|
39
|
+
require: true,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
interface: 'password',
|
|
44
|
+
type: 'password',
|
|
45
|
+
name: 'password',
|
|
46
|
+
hidden: true,
|
|
47
|
+
uiSchema: {
|
|
48
|
+
type: 'string',
|
|
49
|
+
title: '{{t("Password")}}',
|
|
50
|
+
'x-component': 'Password',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
interface: 'linkTo',
|
|
55
|
+
type: 'belongsToMany',
|
|
56
|
+
name: 'roles',
|
|
57
|
+
target: 'roles',
|
|
58
|
+
foreignKey: 'userId',
|
|
59
|
+
otherKey: 'roleName',
|
|
60
|
+
sourceKey: 'id',
|
|
61
|
+
targetKey: 'name',
|
|
62
|
+
through: 'rolesUsers',
|
|
63
|
+
uiSchema: {
|
|
64
|
+
type: 'array',
|
|
65
|
+
title: '{{t("Roles")}}',
|
|
66
|
+
'x-component': 'RecordPicker',
|
|
67
|
+
'x-component-props': {
|
|
68
|
+
multiple: true,
|
|
69
|
+
fieldNames: {
|
|
70
|
+
label: 'title',
|
|
71
|
+
value: 'name',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
type: 'string',
|
|
78
|
+
name: 'appLang',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
type: 'string',
|
|
82
|
+
name: 'resetToken',
|
|
83
|
+
unique: true,
|
|
84
|
+
hidden: true,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
114
87
|
};
|
|
115
|
-
//# sourceMappingURL=users.js.map
|
|
88
|
+
//# sourceMappingURL=users.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["collections/users.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,gBAAgB;IACvB,QAAQ,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/collections/users.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,gBAAgB;IACvB,QAAQ,EAAE,MAA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,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,gBAAgB;gBACvB,aAAa,EAAE,cAAc;gBAC7B,mBAAmB,EAAE;oBACnB,QAAQ,EAAE,IAAI;oBACd,UAAU,EAAE;wBACV,KAAK,EAAE,OAAO;wBACd,KAAK,EAAE,MAAM;qBACd;iBACF;aACF;SACF;QACD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,SAAS;SAChB;QACD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,IAAI;SACb;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'users',\n title: '{{t(\"Users\")}}',\n sortable: 'sort',\n model: 'UserModel',\n createdBy: true,\n updatedBy: true,\n fields: [\n {\n name: 'id',\n type: 'integer',\n autoIncrement: true,\n primaryKey: true,\n allowNull: false,\n uiSchema: { type: 'number', title: '{{t(\"ID\")}}', 'x-component': 'InputNumber', 'x-read-pretty': true },\n interface: 'id',\n },\n {\n interface: 'input',\n type: 'string',\n name: 'nickname',\n uiSchema: {\n type: 'string',\n title: '{{t(\"Nickname\")}}',\n 'x-component': 'Input',\n },\n },\n {\n interface: 'email',\n type: 'string',\n name: 'email',\n unique: true,\n uiSchema: {\n type: 'string',\n title: '{{t(\"Email\")}}',\n 'x-component': 'Input',\n require: true,\n },\n },\n {\n interface: 'password',\n type: 'password',\n name: 'password',\n hidden: true,\n uiSchema: {\n type: 'string',\n title: '{{t(\"Password\")}}',\n 'x-component': 'Password',\n },\n },\n {\n interface: 'linkTo',\n type: 'belongsToMany',\n name: 'roles',\n target: 'roles',\n foreignKey: 'userId',\n otherKey: 'roleName',\n sourceKey: 'id',\n targetKey: 'name',\n through: 'rolesUsers',\n uiSchema: {\n type: 'array',\n title: '{{t(\"Roles\")}}',\n 'x-component': 'RecordPicker',\n 'x-component-props': {\n multiple: true,\n fieldNames: {\n label: 'title',\n value: 'name',\n },\n },\n },\n },\n {\n type: 'string',\n name: 'appLang',\n },\n {\n type: 'string',\n name: 'resetToken',\n unique: true,\n hidden: true,\n },\n ],\n} as CollectionOptions;\n"]}
|
package/lib/index.js
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const data = _interopRequireDefault(require("react"));
|
|
5
|
-
|
|
6
|
-
_react = function _react() {
|
|
7
|
-
return data;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
16
|
-
return mod && mod.__esModule ? mod : {
|
|
17
|
-
"default": mod
|
|
18
|
-
};
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
4
|
};
|
|
20
|
-
|
|
21
|
-
Object.defineProperty(exports, "__esModule", {
|
|
22
|
-
value: true
|
|
23
|
-
});
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
6
|
exports.default = void 0;
|
|
25
|
-
|
|
26
7
|
var server_1 = require("./server");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
enumerable: true,
|
|
30
|
-
get: function get() {
|
|
31
|
-
return __importDefault(server_1).default;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
//# sourceMappingURL=index.js.map
|
|
8
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(server_1).default; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAmC;AAA1B,kHAAA,OAAO,OAAA","
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAmC;AAA1B,kHAAA,OAAO,OAAA","sourcesContent":["export { default } from './server';\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface JwtOptions {
|
|
2
|
+
secret: string;
|
|
3
|
+
expiresIn?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class JwtService {
|
|
6
|
+
protected options: JwtOptions;
|
|
7
|
+
constructor(options: JwtOptions);
|
|
8
|
+
private expiresIn;
|
|
9
|
+
private secret;
|
|
10
|
+
sign(payload: any): string;
|
|
11
|
+
decode(token: string): Promise<any>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.JwtService = void 0;
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
class JwtService {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
expiresIn() {
|
|
13
|
+
return this.options.expiresIn || '7d';
|
|
14
|
+
}
|
|
15
|
+
secret() {
|
|
16
|
+
return this.options.secret;
|
|
17
|
+
}
|
|
18
|
+
sign(payload) {
|
|
19
|
+
return jsonwebtoken_1.default.sign(payload, this.secret(), { expiresIn: this.expiresIn() });
|
|
20
|
+
}
|
|
21
|
+
decode(token) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
jsonwebtoken_1.default.verify(token, this.secret(), (err, decoded) => {
|
|
24
|
+
if (err) {
|
|
25
|
+
return reject(err);
|
|
26
|
+
}
|
|
27
|
+
resolve(decoded);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.JwtService = JwtService;
|
|
33
|
+
//# sourceMappingURL=jwt-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-service.js","sourceRoot":"","sources":["../src/jwt-service.ts"],"names":[],"mappings":";;;;;;AAAA,gEAA+B;AAO/B,MAAa,UAAU;IACrB,YAAsB,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;IAAG,CAAC;IAErC,SAAS;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;IACxC,CAAC;IAEO,MAAM;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,IAAI,CAAC,OAAY;QACf,OAAO,sBAAG,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,sBAAG,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,GAAQ,EAAE,OAAY,EAAE,EAAE;gBAC1D,IAAI,GAAG,EAAE;oBACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;iBACpB;gBAED,OAAO,CAAC,OAAO,CAAC,CAAC;YACnB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA1BD,gCA0BC","sourcesContent":["import jwt from 'jsonwebtoken';\n\nexport interface JwtOptions {\n secret: string;\n expiresIn?: string;\n}\n\nexport class JwtService {\n constructor(protected options: JwtOptions) {}\n\n private expiresIn() {\n return this.options.expiresIn || '7d';\n }\n\n private secret() {\n return this.options.secret;\n }\n\n sign(payload: any) {\n return jwt.sign(payload, this.secret(), { expiresIn: this.expiresIn() });\n }\n\n decode(token: string): Promise<any> {\n return new Promise((resolve, reject) => {\n jwt.verify(token, this.secret(), (err: any, decoded: any) => {\n if (err) {\n return reject(err);\n }\n\n resolve(decoded);\n });\n });\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function check(options: any): (ctx: any, next: any) => Promise<any>;
|
package/lib/middlewares/check.js
CHANGED
|
@@ -1,64 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
16
|
-
function adopt(value) {
|
|
17
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
18
|
-
resolve(value);
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
9
|
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
23
|
-
function fulfilled(value) {
|
|
24
|
-
try {
|
|
25
|
-
step(generator.next(value));
|
|
26
|
-
} catch (e) {
|
|
27
|
-
reject(e);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function rejected(value) {
|
|
32
|
-
try {
|
|
33
|
-
step(generator["throw"](value));
|
|
34
|
-
} catch (e) {
|
|
35
|
-
reject(e);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function step(result) {
|
|
40
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
44
|
-
});
|
|
45
10
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return next();
|
|
60
|
-
});
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.check = void 0;
|
|
13
|
+
// TODO(usage): 拦截用户的处理暂时作为一个中间件导出,应用需要的时候可以直接使用这个中间件
|
|
14
|
+
function check(options) {
|
|
15
|
+
return function check(ctx, next) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const { currentUser } = ctx.state;
|
|
18
|
+
if (!currentUser) {
|
|
19
|
+
return ctx.throw(401, 'Unauthorized');
|
|
20
|
+
}
|
|
21
|
+
return next();
|
|
22
|
+
});
|
|
23
|
+
};
|
|
61
24
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
//# sourceMappingURL=check.js.map
|
|
25
|
+
exports.check = check;
|
|
26
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["middlewares/check.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/middlewares/check.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAqD;AACrD,SAAgB,KAAK,CAAC,OAAO;IAC3B,OAAO,SAAe,KAAK,CAAC,GAAG,EAAE,IAAI;;YACnC,MAAM,EAAE,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC;YAClC,IAAI,CAAC,WAAW,EAAE;gBAChB,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;aACvC;YACD,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;KAAA,CAAC;AACJ,CAAC;AARD,sBAQC","sourcesContent":["// TODO(usage): 拦截用户的处理暂时作为一个中间件导出,应用需要的时候可以直接使用这个中间件\nexport function check(options) {\n return async function check(ctx, next) {\n const { currentUser } = ctx.state;\n if (!currentUser) {\n return ctx.throw(401, 'Unauthorized');\n }\n return next();\n };\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { check } from './check';
|
|
2
|
+
export { parseToken } from './parseToken';
|
package/lib/middlewares/index.js
CHANGED
|
@@ -1,43 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const data = _interopRequireDefault(require("react"));
|
|
5
|
-
|
|
6
|
-
_react = function _react() {
|
|
7
|
-
return data;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
16
|
-
return mod && mod.__esModule ? mod : {
|
|
17
|
-
"default": mod
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
Object.defineProperty(exports, "__esModule", {
|
|
22
|
-
value: true
|
|
23
|
-
});
|
|
24
|
-
exports.check = exports.parseToken = void 0;
|
|
25
|
-
|
|
26
|
-
var parseToken_1 = require("./parseToken");
|
|
27
|
-
|
|
28
|
-
Object.defineProperty(exports, "parseToken", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
get: function get() {
|
|
31
|
-
return __importDefault(parseToken_1).default;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseToken = exports.check = void 0;
|
|
35
4
|
var check_1 = require("./check");
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return __importDefault(check_1).default;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
//# sourceMappingURL=index.js.map
|
|
5
|
+
Object.defineProperty(exports, "check", { enumerable: true, get: function () { return check_1.check; } });
|
|
6
|
+
var parseToken_1 = require("./parseToken");
|
|
7
|
+
Object.defineProperty(exports, "parseToken", { enumerable: true, get: function () { return parseToken_1.parseToken; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["middlewares/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,2CAA0C;AAAjC,wGAAA,UAAU,OAAA","sourcesContent":["export { check } from './check';\nexport { parseToken } from './parseToken';\n"]}
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { Context, Next } from '@nocobase/actions';
|
|
2
|
+
import UsersPlugin from '../server';
|
|
3
|
+
export declare function parseToken(options?: {
|
|
4
|
+
plugin: UsersPlugin;
|
|
5
|
+
}): (ctx: Context, next: Next) => Promise<any>;
|
|
6
|
+
export declare function setCurrentRole(ctx: any): void;
|
|
@@ -1,70 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
16
|
-
function adopt(value) {
|
|
17
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
18
|
-
resolve(value);
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
9
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.setCurrentRole = exports.parseToken = void 0;
|
|
13
|
+
function parseToken(options) {
|
|
14
|
+
return function parseToken(ctx, next) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const user = yield findUserByToken(ctx, options.plugin);
|
|
17
|
+
if (user) {
|
|
18
|
+
ctx.state.currentUser = user;
|
|
19
|
+
setCurrentRole(ctx);
|
|
20
|
+
}
|
|
21
|
+
return next();
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.parseToken = parseToken;
|
|
26
|
+
function setCurrentRole(ctx) {
|
|
27
|
+
var _a;
|
|
28
|
+
let currentRole = ctx.get('X-Role');
|
|
29
|
+
if (currentRole === 'anonymous') {
|
|
30
|
+
ctx.state.currentRole = currentRole;
|
|
31
|
+
return;
|
|
29
32
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
step(generator["throw"](value));
|
|
34
|
-
} catch (e) {
|
|
35
|
-
reject(e);
|
|
36
|
-
}
|
|
33
|
+
const userRoles = ctx.state.currentUser.roles;
|
|
34
|
+
if (userRoles.length == 1) {
|
|
35
|
+
currentRole = userRoles[0].name;
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
else if (userRoles.length > 1) {
|
|
38
|
+
const role = userRoles.find((role) => role.name === currentRole);
|
|
39
|
+
if (!role) {
|
|
40
|
+
const defaultRole = userRoles.find((role) => { var _a; return (_a = role === null || role === void 0 ? void 0 : role.rolesUsers) === null || _a === void 0 ? void 0 : _a.default; });
|
|
41
|
+
currentRole = (_a = (defaultRole || userRoles[0])) === null || _a === void 0 ? void 0 : _a.name;
|
|
42
|
+
}
|
|
41
43
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
Object.defineProperty(exports, "__esModule", {
|
|
48
|
-
value: true
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
function default_1(options) {
|
|
52
|
-
return (ctx, next) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
const token = ctx.get('Authorization').replace(/^Bearer\s+/gi, '');
|
|
54
|
-
const User = ctx.db.getModel('users');
|
|
55
|
-
const user = yield User.findOne({
|
|
56
|
-
where: {
|
|
57
|
-
token
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (user) {
|
|
62
|
-
ctx.state.currentUser = user;
|
|
44
|
+
if (currentRole) {
|
|
45
|
+
ctx.state.currentRole = currentRole;
|
|
63
46
|
}
|
|
64
|
-
|
|
65
|
-
return next();
|
|
66
|
-
});
|
|
67
47
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
48
|
+
exports.setCurrentRole = setCurrentRole;
|
|
49
|
+
function findUserByToken(ctx, plugin) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const token = ctx.getBearerToken();
|
|
52
|
+
if (!token) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const { userId } = yield plugin.jwtService.decode(token);
|
|
57
|
+
return yield ctx.db.getRepository('users').findOne({
|
|
58
|
+
filter: {
|
|
59
|
+
id: userId,
|
|
60
|
+
},
|
|
61
|
+
appends: ['roles'],
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.warn(error);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=parseToken.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["middlewares/parseToken.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parseToken.js","sourceRoot":"","sources":["../../src/middlewares/parseToken.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,SAAgB,UAAU,CAAC,OAAiC;IAC1D,OAAO,SAAe,UAAU,CAAC,GAAY,EAAE,IAAU;;YACvD,MAAM,IAAI,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YACxD,IAAI,IAAI,EAAE;gBACR,GAAG,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC;gBAC7B,cAAc,CAAC,GAAG,CAAC,CAAC;aACrB;YACD,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;KAAA,CAAC;AACJ,CAAC;AATD,gCASC;AAED,SAAgB,cAAc,CAAC,GAAG;;IAChC,IAAI,WAAW,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEpC,IAAI,WAAW,KAAK,WAAW,EAAE;QAC/B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gBACD,OAAO,EAAE,CAAC,OAAO,CAAC;aACnB,CAAC,CAAC;SACJ;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACrB;IACH,CAAC;CAAA","sourcesContent":["import { Context, Next } from '@nocobase/actions';\nimport UsersPlugin from '../server';\n\nexport function parseToken(options?: { plugin: UsersPlugin }) {\n return async function parseToken(ctx: Context, next: Next) {\n const user = await findUserByToken(ctx, options.plugin);\n if (user) {\n ctx.state.currentUser = user;\n setCurrentRole(ctx);\n }\n return next();\n };\n}\n\nexport function setCurrentRole(ctx) {\n let currentRole = ctx.get('X-Role');\n\n if (currentRole === 'anonymous') {\n ctx.state.currentRole = currentRole;\n return;\n }\n\n const userRoles = ctx.state.currentUser.roles;\n\n if (userRoles.length == 1) {\n currentRole = userRoles[0].name;\n } else if (userRoles.length > 1) {\n const role = userRoles.find((role) => role.name === currentRole);\n if (!role) {\n const defaultRole = userRoles.find((role) => role?.rolesUsers?.default);\n currentRole = (defaultRole || userRoles[0])?.name;\n }\n }\n\n if (currentRole) {\n ctx.state.currentRole = currentRole;\n }\n}\n\nasync function findUserByToken(ctx: Context, plugin: UsersPlugin) {\n const token = ctx.getBearerToken();\n if (!token) {\n return null;\n }\n try {\n const { userId } = await plugin.jwtService.decode(token);\n\n return await ctx.db.getRepository('users').findOne({\n filter: {\n id: userId,\n },\n appends: ['roles'],\n });\n } catch (error) {\n console.warn(error);\n }\n}\n"]}
|