@nocobase/plugin-users 0.8.0-alpha.9 → 0.8.1-alpha.4

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.
@@ -14,7 +14,7 @@ var _default = {
14
14
  logging: true,
15
15
  fields: [{
16
16
  name: 'id',
17
- type: 'integer',
17
+ type: 'bigInt',
18
18
  autoIncrement: true,
19
19
  primaryKey: true,
20
20
  allowNull: false,
@@ -44,7 +44,7 @@ var _default = {
44
44
  title: '{{t("Email")}}',
45
45
  'x-component': 'Input',
46
46
  'x-validator': 'email',
47
- require: true
47
+ required: true
48
48
  }
49
49
  }, {
50
50
  interface: 'phone',
@@ -56,7 +56,7 @@ var _default = {
56
56
  title: '{{t("Phone")}}',
57
57
  'x-component': 'Input',
58
58
  'x-validator': 'phone',
59
- require: true
59
+ required: true
60
60
  }
61
61
  }, {
62
62
  interface: 'password',
@@ -86,9 +86,11 @@ function _findUserByToken() {
86
86
  id: userId
87
87
  }
88
88
  });
89
+ ctx.logger.info(`Current user id: ${userId}`);
89
90
  return user;
90
91
  } catch (error) {
91
92
  console.log(error);
93
+ ctx.logger.error(error);
92
94
  return null;
93
95
  }
94
96
  });
package/lib/server.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { HandlerType, Middleware } from '@nocobase/resourcer';
1
+ import { HandlerType } from '@nocobase/resourcer';
2
2
  import { Plugin } from '@nocobase/server';
3
3
  import { Registry } from '@nocobase/utils';
4
4
  import { JwtOptions, JwtService } from './jwt-service';
@@ -8,7 +8,6 @@ export interface UserPluginConfig {
8
8
  }
9
9
  export default class UsersPlugin extends Plugin<UserPluginConfig> {
10
10
  jwtService: JwtService;
11
- tokenMiddleware: Middleware;
12
11
  authenticators: Registry<HandlerType>;
13
12
  constructor(app: any, options: any);
14
13
  beforeLoad(): Promise<void>;
@@ -19,4 +18,5 @@ export default class UsersPlugin extends Plugin<UserPluginConfig> {
19
18
  rootNickname: any;
20
19
  };
21
20
  install(options: any): Promise<void>;
21
+ initVerification(): Promise<void>;
22
22
  }
package/lib/server.js CHANGED
@@ -35,16 +35,6 @@ function _database() {
35
35
  return data;
36
36
  }
37
37
 
