@nocobase/plugin-auth 0.10.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.
Files changed (89) hide show
  1. package/README.md +117 -0
  2. package/client.d.ts +3 -0
  3. package/client.js +65 -0
  4. package/lib/client/basic/Options.d.ts +2 -0
  5. package/lib/client/basic/Options.js +51 -0
  6. package/lib/client/basic/SigninPage.d.ts +6 -0
  7. package/lib/client/basic/SigninPage.js +100 -0
  8. package/lib/client/basic/SignupPage.d.ts +5 -0
  9. package/lib/client/basic/SignupPage.js +131 -0
  10. package/lib/client/index.d.ts +3 -0
  11. package/lib/client/index.js +56 -0
  12. package/lib/client/locale/index.d.ts +2 -0
  13. package/lib/client/locale/index.js +19 -0
  14. package/lib/client/locale/zh-CN.d.ts +9 -0
  15. package/lib/client/locale/zh-CN.js +16 -0
  16. package/lib/client/settings/Authenticator.d.ts +2 -0
  17. package/lib/client/settings/Authenticator.js +159 -0
  18. package/lib/client/settings/Options.d.ts +3 -0
  19. package/lib/client/settings/Options.js +56 -0
  20. package/lib/client/settings/authType.d.ts +16 -0
  21. package/lib/client/settings/authType.js +27 -0
  22. package/lib/client/settings/schemas/authenticators.d.ts +3 -0
  23. package/lib/client/settings/schemas/authenticators.js +438 -0
  24. package/lib/index.d.ts +1 -0
  25. package/lib/index.js +20 -0
  26. package/lib/preset.d.ts +3 -0
  27. package/lib/preset.js +12 -0
  28. package/lib/server/actions/auth.d.ts +8 -0
  29. package/lib/server/actions/auth.js +51 -0
  30. package/lib/server/actions/authenticators.d.ts +8 -0
  31. package/lib/server/actions/authenticators.js +131 -0
  32. package/lib/server/basic-auth.d.ts +10 -0
  33. package/lib/server/basic-auth.js +183 -0
  34. package/lib/server/collections/authenticators.d.ts +6 -0
  35. package/lib/server/collections/authenticators.js +93 -0
  36. package/lib/server/collections/users-authenticators.d.ts +7 -0
  37. package/lib/server/collections/users-authenticators.js +75 -0
  38. package/lib/server/index.d.ts +2 -0
  39. package/lib/server/index.js +20 -0
  40. package/lib/server/locale/en-US.d.ts +9 -0
  41. package/lib/server/locale/en-US.js +15 -0
  42. package/lib/server/locale/index.d.ts +3 -0
  43. package/lib/server/locale/index.js +27 -0
  44. package/lib/server/locale/ja-JP.d.ts +5 -0
  45. package/lib/server/locale/ja-JP.js +11 -0
  46. package/lib/server/locale/pt-BR.d.ts +9 -0
  47. package/lib/server/locale/pt-BR.js +15 -0
  48. package/lib/server/locale/zh-CN.d.ts +10 -0
  49. package/lib/server/locale/zh-CN.js +16 -0
  50. package/lib/server/migrations/20230506152253-basic-authenticator.d.ts +5 -0
  51. package/lib/server/migrations/20230506152253-basic-authenticator.js +40 -0
  52. package/lib/server/migrations/20230607174500-update-basic.d.ts +5 -0
  53. package/lib/server/migrations/20230607174500-update-basic.js +43 -0
  54. package/lib/server/model/authenticator.d.ts +6 -0
  55. package/lib/server/model/authenticator.js +72 -0
  56. package/lib/server/plugin.d.ts +11 -0
  57. package/lib/server/plugin.js +130 -0
  58. package/package.json +17 -0
  59. package/server.d.ts +3 -0
  60. package/server.js +65 -0
  61. package/src/client/basic/Options.tsx +31 -0
  62. package/src/client/basic/SigninPage.tsx +65 -0
  63. package/src/client/basic/SignupPage.tsx +91 -0
  64. package/src/client/index.tsx +41 -0
  65. package/src/client/locale/index.ts +7 -0
  66. package/src/client/locale/zh-CN.ts +10 -0
  67. package/src/client/settings/Authenticator.tsx +95 -0
  68. package/src/client/settings/Options.tsx +35 -0
  69. package/src/client/settings/authType.ts +18 -0
  70. package/src/client/settings/schemas/authenticators.ts +402 -0
  71. package/src/index.ts +1 -0
  72. package/src/preset.ts +4 -0
  73. package/src/server/__tests__/actions.test.ts +142 -0
  74. package/src/server/actions/auth.ts +20 -0
  75. package/src/server/actions/authenticators.ts +85 -0
  76. package/src/server/basic-auth.ts +128 -0
  77. package/src/server/collections/.gitkeep +0 -0
  78. package/src/server/collections/authenticators.ts +97 -0
  79. package/src/server/collections/users-authenticators.ts +73 -0
  80. package/src/server/index.ts +2 -0
  81. package/src/server/locale/en-US.ts +10 -0
  82. package/src/server/locale/index.ts +3 -0
  83. package/src/server/locale/ja-JP.ts +4 -0
  84. package/src/server/locale/pt-BR.ts +10 -0
  85. package/src/server/locale/zh-CN.ts +9 -0
  86. package/src/server/migrations/20230506152253-basic-authenticator.ts +22 -0
  87. package/src/server/migrations/20230607174500-update-basic.ts +25 -0
  88. package/src/server/model/authenticator.ts +48 -0
  89. package/src/server/plugin.ts +92 -0
