@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/actions/users.js
CHANGED
|
@@ -1,277 +1,181 @@
|
|
|
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
|
-
return mod && mod.__esModule ? mod : {
|
|
49
|
-
"default": mod
|
|
50
|
-
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
13
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
exports.changePassword = exports.updateProfile = exports.getUserByResetToken = exports.resetpassword = exports.lostpassword = exports.signup = exports.signout = exports.signin = exports.check = void 0;
|
|
57
|
-
|
|
58
|
-
const database_1 = require("@nocobase/database");
|
|
59
|
-
|
|
60
|
-
const crypto_random_string_1 = __importDefault(require("crypto-random-string"));
|
|
61
|
-
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.setDefaultRole = exports.changePassword = exports.updateProfile = exports.getUserByResetToken = exports.resetpassword = exports.lostpassword = exports.signup = exports.signout = exports.signin = exports.check = void 0;
|
|
16
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
62
17
|
function check(ctx, next) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
if (ctx.state.currentUser) {
|
|
20
|
+
const user = ctx.state.currentUser.toJSON();
|
|
21
|
+
ctx.body = user;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
ctx.body = {};
|
|
25
|
+
}
|
|
26
|
+
yield next();
|
|
27
|
+
});
|
|
72
28
|
}
|
|
73
|
-
|
|
74
29
|
exports.check = check;
|
|
75
|
-
|
|
76
30
|
function signin(ctx, next) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const { uniqueField = 'email', values } = ctx.action.params;
|
|
33
|
+
if (!values[uniqueField]) {
|
|
34
|
+
ctx.throw(401, '请填写邮箱账号');
|
|
35
|
+
}
|
|
36
|
+
const User = ctx.db.getCollection('users');
|
|
37
|
+
const user = yield User.model.findOne({
|
|
38
|
+
where: {
|
|
39
|
+
[uniqueField]: values[uniqueField],
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
if (!user) {
|
|
43
|
+
ctx.throw(401, '邮箱账号未注册');
|
|
44
|
+
}
|
|
45
|
+
const pwd = User.getField('password');
|
|
46
|
+
const isValid = yield pwd.verify(values.password, user.password);
|
|
47
|
+
if (!isValid) {
|
|
48
|
+
ctx.throw(401, '密码错误,请您重新输入');
|
|
49
|
+
}
|
|
50
|
+
const pluginUser = ctx.app.getPlugin('@nocobase/plugin-users');
|
|
51
|
+
ctx.body = Object.assign(Object.assign({}, user.toJSON()), { token: pluginUser.jwtService.sign({
|
|
52
|
+
userId: user.get('id'),
|
|
53
|
+
}) });
|
|
54
|
+
yield next();
|
|
93
55
|
});
|
|
94
|
-
|
|
95
|
-
if (!user) {
|
|
96
|
-
ctx.throw(401, '邮箱账号未注册');
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const isValid = yield database_1.PASSWORD.verify(values.password, user.password);
|
|
100
|
-
|
|
101
|
-
if (!isValid) {
|
|
102
|
-
ctx.throw(401, '密码错误,请您重新输入');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (!user.token) {
|
|
106
|
-
user.token = (0, crypto_random_string_1.default)({
|
|
107
|
-
length: 20
|
|
108
|
-
});
|
|
109
|
-
yield user.save();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
ctx.body = user.toJSON();
|
|
113
|
-
delete ctx.body.password;
|
|
114
|
-
yield next();
|
|
115
|
-
});
|
|
116
56
|
}
|
|
117
|
-
|
|
118
57
|
exports.signin = signin;
|
|
119
|
-
|
|
120
58
|
function signout(ctx, next) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
ctx.body = ctx.state.currentUser;
|
|
61
|
+
yield next();
|
|
62
|
+
});
|
|
125
63
|
}
|
|
126
|
-
|
|
127
64
|
exports.signout = signout;
|
|
128
|
-
|
|
129
65
|
function signup(ctx, next) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
} catch (error) {
|
|
138
|
-
if (error.errors) {
|
|
139
|
-
ctx.throw(401, error.errors.map(data => data.message).join(', '));
|
|
140
|
-
} else {
|
|
141
|
-
ctx.throw(401, '注册失败');
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
yield next();
|
|
146
|
-
});
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const User = ctx.db.getRepository('users');
|
|
68
|
+
const { values } = ctx.action.params;
|
|
69
|
+
const user = yield User.create({ values });
|
|
70
|
+
ctx.body = user;
|
|
71
|
+
yield next();
|
|
72
|
+
});
|
|
147
73
|
}
|
|
148
|
-
|
|
149
74
|
exports.signup = signup;
|
|
150
|
-
|
|
151
75
|
function lostpassword(ctx, next) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const { values: { email }, } = ctx.action.params;
|
|
78
|
+
if (!email) {
|
|
79
|
+
ctx.throw(401, '请填写邮箱账号');
|
|
80
|
+
}
|
|
81
|
+
const User = ctx.db.getCollection('users');
|
|
82
|
+
const user = yield User.model.findOne({
|
|
83
|
+
where: {
|
|
84
|
+
email,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
if (!user) {
|
|
88
|
+
ctx.throw(401, '邮箱账号未注册');
|
|
89
|
+
}
|
|
90
|
+
user.resetToken = crypto_1.default.randomBytes(20).toString('hex');
|
|
91
|
+
yield user.save();
|
|
92
|
+
ctx.body = user;
|
|
93
|
+
yield next();
|
|
164
94
|
});
|
|
165
|
-
|
|
166
|
-
if (!user) {
|
|
167
|
-
ctx.throw(401, '邮箱账号未注册');
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
user.reset_token = (0, crypto_random_string_1.default)({
|
|
171
|
-
length: 20
|
|
172
|
-
});
|
|
173
|
-
yield user.save();
|
|
174
|
-
ctx.body = user;
|
|
175
|
-
yield next();
|
|
176
|
-
});
|
|
177
95
|
}
|
|
178
|
-
|
|
179
96
|
exports.lostpassword = lostpassword;
|
|
180
|
-
|
|
181
97
|
function resetpassword(ctx, next) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const { values: { email, password, resetToken }, } = ctx.action.params;
|
|
100
|
+
const User = ctx.db.getCollection('users');
|
|
101
|
+
const user = yield User.model.findOne({
|
|
102
|
+
where: {
|
|
103
|
+
email,
|
|
104
|
+
resetToken,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
if (!user) {
|
|
108
|
+
ctx.throw(401, 'Unauthorized');
|
|
109
|
+
}
|
|
110
|
+
user.token = null;
|
|
111
|
+
user.resetToken = null;
|
|
112
|
+
user.password = password;
|
|
113
|
+
yield user.save();
|
|
114
|
+
ctx.body = user;
|
|
115
|
+
yield next();
|
|
193
116
|
});
|
|
194
|
-
|
|
195
|
-
if (!user) {
|
|
196
|
-
ctx.throw(401, 'Unauthorized');
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
user.token = null;
|
|
200
|
-
user.reset_token = null;
|
|
201
|
-
user.password = password;
|
|
202
|
-
yield user.save();
|
|
203
|
-
ctx.body = user;
|
|
204
|
-
yield next();
|
|
205
|
-
});
|
|
206
117
|
}
|
|
207
|
-
|
|
208
118
|
exports.resetpassword = resetpassword;
|
|
209
|
-
|
|
210
119
|
function getUserByResetToken(ctx, next) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
const { token } = ctx.action.params;
|
|
122
|
+
const User = ctx.db.getCollection('users');
|
|
123
|
+
const user = yield User.model.findOne({
|
|
124
|
+
where: {
|
|
125
|
+
resetToken: token,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
if (!user) {
|
|
129
|
+
ctx.throw(401, 'Unauthorized');
|
|
130
|
+
}
|
|
131
|
+
ctx.body = user;
|
|
132
|
+
yield next();
|
|
218
133
|
});
|
|
219
|
-
|
|
220
|
-
if (!user) {
|
|
221
|
-
ctx.throw(401, 'Unauthorized');
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
ctx.body = user;
|
|
225
|
-
yield next();
|
|
226
|
-
});
|
|
227
134
|
}
|
|
228
|
-
|
|
229
135
|
exports.getUserByResetToken = getUserByResetToken;
|
|
230
|
-
|
|
231
136
|
function updateProfile(ctx, next) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
yield next();
|
|
242
|
-
});
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const { values } = ctx.action.params;
|
|
139
|
+
if (!ctx.state.currentUser) {
|
|
140
|
+
ctx.throw(401, 'Unauthorized');
|
|
141
|
+
}
|
|
142
|
+
yield ctx.state.currentUser.update(values);
|
|
143
|
+
ctx.body = ctx.state.currentUser;
|
|
144
|
+
yield next();
|
|
145
|
+
});
|
|
243
146
|
}
|
|
244
|
-
|
|
245
147
|
exports.updateProfile = updateProfile;
|
|
246
|
-
|
|
247
148
|
function changePassword(ctx, next) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const { values: { oldPassword, newPassword }, } = ctx.action.params;
|
|
151
|
+
if (!ctx.state.currentUser) {
|
|
152
|
+
ctx.throw(401, 'Unauthorized');
|
|
153
|
+
}
|
|
154
|
+
const User = ctx.db.getCollection('users');
|
|
155
|
+
const user = yield User.model.findOne({
|
|
156
|
+
where: {
|
|
157
|
+
email: ctx.state.currentUser.email,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
const pwd = User.getField('password');
|
|
161
|
+
const isValid = yield pwd.verify(oldPassword, user.password);
|
|
162
|
+
if (!isValid) {
|
|
163
|
+
ctx.throw(401, '密码错误,请您重新输入');
|
|
164
|
+
}
|
|
165
|
+
user.password = newPassword;
|
|
166
|
+
user.save();
|
|
167
|
+
ctx.body = ctx.state.currentUser.toJSON();
|
|
168
|
+
yield next();
|
|
262
169
|
});
|
|
263
|
-
const isValid = yield database_1.PASSWORD.verify(oldPassword, user.password);
|
|
264
|
-
|
|
265
|
-
if (!isValid) {
|
|
266
|
-
ctx.throw(401, '密码错误,请您重新输入');
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
user.password = newPassword;
|
|
270
|
-
user.save();
|
|
271
|
-
ctx.body = ctx.state.currentUser.toJSON();
|
|
272
|
-
yield next();
|
|
273
|
-
});
|
|
274
170
|
}
|
|
275
|
-
|
|
276
171
|
exports.changePassword = changePassword;
|
|
277
|
-
|
|
172
|
+
function setDefaultRole(ctx, next) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
const { values: { roleName }, } = ctx.action.params;
|
|
175
|
+
yield ctx.state.currentUser.setDefaultRole(roleName);
|
|
176
|
+
ctx.body = 'ok';
|
|
177
|
+
yield next();
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
exports.setDefaultRole = setDefaultRole;
|
|
181
|
+
//# sourceMappingURL=users.js.map
|
package/lib/actions/users.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["actions/users.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/actions/users.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,oDAA4B;AAE5B,SAAsB,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;AARD,sBAQC;AAED,SAAsB,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,KA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,EAAE,EAAE,QAAQ,EAAE,GACrB,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;QAEtB,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;AAVD,wCAUC","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,kBAAe;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"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const _default:
|
|
1
|
+
import { CollectionOptions } from '@nocobase/database';
|
|
2
|
+
declare const _default: CollectionOptions;
|
|
3
3
|
export default _default;
|