38
- function _resourcer() {
39
- const data = require("@nocobase/resourcer");
40
-
41
- _resourcer = function _resourcer() {
42
- return data;
43
- };
44
-
45
- return data;
46
- }
47
-
48
38
  function _server() {
49
39
  const data = require("@nocobase/server");
50
40
 
@@ -103,10 +93,8 @@ class UsersPlugin extends _server().Plugin {
103
93
  constructor(app, options) {
104
94
  super(app, options);
105
95
  this.jwtService = void 0;
106
- this.tokenMiddleware = void 0;
107
96
  this.authenticators = new (_utils().Registry)();
108
97
  this.jwtService = new _jwtService.JwtService((options === null || options === void 0 ? void 0 : options.jwt) || {});
109
- this.tokenMiddleware = new (_resourcer().Middleware)(_middlewares.parseToken);
110
98
  }
111
99
 
112
100
  beforeLoad() {
@@ -155,7 +143,7 @@ class UsersPlugin extends _server().Plugin {
155
143
  if (createdBy === true) {
156
144
  collection.setField('createdById', {
157
145
  type: 'context',
158
- dataType: 'integer',
146
+ dataType: 'bigInt',
159
147
  dataIndex: 'state.currentUser.id',
160
148
  createOnly: true,
161
149
  visible: true,
@@ -172,7 +160,7 @@ class UsersPlugin extends _server().Plugin {
172
160
  if (updatedBy === true) {
173
161
  collection.setField('updatedById', {
174
162
  type: 'context',
175
- dataType: 'integer',
163
+ dataType: 'bigInt',
176
164
  dataIndex: 'state.currentUser.id',
177
165
  visible: true,
178
166
  index: true
@@ -202,6 +190,8 @@ class UsersPlugin extends _server().Plugin {
202
190
  const loggedInActions = ['signout', 'updateProfile', 'changePassword'];
203
191
  publicActions.forEach(action => _this.app.acl.allow('users', action));
204
192
  loggedInActions.forEach(action => _this.app.acl.allow('users', action, 'loggedIn'));
193
+
194
+ _this.app.on('beforeStart', () => _this.initVerification());
205
195
  })();
206
196
  }
207
197
 
@@ -221,110 +211,7 @@ class UsersPlugin extends _server().Plugin {
221
211
  }
222
212
  });
223
213
 
224
- (0, _authenticators.default)(_this2); // TODO(module): should move to preset
225
-
226
- const verificationPlugin = _this2.app.getPlugin('verification');
227
-
228
- if (verificationPlugin && process.env.DEFAULT_SMS_VERIFY_CODE_PROVIDER) {
229
- verificationPlugin.interceptors.register('users:signin', {
230
- manual: true,
231
- provider: process.env.DEFAULT_SMS_VERIFY_CODE_PROVIDER,
232
-
233
- getReceiver(ctx) {
234
- return ctx.action.params.values.phone;
235
- },
236
-
237
- expiresIn: 120,
238
- validate: function () {
239
- var _validate = _asyncToGenerator(function* (ctx, phone) {
240
- if (!phone) {
241
- throw new Error(ctx.t('Not a valid cellphone number, please re-enter'));
242
- }
243
-
244
- const User = _this2.db.getCollection('users');
245
-
246
- const exists = yield User.model.count({
247
- where: {
248
- phone
249
- }
250
- });
251
-
252
- if (!exists) {
253
- throw new Error(ctx.t('The phone number is not registered, please register first', {
254
- ns: _2.namespace
255
- }));
256
- }
257
-
258
- return true;
259
- });
260
-
261
- function validate(_x, _x2) {
262
- return _validate.apply(this, arguments);
263
- }
264
-
265
- return validate;
266
- }()
267
- });
268
- verificationPlugin.interceptors.register('users:signup', {
269
- provider: process.env.DEFAULT_SMS_VERIFY_CODE_PROVIDER,
270
-
271
- getReceiver(ctx) {
272
- return ctx.action.params.values.phone;
273
- },
274
-
275
- expiresIn: 120,
276
- validate: function () {
277
- var _validate2 = _asyncToGenerator(function* (ctx, phone) {
278
- if (!phone) {
279
- throw new Error(ctx.t('Not a valid cellphone number, please re-enter', {
280
- ns: _2.namespace
281
- }));
282
- }
283
-
284
- const User = _this2.db.getCollection('users');
285
-
286
- const exists = yield User.model.count({
287
- where: {
288
- phone
289
- }
290
- });
291
-
292
- if (exists) {
293
- throw new Error(ctx.t('The phone number has been registered, please login directly', {
294
- ns: _2.namespace
295
- }));
296
- }
297
-
298
- return true;
299
- });
300
-
301
- function validate(_x3, _x4) {
302
- return _validate2.apply(this, arguments);
303
- }
304
-
305
- return validate;
306
- }()
307
- });
308
-
309
- _this2.authenticators.register('sms', (ctx, next) => verificationPlugin.intercept(ctx, /*#__PURE__*/_asyncToGenerator(function* () {
310
- const values = ctx.action.params.values;
311
- const User = ctx.db.getCollection('users');
312
- const user = yield User.model.findOne({
313
- where: {
314
- phone: values.phone
315
- }
316
- });
317
-
318
- if (!user) {
319
- return ctx.throw(404, ctx.t('The phone number is incorrect, please re-enter', {
320
- ns: _2.namespace
321
- }));
322
- }
323
-
324
- ctx.state.currentUser = user;
325
- return next();
326
- })));
327
- }
214
+ (0, _authenticators.default)(_this2);
328
215
  })();
329
216
  }
330
217
 
@@ -336,13 +223,13 @@ class UsersPlugin extends _server().Plugin {
336
223
  INIT_ROOT_PASSWORD = _process$env.INIT_ROOT_PASSWORD,
337
224
  INIT_ROOT_EMAIL = _process$env.INIT_ROOT_EMAIL;
338
225
 
339
- const _ref2 = options.users || (options === null || options === void 0 ? void 0 : (_options$cliArgs = options.cliArgs) === null || _options$cliArgs === void 0 ? void 0 : _options$cliArgs[0]) || {},
340
- _ref2$rootEmail = _ref2.rootEmail,
341
- rootEmail = _ref2$rootEmail === void 0 ? INIT_ROOT_EMAIL : _ref2$rootEmail,
342
- _ref2$rootPassword = _ref2.rootPassword,
343
- rootPassword = _ref2$rootPassword === void 0 ? INIT_ROOT_PASSWORD : _ref2$rootPassword,
344
- _ref2$rootNickname = _ref2.rootNickname,
345
- rootNickname = _ref2$rootNickname === void 0 ? INIT_ROOT_NICKNAME || 'Super Admin' : _ref2$rootNickname;
226
+ const _ref = options.users || (options === null || options === void 0 ? void 0 : (_options$cliArgs = options.cliArgs) === null || _options$cliArgs === void 0 ? void 0 : _options$cliArgs[0]) || {},
227
+ _ref$rootEmail = _ref.rootEmail,
228
+ rootEmail = _ref$rootEmail === void 0 ? INIT_ROOT_EMAIL : _ref$rootEmail,
229
+ _ref$rootPassword = _ref.rootPassword,
230
+ rootPassword = _ref$rootPassword === void 0 ? INIT_ROOT_PASSWORD : _ref$rootPassword,
231
+ _ref$rootNickname = _ref.rootNickname,
232
+ rootNickname = _ref$rootNickname === void 0 ? INIT_ROOT_NICKNAME || 'Super Admin' : _ref$rootNickname;
346
233
 
347
234
  return {
348
235
  rootEmail,
@@ -376,6 +263,123 @@ class UsersPlugin extends _server().Plugin {
376
263
  yield repo.db2cm('users');
377
264
  }
378
265
  })();
266
+ } // TODO(module): should move to preset or dynamic configuration panel
267
+
268
+
269
+ initVerification() {
270
+ var _this4 = this;
271
+
272
+ return _asyncToGenerator(function* () {
273
+ const verificationPlugin = _this4.app.getPlugin('verification');
274
+
275
+ if (!verificationPlugin) {
276
+ return;
277
+ }
278
+
279
+ const systemSettingsRepo = _this4.db.getRepository('systemSettings');
280
+
281
+ const settings = yield systemSettingsRepo.findOne();
282
+
283
+ if (!settings.smsAuthEnabled) {
284
+ return;
285
+ }
286
+
287
+ verificationPlugin.interceptors.register('users:signin', {
288
+ manual: true,
289
+
290
+ getReceiver(ctx) {
291
+ return ctx.action.params.values.phone;
292
+ },
293
+
294
+ expiresIn: 120,
295
+ validate: function () {
296
+ var _validate = _asyncToGenerator(function* (ctx, phone) {
297
+ if (!phone) {
298
+ throw new Error(ctx.t('Not a valid cellphone number, please re-enter'));
299
+ }
300
+
301
+ const User = _this4.db.getCollection('users');
302
+
303
+ const exists = yield User.model.count({
304
+ where: {
305
+ phone
306
+ }
307
+ });
308
+
309
+ if (!exists) {
310
+ throw new Error(ctx.t('The phone number is not registered, please register first', {
311
+ ns: _2.namespace
312
+ }));
313
+ }
314
+
315
+ return true;
316
+ });
317
+
318
+ function validate(_x, _x2) {
319
+ return _validate.apply(this, arguments);
320
+ }
321
+
322
+ return validate;
323
+ }()
324
+ });
325
+ verificationPlugin.interceptors.register('users:signup', {
326
+ getReceiver(ctx) {
327
+ return ctx.action.params.values.phone;
328
+ },
329
+
330
+ expiresIn: 120,
331
+ validate: function () {
332
+ var _validate2 = _asyncToGenerator(function* (ctx, phone) {
333
+ if (!phone) {
334
+ throw new Error(ctx.t('Not a valid cellphone number, please re-enter', {
335
+ ns: _2.namespace
336
+ }));
337
+ }
338
+
339
+ const User = _this4.db.getCollection('users');
340
+
341
+ const exists = yield User.model.count({
342
+ where: {
343
+ phone
344
+ }
345
+ });
346
+
347
+ if (exists) {
348
+ throw new Error(ctx.t('The phone number has been registered, please login directly', {
349
+ ns: _2.namespace
350
+ }));
351
+ }
352
+
353
+ return true;
354
+ });
355
+
356
+ function validate(_x3, _x4) {
357
+ return _validate2.apply(this, arguments);
358
+ }
359
+
360
+ return validate;
361
+ }()
362
+ });
363
+
364
+ _this4.authenticators.register('sms', (ctx, next) => verificationPlugin.intercept(ctx, /*#__PURE__*/_asyncToGenerator(function* () {
365
+ const values = ctx.action.params.values;
366
+ const User = ctx.db.getCollection('users');
367
+ const user = yield User.model.findOne({
368
+ where: {
369
+ phone: values.phone
370
+ }
371
+ });
372
+
373
+ if (!user) {
374
+ return ctx.throw(404, ctx.t('The phone number is incorrect, please re-enter', {
375
+ ns: _2.namespace
376
+ }));
377
+ }
378
+
379
+ ctx.state.currentUser = user;
380
+ return next();
381
+ })));
382
+ })();
379
383
  }
380
384
 
381
385
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-users",
3
- "version": "0.8.0-alpha.9",
3
+ "version": "0.8.1-alpha.4",
4
4
  "main": "lib/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "licenses": [
@@ -10,17 +10,17 @@
10
10
  }
11
11
  ],
12
12
  "dependencies": {
13
- "@nocobase/actions": "0.8.0-alpha.9",
14
- "@nocobase/database": "0.8.0-alpha.9",
15
- "@nocobase/resourcer": "0.8.0-alpha.9",
16
- "@nocobase/server": "0.8.0-alpha.9",
17
- "@nocobase/utils": "0.8.0-alpha.9",
13
+ "@nocobase/actions": "0.8.1-alpha.4",
14
+ "@nocobase/database": "0.8.1-alpha.4",
15
+ "@nocobase/resourcer": "0.8.1-alpha.4",
16
+ "@nocobase/server": "0.8.1-alpha.4",
17
+ "@nocobase/utils": "0.8.1-alpha.4",
18
18
  "json-templates": "^4.2.0",
19
19
  "jsonwebtoken": "^8.5.1"
20
20
  },
21
21
  "devDependencies": {
22
- "@nocobase/test": "0.8.0-alpha.9",
22
+ "@nocobase/test": "0.8.1-alpha.4",
23
23
  "@types/jsonwebtoken": "^8.5.8"
24
24
  },
25
- "gitHead": "6afe02d59bb22df0f96a7605c9001dcc17a30d6a"
25
+ "gitHead": "22ccdf7bd7fcbd16aeefd5250db237a4bd1ccff1"
26
26
  }