@nocobase/plugin-users 0.5.0-alpha.37 → 0.7.0-alpha.1
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/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Context, Next } from '@nocobase/actions';
|
|
2
|
+
export declare function check(ctx: Context, next: Next): Promise<void>;
|
|
3
|
+
export declare function signin(ctx: Context, next: Next): Promise<void>;
|
|
4
|
+
export declare function signout(ctx: Context, next: Next): Promise<void>;
|
|
5
|
+
export declare function signup(ctx: Context, next: Next): Promise<void>;
|
|
6
|
+
export declare function lostpassword(ctx: Context, next: Next): Promise<void>;
|
|
7
|
+
export declare function resetpassword(ctx: Context, next: Next): Promise<void>;
|
|
8
|
+
export declare function getUserByResetToken(ctx: Context, next: Next): Promise<void>;
|
|
9
|
+
export declare function updateProfile(ctx: Context, next: Next): Promise<void>;
|
|
10
|
+
export declare function changePassword(ctx: Context, next: Next): Promise<void>;
|
|
11
|
+
export declare function setDefaultRole(ctx: Context, next: Next): Promise<void>;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import crypto from 'crypto';
|
|
11
|
+
export function check(ctx, next) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
if (ctx.state.currentUser) {
|
|
14
|
+
const user = ctx.state.currentUser.toJSON();
|
|
15
|
+
ctx.body = user;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
ctx.body = {};
|
|
19
|
+
}
|
|
20
|
+
yield next();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function signin(ctx, next) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const { uniqueField = 'email', values } = ctx.action.params;
|
|
26
|
+
if (!values[uniqueField]) {
|
|
27
|
+
ctx.throw(401, '请填写邮箱账号');
|
|
28
|
+
}
|
|
29
|
+
const User = ctx.db.getCollection('users');
|
|
30
|
+
const user = yield User.model.findOne({
|
|
31
|
+
where: {
|
|
32
|
+
[uniqueField]: values[uniqueField],
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
if (!user) {
|
|
36
|
+
ctx.throw(401, '邮箱账号未注册');
|
|
37
|
+
}
|
|
38
|
+
const pwd = User.getField('password');
|
|
39
|
+
const isValid = yield pwd.verify(values.password, user.password);
|
|
40
|
+
if (!isValid) {
|
|
41
|
+
ctx.throw(401, '密码错误,请您重新输入');
|
|
42
|
+
}
|
|
43
|
+
const pluginUser = ctx.app.getPlugin('@nocobase/plugin-users');
|
|
44
|
+
ctx.body = Object.assign(Object.assign({}, user.toJSON()), { token: pluginUser.jwtService.sign({
|
|
45
|
+
userId: user.get('id'),
|
|
46
|
+
}) });
|
|
47
|
+
yield next();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export function signout(ctx, next) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
ctx.body = ctx.state.currentUser;
|
|
53
|
+
yield next();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
export function signup(ctx, next) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const User = ctx.db.getRepository('users');
|
|
59
|
+
const { values } = ctx.action.params;
|
|
60
|
+
const user = yield User.create({ values });
|
|
61
|
+
ctx.body = user;
|
|
62
|
+
yield next();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export function lostpassword(ctx, next) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const { values: { email }, } = ctx.action.params;
|
|
68
|
+
if (!email) {
|
|
69
|
+
ctx.throw(401, '请填写邮箱账号');
|
|
70
|
+
}
|
|
71
|
+
const User = ctx.db.getCollection('users');
|
|
72
|
+
const user = yield User.model.findOne({
|
|
73
|
+
where: {
|
|
74
|
+
email,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
if (!user) {
|
|
78
|
+
ctx.throw(401, '邮箱账号未注册');
|
|
79
|
+
}
|
|
80
|
+
user.resetToken = crypto.randomBytes(20).toString('hex');
|
|
81
|
+
yield user.save();
|
|
82
|
+
ctx.body = user;
|
|
83
|
+
yield next();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
export function resetpassword(ctx, next) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const { values: { email, password, resetToken }, } = ctx.action.params;
|
|
89
|
+
const User = ctx.db.getCollection('users');
|
|
90
|
+
const user = yield User.model.findOne({
|
|
91
|
+
where: {
|
|
92
|
+
email,
|
|
93
|
+
resetToken,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
if (!user) {
|
|
97
|
+
ctx.throw(401, 'Unauthorized');
|
|
98
|
+
}
|
|
99
|
+
user.token = null;
|
|
100
|
+
user.resetToken = null;
|
|
101
|
+
user.password = password;
|
|
102
|
+
yield user.save();
|
|
103
|
+
ctx.body = user;
|
|
104
|
+
yield next();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
export function getUserByResetToken(ctx, next) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const { token } = ctx.action.params;
|
|
110
|
+
const User = ctx.db.getCollection('users');
|
|
111
|
+
const user = yield User.model.findOne({
|
|
112
|
+
where: {
|
|
113
|
+
resetToken: token,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
if (!user) {
|
|
117
|
+
ctx.throw(401, 'Unauthorized');
|
|
118
|
+
}
|
|
119
|
+
ctx.body = user;
|
|
120
|
+
yield next();
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
export function updateProfile(ctx, next) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const { values } = ctx.action.params;
|
|
126
|
+
if (!ctx.state.currentUser) {
|
|
127
|
+
ctx.throw(401, 'Unauthorized');
|
|
128
|
+
}
|
|
129
|
+
yield ctx.state.currentUser.update(values);
|
|
130
|
+
ctx.body = ctx.state.currentUser;
|
|
131
|
+
yield next();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
export function changePassword(ctx, next) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const { values: { oldPassword, newPassword }, } = ctx.action.params;
|
|
137
|
+
if (!ctx.state.currentUser) {
|
|
138
|
+
ctx.throw(401, 'Unauthorized');
|
|
139
|
+
}
|
|
140
|
+
const User = ctx.db.getCollection('users');
|
|
141
|
+
const user = yield User.model.findOne({
|
|
142
|
+
where: {
|
|
143
|
+
email: ctx.state.currentUser.email,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
const pwd = User.getField('password');
|
|
147
|
+
const isValid = yield pwd.verify(oldPassword, user.password);
|
|
148
|
+
if (!isValid) {
|
|
149
|
+
ctx.throw(401, '密码错误,请您重新输入');
|
|
150
|
+
}
|
|
151
|
+
user.password = newPassword;
|
|
152
|
+
user.save();
|
|
153
|
+
ctx.body = ctx.state.currentUser.toJSON();
|
|
154
|
+
yield next();
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
export function setDefaultRole(ctx, next) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const { values: { roleName }, } = ctx.action.params;
|
|
160
|
+
yield ctx.state.currentUser.setDefaultRole(roleName);
|
|
161
|
+
ctx.body = 'ok';
|
|
162
|
+
yield next();
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=users.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/actions/users.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,UAAgB,KAAK,CAAC,GAAY,EAAE,IAAU;;QAClD,IAAI,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE;YACzB,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YAC5C,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;SACjB;aAAM;YACL,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;SACf;QACD,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;CAAA;AAED,MAAM,UAAgB,MAAM,CAAC,GAAY,EAAE,IAAU;;QACnD,MAAM,EAAE,WAAW,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;QAE5D,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE;YACxB,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;SAC3B;QACD,MAAM,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OA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AEtB,MAAM,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAErD,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;QAEhB,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;CAAA","sourcesContent":["import { Context, Next } from '@nocobase/actions';\nimport { PasswordField } from '@nocobase/database';\nimport crypto from 'crypto';\n\nexport async function check(ctx: Context, next: Next) {\n if (ctx.state.currentUser) {\n const user = ctx.state.currentUser.toJSON();\n ctx.body = user;\n } else {\n ctx.body = {};\n }\n await next();\n}\n\nexport async function signin(ctx: Context, next: Next) {\n const { uniqueField = 'email', values } = ctx.action.params;\n\n if (!values[uniqueField]) {\n ctx.throw(401, '请填写邮箱账号');\n }\n const User = ctx.db.getCollection('users');\n const user = await User.model.findOne<any>({\n where: {\n [uniqueField]: values[uniqueField],\n },\n });\n if (!user) {\n ctx.throw(401, '邮箱账号未注册');\n }\n const pwd = User.getField<PasswordField>('password');\n const isValid = await pwd.verify(values.password, user.password);\n if (!isValid) {\n ctx.throw(401, '密码错误,请您重新输入');\n }\n\n const pluginUser = ctx.app.getPlugin('@nocobase/plugin-users');\n\n ctx.body = {\n ...user.toJSON(),\n token: pluginUser.jwtService.sign({\n userId: user.get('id'),\n }),\n };\n await next();\n}\n\nexport async function signout(ctx: Context, next: Next) {\n ctx.body = ctx.state.currentUser;\n await next();\n}\n\nexport async function signup(ctx: Context, next: Next) {\n const User = ctx.db.getRepository('users');\n const { values } = ctx.action.params;\n const user = await User.create({ values });\n ctx.body = user;\n await next();\n}\n\nexport async function lostpassword(ctx: Context, next: Next) {\n const {\n values: { email },\n } = ctx.action.params;\n if (!email) {\n ctx.throw(401, '请填写邮箱账号');\n }\n const User = ctx.db.getCollection('users');\n const user = await User.model.findOne<any>({\n where: {\n email,\n },\n });\n if (!user) {\n ctx.throw(401, '邮箱账号未注册');\n }\n user.resetToken = crypto.randomBytes(20).toString('hex');\n await user.save();\n ctx.body = user;\n await next();\n}\n\nexport async function resetpassword(ctx: Context, next: Next) {\n const {\n values: { email, password, resetToken },\n } = ctx.action.params;\n const User = ctx.db.getCollection('users');\n const user = await User.model.findOne<any>({\n where: {\n email,\n resetToken,\n },\n });\n if (!user) {\n ctx.throw(401, 'Unauthorized');\n }\n user.token = null;\n user.resetToken = null;\n user.password = password;\n await user.save();\n ctx.body = user;\n await next();\n}\n\nexport async function getUserByResetToken(ctx: Context, next: Next) {\n const { token } = ctx.action.params;\n const User = ctx.db.getCollection('users');\n const user = await User.model.findOne({\n where: {\n resetToken: token,\n },\n });\n if (!user) {\n ctx.throw(401, 'Unauthorized');\n }\n ctx.body = user;\n await next();\n}\n\nexport async function updateProfile(ctx: Context, next: Next) {\n const { values } = ctx.action.params;\n if (!ctx.state.currentUser) {\n ctx.throw(401, 'Unauthorized');\n }\n await ctx.state.currentUser.update(values);\n ctx.body = ctx.state.currentUser;\n await next();\n}\n\nexport async function changePassword(ctx: Context, next: Next) {\n const {\n values: { oldPassword, newPassword },\n } = ctx.action.params;\n if (!ctx.state.currentUser) {\n ctx.throw(401, 'Unauthorized');\n }\n const User = ctx.db.getCollection('users');\n const user = await User.model.findOne<any>({\n where: {\n email: ctx.state.currentUser.email,\n },\n });\n const pwd = User.getField<PasswordField>('password');\n const isValid = await pwd.verify(oldPassword, user.password);\n if (!isValid) {\n ctx.throw(401, '密码错误,请您重新输入');\n }\n user.password = newPassword;\n user.save();\n ctx.body = ctx.state.currentUser.toJSON();\n await next();\n}\n\nexport async function setDefaultRole(ctx: Context, next: Next) {\n const {\n values: { roleName },\n } = ctx.action.params;\n\n await ctx.state.currentUser.setDefaultRole(roleName);\n\n ctx.body = 'ok';\n\n await next();\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles-users.js","sourceRoot":"","sources":["../../src/collections/roles-users.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,IAAI,EAAE,YAAY;IAClB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;CAC1B,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'rolesUsers',\n fields: [{ type: 'boolean', name: 'default' }],\n} as CollectionOptions;\n"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
name: 'users',
|
|
3
|
+
title: '{{t("Users")}}',
|
|
4
|
+
sortable: 'sort',
|
|
5
|
+
model: 'UserModel',
|
|
6
|
+
createdBy: true,
|
|
7
|
+
updatedBy: true,
|
|
8
|
+
fields: [
|
|
9
|
+
{
|
|
10
|
+
name: 'id',
|
|
11
|
+
type: 'integer',
|
|
12
|
+
autoIncrement: true,
|
|
13
|
+
primaryKey: true,
|
|
14
|
+
allowNull: false,
|
|
15
|
+
uiSchema: { type: 'number', title: '{{t("ID")}}', 'x-component': 'InputNumber', 'x-read-pretty': true },
|
|
16
|
+
interface: 'id',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
interface: 'input',
|
|
20
|
+
type: 'string',
|
|
21
|
+
name: 'nickname',
|
|
22
|
+
uiSchema: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
title: '{{t("Nickname")}}',
|
|
25
|
+
'x-component': 'Input',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
interface: 'email',
|
|
30
|
+
type: 'string',
|
|
31
|
+
name: 'email',
|
|
32
|
+
unique: true,
|
|
33
|
+
uiSchema: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
title: '{{t("Email")}}',
|
|
36
|
+
'x-component': 'Input',
|
|
37
|
+
require: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
interface: 'password',
|
|
42
|
+
type: 'password',
|
|
43
|
+
name: 'password',
|
|
44
|
+
hidden: true,
|
|
45
|
+
uiSchema: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
title: '{{t("Password")}}',
|
|
48
|
+
'x-component': 'Password',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
interface: 'linkTo',
|
|
53
|
+
type: 'belongsToMany',
|
|
54
|
+
name: 'roles',
|
|
55
|
+
target: 'roles',
|
|
56
|
+
foreignKey: 'userId',
|
|
57
|
+
otherKey: 'roleName',
|
|
58
|
+
sourceKey: 'id',
|
|
59
|
+
targetKey: 'name',
|
|
60
|
+
through: 'rolesUsers',
|
|
61
|
+
uiSchema: {
|
|
62
|
+
type: 'array',
|
|
63
|
+
title: '{{t("Roles")}}',
|
|
64
|
+
'x-component': 'RecordPicker',
|
|
65
|
+
'x-component-props': {
|
|
66
|
+
multiple: true,
|
|
67
|
+
fieldNames: {
|
|
68
|
+
label: 'title',
|
|
69
|
+
value: 'name',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
type: 'string',
|
|
76
|
+
name: 'appLang',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: 'string',
|
|
80
|
+
name: 'resetToken',
|
|
81
|
+
unique: true,
|
|
82
|
+
hidden: true,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=users.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/collections/users.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,gBAAgB;IACvB,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,WAAW;IAClB,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,IAAI;IACf,MAAM,EAAE;QACN;YACE,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,SAAS;YACf,aAAa,EAAE,IAAI;YACnB,UAAU,EAAE,IAAI;YAChB,SAAS,EAAE,KAAK;YAChB,QAAQ,EAAE,EAAE,IAAI,EAAE,Q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AE,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/esm/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './server';
|
package/esm/index.js
ADDED
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC","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,26 @@
|
|
|
1
|
+
import jwt from 'jsonwebtoken';
|
|
2
|
+
export class JwtService {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
this.options = options;
|
|
5
|
+
}
|
|
6
|
+
expiresIn() {
|
|
7
|
+
return this.options.expiresIn || '7d';
|
|
8
|
+
}
|
|
9
|
+
secret() {
|
|
10
|
+
return this.options.secret;
|
|
11
|
+
}
|
|
12
|
+
sign(payload) {
|
|
13
|
+
return jwt.sign(payload, this.secret(), { expiresIn: this.expiresIn() });
|
|
14
|
+
}
|
|
15
|
+
decode(token) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
jwt.verify(token, this.secret(), (err, decoded) => {
|
|
18
|
+
if (err) {
|
|
19
|
+
return reject(err);
|
|
20
|
+
}
|
|
21
|
+
resolve(decoded);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=jwt-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-service.js","sourceRoot":"","sources":["../src/jwt-service.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,cAAc,CAAC;AAO/B,MAAM,OAAO,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,GAAG,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,GAAG,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","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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function check(options: any): (ctx: any, next: any) => Promise<any>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
// TODO(usage): 拦截用户的处理暂时作为一个中间件导出,应用需要的时候可以直接使用这个中间件
|
|
11
|
+
export function check(options) {
|
|
12
|
+
return function check(ctx, next) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const { currentUser } = ctx.state;
|
|
15
|
+
if (!currentUser) {
|
|
16
|
+
return ctx.throw(401, 'Unauthorized');
|
|
17
|
+
}
|
|
18
|
+
return next();
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/middlewares/check.ts"],"names":[],"mappings":";;;;;;;;;AAAA,qDAAqD;AACrD,MAAM,UAAU,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","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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export { check } from './check';\nexport { parseToken } from './parseToken';\n"]}
|