@@ -0,0 +1,438 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createFormSchema = exports.authenticatorsSchema = void 0;
7
+ function _shared() {
8
+ const data = require("@formily/shared");
9
+ _shared = function _shared() {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _client() {
15
+ const data = require("@nocobase/client");
16
+ _client = function _client() {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _react() {
22
+ const data = require("react");
23
+ _react = function _react() {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ var _authType = require("../authType");
29
+ function _antd() {
30
+ const data = require("antd");
31
+ _antd = function _antd() {
32
+ return data;
33
+ };
34
+ return data;
35
+ }
36
+ function _reactI18next() {
37
+ const data = require("react-i18next");
38
+ _reactI18next = function _reactI18next() {
39
+ return data;
40
+ };
41
+ return data;
42
+ }
43
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
44
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
45
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
46
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
47
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
48
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
49
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
50
+ const collection = {
51
+ name: 'authenticators',
52
+ sortable: true,
53
+ fields: [{
54
+ name: 'id',
55
+ type: 'string',
56
+ interface: 'id'
57
+ }, {
58
+ interface: 'input',
59
+ type: 'string',
60
+ name: 'name',
61
+ uiSchema: {
62
+ type: 'string',
63
+ title: '{{t("Name")}}',
64
+ 'x-component': 'Input',
65
+ required: true
66
+ }
67
+ }, {
68
+ interface: 'input',
69
+ type: 'string',
70
+ name: 'authType',
71
+ uiSchema: {
72
+ type: 'string',
73
+ title: '{{t("Auth Type", {ns: "auth"})}}',
74
+ 'x-component': 'Select',
75
+ required: true
76
+ }
77
+ }, {
78
+ interface: 'input',
79
+ type: 'string',
80
+ name: 'title',
81
+ uiSchema: {
82
+ type: 'string',
83
+ title: '{{t("Title")}}',
84
+ 'x-component': 'Input'
85
+ }
86
+ }, {
87
+ interface: 'textarea',
88
+ type: 'string',
89
+ name: 'description',
90
+ uiSchema: {
91
+ type: 'string',
92
+ title: '{{t("Description")}}',
93
+ 'x-component': 'Input'
94
+ }
95
+ }, {
96
+ type: 'boolean',
97
+ name: 'enabled',
98
+ uiSchema: {
99
+ type: 'boolean',
100
+ title: '{{t("Enabled")}}',
101
+ 'x-component': 'Checkbox'
102
+ }
103
+ }]
104
+ };
105
+ const createFormSchema = {
106
+ type: 'object',
107
+ properties: {
108
+ drawer: {
109
+ type: 'void',
110
+ 'x-component': 'Action.Drawer',
111
+ 'x-decorator': 'Form',
112
+ 'x-decorator-props': {
113
+ useValues(options) {
114
+ const ctx = (0, _client().useActionContext)();
115
+ const _useContext = (0, _react().useContext)(_authType.AuthTypeContext),
116
+ authType = _useContext.type;
117
+ return (0, _client().useRequest)(() => Promise.resolve({
118
+ data: {
119
+ name: `s_${(0, _shared().uid)()}`,
120
+ authType
121
+ }
122
+ }), _objectSpread(_objectSpread({}, options), {}, {
123
+ refreshDeps: [ctx.visible]
124
+ }));
125
+ }
126
+ },
127
+ title: '{{t("Add new")}}',
128
+ properties: {
129
+ name: {
130
+ 'x-component': 'CollectionField',
131
+ 'x-decorator': 'FormItem'
132
+ },
133
+ authType: {
134
+ 'x-component': 'CollectionField',
135
+ 'x-decorator': 'FormItem',
136
+ 'x-component-props': {
137
+ options: '{{ types }}'
138
+ }
139
+ },
140
+ title: {
141
+ 'x-component': 'CollectionField',
142
+ 'x-decorator': 'FormItem'
143
+ },
144
+ description: {
145
+ 'x-component': 'CollectionField',
146
+ 'x-decorator': 'FormItem'
147
+ },
148
+ enabled: {
149
+ 'x-component': 'CollectionField',
150
+ 'x-decorator': 'FormItem'
151
+ },
152
+ options: {
153
+ type: 'object',
154
+ 'x-component': 'Options'
155
+ },
156
+ footer: {
157
+ type: 'void',
158
+ 'x-component': 'Action.Drawer.Footer',
159
+ properties: {
160
+ cancel: {
161
+ title: '{{t("Cancel")}}',
162
+ 'x-component': 'Action',
163
+ 'x-component-props': {
164
+ useAction: '{{ cm.useCancelAction }}'
165
+ }
166
+ },
167
+ submit: {
168
+ title: '{{t("Submit")}}',
169
+ 'x-component': 'Action',
170
+ 'x-component-props': {
171
+ type: 'primary',
172
+ useAction: '{{ cm.useCreateAction }}'
173
+ }
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ };
181
+ exports.createFormSchema = createFormSchema;
182
+ const authenticatorsSchema = {
183
+ type: 'void',
184
+ name: 'authenticators',
185
+ 'x-decorator': 'ResourceActionProvider',
186
+ 'x-decorator-props': {
187
+ collection,
188
+ resourceName: 'authenticators',
189
+ dragSort: true,
190
+ request: {
191
+ resource: 'authenticators',
192
+ action: 'list',
193
+ params: {
194
+ pageSize: 50,
195
+ sort: 'sort',
196
+ appends: []
197
+ }
198
+ }
199
+ },
200
+ 'x-component': 'CollectionProvider',
201
+ 'x-component-props': {
202
+ collection
203
+ },
204
+ properties: {
205
+ actions: {
206
+ type: 'void',
207
+ 'x-component': 'ActionBar',
208
+ 'x-component-props': {
209
+ style: {
210
+ marginBottom: 16
211
+ }
212
+ },
213
+ properties: {
214
+ delete: {
215
+ type: 'void',
216
+ title: '{{t("Delete")}}',
217
+ 'x-component': 'Action',
218
+ 'x-component-props': {
219
+ useAction: '{{ cm.useBulkDestroyAction }}',
220
+ confirm: {
221
+ title: "{{t('Delete')}}",
222
+ content: "{{t('Are you sure you want to delete it?')}}"
223
+ }
224
+ }
225
+ },
226
+ create: {
227
+ type: 'void',
228
+ title: '{{t("Add new")}}',
229
+ 'x-component': 'AddNew',
230
+ 'x-component-props': {
231
+ type: 'primary'
232
+ }
233
+ }
234
+ }
235
+ },
236
+ table: {
237
+ type: 'void',
238
+ 'x-uid': 'input',
239
+ 'x-component': 'Table.Void',
240
+ 'x-component-props': {
241
+ rowKey: 'id',
242
+ rowSelection: {
243
+ type: 'checkbox'
244
+ },
245
+ useDataSource: '{{ cm.useDataSourceFromRAC }}',
246
+ useAction() {
247
+ const api = (0, _client().useAPIClient)();
248
+ const _useTranslation = (0, _reactI18next().useTranslation)(),
249
+ t = _useTranslation.t;
250
+ return {
251
+ move(from, to) {
252
+ return _asyncToGenerator(function* () {
253
+ yield api.resource('authenticators').move({
254
+ sourceId: from.id,
255
+ targetId: to.id
256
+ });
257
+ _antd().message.success(t('Saved successfully'), 0.2);
258
+ })();
259
+ }
260
+ };
261
+ }
262
+ },
263
+ properties: {
264
+ id: {
265
+ type: 'void',
266
+ 'x-decorator': 'Table.Column.Decorator',
267
+ 'x-component': 'Table.Column',
268
+ properties: {
269
+ id: {
270
+ type: 'number',
271
+ 'x-component': 'CollectionField',
272
+ 'x-read-pretty': true
273
+ }
274
+ }
275
+ },
276
+ name: {
277
+ type: 'void',
278
+ 'x-decorator': 'Table.Column.Decorator',
279
+ 'x-component': 'Table.Column',
280
+ properties: {
281
+ name: {
282
+ type: 'string',
283
+ 'x-component': 'CollectionField',
284
+ 'x-read-pretty': true
285
+ }
286
+ }
287
+ },
288
+ authType: {
289
+ type: 'void',
290
+ 'x-decorator': 'Table.Column.Decorator',
291
+ 'x-component': 'Table.Column',
292
+ properties: {
293
+ authType: {
294
+ type: 'string',
295
+ 'x-component': 'CollectionField',
296
+ 'x-read-pretty': true
297
+ }
298
+ }
299
+ },
300
+ title: {
301
+ type: 'void',
302
+ 'x-decorator': 'Table.Column.Decorator',
303
+ 'x-component': 'Table.Column',
304
+ properties: {
305
+ title: {
306
+ type: 'string',
307
+ 'x-component': 'CollectionField',
308
+ 'x-read-pretty': true
309
+ }
310
+ }
311
+ },
312
+ description: {
313
+ type: 'void',
314
+ 'x-decorator': 'Table.Column.Decorator',
315
+ 'x-component': 'Table.Column',
316
+ properties: {
317
+ description: {
318
+ type: 'boolean',
319
+ 'x-component': 'CollectionField',
320
+ 'x-read-pretty': true
321
+ }
322
+ }
323
+ },
324
+ enabled: {
325
+ type: 'void',
326
+ 'x-decorator': 'Table.Column.Decorator',
327
+ 'x-component': 'Table.Column',
328
+ properties: {
329
+ enabled: {
330
+ type: 'boolean',
331
+ 'x-component': 'CollectionField',
332
+ 'x-read-pretty': true
333
+ }
334
+ }
335
+ },
336
+ actions: {
337
+ type: 'void',
338
+ title: '{{t("Actions")}}',
339
+ 'x-component': 'Table.Column',
340
+ properties: {
341
+ actions: {
342
+ type: 'void',
343
+ 'x-component': 'Space',
344
+ 'x-component-props': {
345
+ split: '|'
346
+ },
347
+ properties: {
348
+ update: {
349
+ type: 'void',
350
+ title: '{{t("Configure")}}',
351
+ 'x-component': 'Action.Link',
352
+ 'x-component-props': {
353
+ type: 'primary'
354
+ },
355
+ properties: {
356
+ drawer: {
357
+ type: 'void',
358
+ 'x-component': 'Action.Drawer',
359
+ 'x-decorator': 'Form',
360
+ 'x-decorator-props': {
361
+ useValues: '{{ cm.useValuesFromRecord }}'
362
+ },
363
+ title: '{{t("Configure")}}',
364
+ properties: {
365
+ name: {
366
+ 'x-component': 'CollectionField',
367
+ 'x-decorator': 'FormItem'
368
+ },
369
+ authType: {
370
+ 'x-component': 'CollectionField',
371
+ 'x-decorator': 'FormItem',
372
+ 'x-component-props': {
373
+ options: '{{ types }}'
374
+ }
375
+ },
376
+ title: {
377
+ 'x-component': 'CollectionField',
378
+ 'x-decorator': 'FormItem'
379
+ },
380
+ description: {
381
+ 'x-component': 'CollectionField',
382
+ 'x-decorator': 'FormItem'
383
+ },
384
+ enabled: {
385
+ 'x-component': 'CollectionField',
386
+ 'x-decorator': 'FormItem'
387
+ },
388
+ options: {
389
+ type: 'object',
390
+ 'x-component': 'Options'
391
+ },
392
+ footer: {
393
+ type: 'void',
394
+ 'x-component': 'Action.Drawer.Footer',
395
+ properties: {
396
+ cancel: {
397
+ title: '{{t("Cancel")}}',
398
+ 'x-component': 'Action',
399
+ 'x-component-props': {
400
+ useAction: '{{ cm.useCancelAction }}'
401
+ }
402
+ },
403
+ submit: {
404
+ title: '{{t("Submit")}}',
405
+ 'x-component': 'Action',
406
+ 'x-component-props': {
407
+ type: 'primary',
408
+ useAction: '{{ cm.useUpdateAction }}'
409
+ }
410
+ }
411
+ }
412
+ }
413
+ }
414
+ }
415
+ }
416
+ },
417
+ delete: {
418
+ type: 'void',
419
+ title: '{{ t("Delete") }}',
420
+ 'x-component': 'Action.Link',
421
+ 'x-component-props': {
422
+ confirm: {
423
+ title: "{{t('Delete record')}}",
424
+ content: "{{t('Are you sure you want to delete it?')}}"
425
+ },
426
+ useAction: '{{cm.useDestroyAction}}'
427
+ },
428
+ 'x-disabled': '{{ useCanNotDelete() }}'
429
+ }
430
+ }
431
+ }
432
+ }
433
+ }
434
+ }
435
+ }
436
+ }
437
+ };
438
+ exports.authenticatorsSchema = authenticatorsSchema;
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { default, AuthModel } from './server';
package/lib/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "AuthModel", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _server.AuthModel;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "default", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _server.default;
16
+ }
17
+ });
18
+ var _server = _interopRequireWildcard(require("./server"));
19
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -0,0 +1,3 @@
1
+ export declare const presetAuthType = "Email/Password";
2
+ export declare const presetAuthenticator = "basic";
3
+ export declare const namespace: any;
package/lib/preset.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.presetAuthenticator = exports.presetAuthType = exports.namespace = void 0;
7
+ const presetAuthType = 'Email/Password';
8
+ exports.presetAuthType = presetAuthType;
9
+ const presetAuthenticator = 'basic';
10
+ exports.presetAuthenticator = presetAuthenticator;
11
+ const namespace = require('../package.json').name;
12
+ exports.namespace = namespace;
@@ -0,0 +1,8 @@
1
+ import { Context, Next } from '@nocobase/actions';
2
+ declare const _default: {
3
+ lostPassword: (ctx: Context, next: Next) => Promise<void>;
4
+ resetPassword: (ctx: Context, next: Next) => Promise<void>;
5
+ getUserByResetToken: (ctx: Context, next: Next) => Promise<void>;
6
+ changePassword: (ctx: Context, next: Next) => Promise<void>;
7
+ };
8
+ export default _default;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
8
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
9
+ var _default = {
10
+ lostPassword: function () {
11
+ var _lostPassword = _asyncToGenerator(function* (ctx, next) {
12
+ ctx.body = yield ctx.auth.lostPassword();
13
+ yield next();
14
+ });
15
+ function lostPassword(_x, _x2) {
16
+ return _lostPassword.apply(this, arguments);
17
+ }
18
+ return lostPassword;
19
+ }(),
20
+ resetPassword: function () {
21
+ var _resetPassword = _asyncToGenerator(function* (ctx, next) {
22
+ ctx.body = yield ctx.auth.resetPassword();
23
+ yield next();
24
+ });
25
+ function resetPassword(_x3, _x4) {
26
+ return _resetPassword.apply(this, arguments);
27
+ }
28
+ return resetPassword;
29
+ }(),
30
+ getUserByResetToken: function () {
31
+ var _getUserByResetToken = _asyncToGenerator(function* (ctx, next) {
32
+ ctx.body = yield ctx.auth.getUserByResetToken();
33
+ yield next();
34
+ });
35
+ function getUserByResetToken(_x5, _x6) {
36
+ return _getUserByResetToken.apply(this, arguments);
37
+ }
38
+ return getUserByResetToken;
39
+ }(),
40
+ changePassword: function () {
41
+ var _changePassword = _asyncToGenerator(function* (ctx, next) {
42
+ ctx.body = yield ctx.auth.changePassword();
43
+ yield next();
44
+ });
45
+ function changePassword(_x7, _x8) {
46
+ return _changePassword.apply(this, arguments);
47
+ }
48
+ return changePassword;
49
+ }()
50
+ };
51
+ exports.default = _default;
@@ -0,0 +1,8 @@
1
+ import { Context, Next } from '@nocobase/actions';
2
+ declare const _default: {
3
+ listTypes: (ctx: Context, next: Next) => Promise<void>;
4
+ publicList: (ctx: Context, next: Next) => Promise<void>;
5
+ destroy: (ctx: Context, next: Next) => Promise<void>;
6
+ update: (ctx: Context, next: Next) => Promise<void>;
7
+ };
8
+ export default _default;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _preset = require("../../preset");
8
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
+ function checkCount(_x, _x2) {
11
+ return _checkCount.apply(this, arguments);
12
+ }
13
+ function _checkCount() {
14
+ _checkCount = _asyncToGenerator(function* (repository, id) {
15
+ // TODO(yangqia): This is a temporary solution, may cause concurrency problem.
16
+ const count = yield repository.count({
17
+ filter: {
18
+ enabled: true,
19
+ id: {
20
+ $ne: id
21
+ }
22
+ }
23
+ });
24
+ if (count <= 0) {
25
+ throw new Error('Please keep and enable at least one authenticator');
26
+ }
27
+ });
28
+ return _checkCount.apply(this, arguments);
29
+ }
30
+ var _default = {
31
+ listTypes: function () {
32
+ var _listTypes = _asyncToGenerator(function* (ctx, next) {
33
+ ctx.body = ctx.app.authManager.listTypes();
34
+ yield next();
35
+ });
36
+ function listTypes(_x3, _x4) {
37
+ return _listTypes.apply(this, arguments);
38
+ }
39
+ return listTypes;
40
+ }(),
41
+ publicList: function () {
42
+ var _publicList = _asyncToGenerator(function* (ctx, next) {
43
+ const repo = ctx.db.getRepository('authenticators');
44
+ const authenticators = yield repo.find({
45
+ fields: ['name', 'authType', 'title', 'options', 'sort'],
46
+ filter: {
47
+ enabled: true
48
+ },
49
+ sort: 'sort'
50
+ });
51
+ ctx.body = authenticators.map(authenticator => {
52
+ var _authenticator$option;
53
+ return {
54
+ name: authenticator.name,
55
+ authType: authenticator.authType,
56
+ title: authenticator.title,
57
+ options: ((_authenticator$option = authenticator.options) === null || _authenticator$option === void 0 ? void 0 : _authenticator$option.public) || {}
58
+ };
59
+ });
60
+ yield next();
61
+ });
62
+ function publicList(_x5, _x6) {
63
+ return _publicList.apply(this, arguments);
64
+ }
65
+ return publicList;
66
+ }(),
67
+ destroy: function () {
68
+ var _destroy = _asyncToGenerator(function* (ctx, next) {
69
+ const repository = ctx.db.getRepository('authenticators');
70
+ const _ctx$action$params = ctx.action.params,
71
+ filterByTk = _ctx$action$params.filterByTk,
72
+ filter = _ctx$action$params.filter;
73
+ try {
74
+ yield checkCount(repository, filterByTk);
75
+ } catch (err) {
76
+ ctx.throw(400, ctx.t(err.message, {
77
+ ns: _preset.namespace
78
+ }));
79
+ }
80
+ const instance = yield repository.destroy({
81
+ filter,
82
+ filterByTk,
83
+ context: ctx
84
+ });
85
+ ctx.body = instance;
86
+ yield next();
87
+ });
88
+ function destroy(_x7, _x8) {
89
+ return _destroy.apply(this, arguments);
90
+ }
91
+ return destroy;
92
+ }(),
93
+ update: function () {
94
+ var _update = _asyncToGenerator(function* (ctx, next) {
95
+ const repository = ctx.db.getRepository('authenticators');
96
+ const _ctx$action$params2 = ctx.action.params,
97
+ forceUpdate = _ctx$action$params2.forceUpdate,
98
+ filterByTk = _ctx$action$params2.filterByTk,
99
+ values = _ctx$action$params2.values,
100
+ whitelist = _ctx$action$params2.whitelist,
101
+ blacklist = _ctx$action$params2.blacklist,
102
+ filter = _ctx$action$params2.filter,
103
+ updateAssociationValues = _ctx$action$params2.updateAssociationValues;
104
+ if (!values.enabled) {
105
+ try {
106
+ yield checkCount(repository, values.id);
107
+ } catch (err) {
108
+ ctx.throw(400, ctx.t(err.message, {
109
+ ns: _preset.namespace
110
+ }));
111
+ }
112
+ }
113
+ ctx.body = yield repository.update({
114
+ filterByTk,
115
+ values,
116
+ whitelist,
117
+ blacklist,
118
+ filter,
119
+ updateAssociationValues,
120
+ context: ctx,
121
+ forceUpdate
122
+ });
123
+ yield next();
124
+ });
125
+ function update(_x9, _x10) {
126
+ return _update.apply(this, arguments);
127
+ }
128
+ return update;
129
+ }()
130
+ };
131
+ exports.default = _default;
@@ -0,0 +1,10 @@
1
+ import { AuthConfig, BaseAuth } from '@nocobase/auth';
2
+ export declare class BasicAuth extends BaseAuth {
3
+ constructor(config: AuthConfig);
4
+ validate(): Promise<any>;
5
+ signUp(): Promise<any>;
6
+ lostPassword(): Promise<any>;
7
+ resetPassword(): Promise<any>;
8
+ getUserByResetToken(): Promise<any>;
9
+ changePassword(): Promise<any>;
10
+ }