@nocobase/plugin-verification 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.
Files changed (71) hide show
  1. package/client.d.ts +4 -0
  2. package/client.js +30 -0
  3. package/lib/client/ProviderOptions.d.ts +3 -0
  4. package/lib/client/ProviderOptions.js +81 -0
  5. package/lib/client/Shortcut.d.ts +1 -0
  6. package/lib/client/Shortcut.js +78 -0
  7. package/lib/client/VerificationProviders.d.ts +2 -0
  8. package/lib/client/VerificationProviders.js +55 -0
  9. package/lib/client/index.d.ts +3 -0
  10. package/lib/client/index.js +74 -0
  11. package/lib/client/locale/index.d.ts +3 -0
  12. package/lib/client/locale/index.js +47 -0
  13. package/lib/client/locale/zh-CN.d.ts +12 -0
  14. package/lib/client/locale/zh-CN.js +19 -0
  15. package/lib/client/providerTypes/index.d.ts +4 -0
  16. package/lib/client/providerTypes/index.js +25 -0
  17. package/lib/client/providerTypes/sms-aliyun.d.ts +57 -0
  18. package/lib/client/providerTypes/sms-aliyun.js +45 -0
  19. package/lib/client/schemas/providers.d.ts +355 -0
  20. package/lib/client/schemas/providers.js +356 -0
  21. package/lib/index.d.ts +1 -4
  22. package/lib/index.js +3 -34
  23. package/lib/{Plugin.d.ts → server/Plugin.d.ts} +1 -1
  24. package/lib/{Plugin.js → server/Plugin.js} +22 -4
  25. package/lib/{actions → server/actions}/index.d.ts +0 -0
  26. package/lib/{actions → server/actions}/index.js +0 -0
  27. package/lib/{actions → server/actions}/verifications.d.ts +0 -0
  28. package/lib/{actions → server/actions}/verifications.js +12 -5
  29. package/lib/{collections → server/collections}/verifications.d.ts +0 -0
  30. package/lib/{collections → server/collections}/verifications.js +0 -0
  31. package/lib/{collections → server/collections}/verifications_providers.d.ts +0 -0
  32. package/lib/{collections → server/collections}/verifications_providers.js +3 -0
  33. package/lib/{constants.d.ts → server/constants.d.ts} +0 -0
  34. package/lib/{constants.js → server/constants.js} +0 -0
  35. package/lib/server/index.d.ts +4 -0
  36. package/lib/server/index.js +46 -0
  37. package/lib/{locale → server/locale}/index.d.ts +0 -0
  38. package/lib/{locale → server/locale}/index.js +0 -0
  39. package/lib/{locale → server/locale}/zh-CN.d.ts +1 -0
  40. package/lib/{locale → server/locale}/zh-CN.js +2 -1
  41. package/lib/{providers → server/providers}/index.d.ts +0 -0
  42. package/lib/{providers → server/providers}/index.js +0 -0
  43. package/lib/{providers → server/providers}/sms-aliyun.d.ts +0 -0
  44. package/lib/{providers → server/providers}/sms-aliyun.js +1 -0
  45. package/package.json +7 -7
  46. package/server.d.ts +4 -0
  47. package/server.js +30 -0
  48. package/src/client/ProviderOptions.tsx +22 -0
  49. package/src/client/Shortcut.tsx +20 -0
  50. package/src/client/VerificationProviders.tsx +19 -0
  51. package/src/client/index.tsx +41 -0
  52. package/src/client/locale/index.ts +16 -0
  53. package/src/client/locale/zh-CN.ts +13 -0
  54. package/src/client/providerTypes/index.ts +9 -0
  55. package/src/client/providerTypes/sms-aliyun.ts +39 -0
  56. package/src/client/schemas/providers.ts +330 -0
  57. package/src/index.ts +1 -5
  58. package/src/{Plugin.ts → server/Plugin.ts} +13 -2
  59. package/src/{__tests__ → server/__tests__}/Plugin.test.ts +1 -3
  60. package/src/{__tests__ → server/__tests__}/collections/authors.ts +0 -0
  61. package/src/{__tests__ → server/__tests__}/index.ts +0 -0
  62. package/src/{actions → server/actions}/index.ts +0 -0
  63. package/src/{actions → server/actions}/verifications.ts +5 -3
  64. package/src/{collections → server/collections}/verifications.ts +0 -0
  65. package/src/{collections → server/collections}/verifications_providers.ts +4 -0
  66. package/src/{constants.ts → server/constants.ts} +0 -0
  67. package/src/server/index.ts +5 -0
  68. package/src/{locale → server/locale}/index.ts +0 -0
  69. package/src/{locale → server/locale}/zh-CN.ts +2 -1
  70. package/src/{providers → server/providers}/index.ts +0 -0
  71. package/src/{providers → server/providers}/sms-aliyun.ts +1 -0
package/server.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ 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); }
4
+
5
+ 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; }
6
+
7
+ var _index = _interopRequireWildcard(require("./lib/server"));
8
+
9
+ Object.defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+ var _exportNames = {};
13
+ Object.defineProperty(exports, "default", {
14
+ enumerable: true,
15
+ get: function get() {
16
+ return _index.default;
17
+ }
18
+ });
19
+
20
+ Object.keys(_index).forEach(function (key) {
21
+ if (key === "default" || key === "__esModule") return;
22
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
23
+ if (key in exports && exports[key] === _index[key]) return;
24
+ Object.defineProperty(exports, key, {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _index[key];
28
+ }
29
+ });
30
+ });
@@ -0,0 +1,22 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { FormLayout } from '@formily/antd';
3
+ import { Field } from '@formily/core';
4
+ import { observer, RecursionField, Schema, useField, useForm } from '@formily/react';
5
+
6
+ import providerTypes from './providerTypes';
7
+
8
+
9
+ export default observer((props) => {
10
+ const form = useForm();
11
+ const field = useField<Field>();
12
+ const [s, setSchema] = useState(new Schema({}));
13
+ useEffect(() => {
14
+ form.clearFormGraph('options.*');
15
+ setSchema(new Schema(providerTypes.get(form.values.type) || {}));
16
+ }, [form.values.type]);
17
+ return (
18
+ <FormLayout layout={'vertical'}>
19
+ <RecursionField key={form.values.type || 'sms-aliyun'} basePath={field.address} onlyRenderProperties schema={s} />
20
+ </FormLayout>
21
+ );
22
+ });
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { useHistory } from 'react-router-dom';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { CheckCircleOutlined } from '@ant-design/icons';
5
+ import { PluginManager } from '@nocobase/client';
6
+ import { NAMESPACE } from './locale';
7
+
8
+ export const Shortcut = () => {
9
+ const { t } = useTranslation();
10
+ const history = useHistory();
11
+ return (
12
+ <PluginManager.Toolbar.Item
13
+ icon={<CheckCircleOutlined />}
14
+ title={t('Verification', { ns: NAMESPACE })}
15
+ onClick={() => {
16
+ history.push('/admin/settings/verification/providers');
17
+ }}
18
+ />
19
+ );
20
+ };
@@ -0,0 +1,19 @@
1
+ import { SchemaComponent } from "@nocobase/client";
2
+ import React from "react";
3
+ import { Card } from 'antd';
4
+
5
+ import providers from "./schemas/providers";
6
+ import ProviderOptions from "./ProviderOptions";
7
+
8
+ export function VerificationProviders() {
9
+ return (
10
+ <Card bordered={false}>
11
+ <SchemaComponent
12
+ schema={providers}
13
+ components={{
14
+ ProviderOptions
15
+ }}
16
+ />
17
+ </Card>
18
+ );
19
+ };
@@ -0,0 +1,41 @@
1
+ import React, { useContext } from 'react';
2
+
3
+ import { PluginManagerContext, SettingsCenterProvider } from '@nocobase/client';
4
+
5
+ import { NAMESPACE } from './locale';
6
+
7
+ import { VerificationProviders } from './VerificationProviders';
8
+
9
+ export { default as verificationProviderTypes } from './providerTypes';
10
+
11
+ export default function(props) {
12
+ const ctx = useContext(PluginManagerContext);
13
+ return (
14
+ <SettingsCenterProvider
15
+ settings={{
16
+ verification: {
17
+ icon: 'CheckCircleOutlined',
18
+ title: `{{t("Verification", { ns: "${NAMESPACE}" })}}`,
19
+ tabs: {
20
+ providers: {
21
+ title: `{{t("Verification providers", { ns: "${NAMESPACE}" })}}`,
22
+ component: VerificationProviders,
23
+ },
24
+ },
25
+ },
26
+ }}
27
+ >
28
+ <PluginManagerContext.Provider
29
+ value={{
30
+ components: {
31
+ ...ctx?.components,
32
+ },
33
+ }}
34
+ >
35
+ {props.children}
36
+ </PluginManagerContext.Provider>
37
+ </SettingsCenterProvider>
38
+ );
39
+ };
40
+
41
+
@@ -0,0 +1,16 @@
1
+ import { useTranslation } from 'react-i18next';
2
+ import { i18n } from '@nocobase/client';
3
+
4
+ import zhCN from './zh-CN';
5
+
6
+ export const NAMESPACE = 'verification';
7
+
8
+ i18n.addResources('zh-CN', NAMESPACE, zhCN);
9
+
10
+ export function lang(key: string) {
11
+ return i18n.t(key, { ns: NAMESPACE });
12
+ }
13
+
14
+ export function useVerificationTranslation() {
15
+ return useTranslation(NAMESPACE);
16
+ }
@@ -0,0 +1,13 @@
1
+ export default {
2
+ 'Verification': '验证码',
3
+ 'Verification providers': '验证码提供商',
4
+ 'Provider type': '提供商类型',
5
+
6
+ // aliyun sms
7
+ 'Aliyun SMS': '阿里云短信服务',
8
+ 'Access Key ID': 'Access Key ID',
9
+ 'Access Key Secret': 'Access Key Secret',
10
+ 'Endpoint': '接入点',
11
+ 'Sign': '签名',
12
+ 'Template code': '模板代码',
13
+ };
@@ -0,0 +1,9 @@
1
+ import { ISchema } from '@formily/react';
2
+ import { Registry } from "@nocobase/utils/client";
3
+ import SMSAliyun from './sms-aliyun';
4
+
5
+ const providerTypes: Registry<ISchema> = new Registry();
6
+
7
+ providerTypes.register('sms-aliyun', SMSAliyun);
8
+
9
+ export default providerTypes;
@@ -0,0 +1,39 @@
1
+ import { ISchema } from '@formily/react';
2
+
3
+ import { NAMESPACE } from '../locale';
4
+
5
+ export default {
6
+ type: 'object',
7
+ properties: {
8
+ accessKeyId: {
9
+ title: `{{t("Access Key ID", { ns: "${NAMESPACE}" })}}`,
10
+ type: 'string',
11
+ 'x-decorator': 'FormItem',
12
+ 'x-component': 'Input',
13
+ },
14
+ accessKeySecret: {
15
+ title: `{{t("Access Key Secret", { ns: "${NAMESPACE}" })}}`,
16
+ type: 'string',
17
+ 'x-decorator': 'FormItem',
18
+ 'x-component': 'Password',
19
+ },
20
+ endpoint: {
21
+ title: `{{t("Endpoint", { ns: "${NAMESPACE}" })}}`,
22
+ type: 'string',
23
+ 'x-decorator': 'FormItem',
24
+ 'x-component': 'Input',
25
+ },
26
+ sign: {
27
+ title: `{{t("Sign", { ns: "${NAMESPACE}" })}}`,
28
+ type: 'string',
29
+ 'x-decorator': 'FormItem',
30
+ 'x-component': 'Input',
31
+ },
32
+ template: {
33
+ title: `{{t("Template code", { ns: "${NAMESPACE}" })}}`,
34
+ type: 'string',
35
+ 'x-decorator': 'FormItem',
36
+ 'x-component': 'Input',
37
+ }
38
+ }
39
+ } as ISchema;
@@ -0,0 +1,330 @@
1
+ import { uid } from '@formily/shared';
2
+ import { useActionContext, useRequest } from '@nocobase/client';
3
+ import { NAMESPACE } from '../locale';
4
+
5
+ const collection = {
6
+ name: 'verifications_providers',
7
+ fields: [
8
+ {
9
+ type: 'string',
10
+ name: 'id',
11
+ interface: 'input',
12
+ uiSchema: {
13
+ title: '{{t("ID")}}',
14
+ type: 'string',
15
+ 'x-component': 'Input',
16
+ required: true,
17
+ }
18
+ },
19
+ {
20
+ type: 'string',
21
+ name: 'title',
22
+ interface: 'input',
23
+ uiSchema: {
24
+ title: '{{t("Title")}}',
25
+ type: 'string',
26
+ 'x-component': 'Input',
27
+ required: true,
28
+ }
29
+ },
30
+ {
31
+ type: 'string',
32
+ name: 'type',
33
+ interface: 'select',
34
+ uiSchema: {
35
+ title: `{{t("Provider type", { ns: "${NAMESPACE}" })}}`,
36
+ type: 'string',
37
+ 'x-component': 'Select',
38
+ required: true,
39
+ enum: [
40
+ { label: `{{t("Aliyun SMS", { ns: "${NAMESPACE}" })}}`, value: 'sms-aliyun' },
41
+ ],
42
+ },
43
+ },
44
+ {
45
+ type: 'radio',
46
+ name: 'default',
47
+ interface: 'checkbox',
48
+ uiSchema: {
49
+ title: '{{t("Default")}}',
50
+ type: 'boolean',
51
+ 'x-component': 'Checkbox',
52
+ }
53
+ }
54
+ ]
55
+ };
56
+
57
+ export default {
58
+ type: 'void',
59
+ name: 'providers',
60
+ 'x-decorator': 'ResourceActionProvider',
61
+ 'x-decorator-props': {
62
+ collection,
63
+ resourceName: 'verifications_providers',
64
+ request: {
65
+ resource: 'verifications_providers',
66
+ action: 'list',
67
+ params: {
68
+ pageSize: 50,
69
+ sort: ['-default', 'id'],
70
+ appends: [],
71
+ },
72
+ },
73
+ },
74
+ 'x-component': 'CollectionProvider',
75
+ 'x-component-props': {
76
+ collection,
77
+ },
78
+ properties: {
79
+ actions: {
80
+ type: 'void',
81
+ 'x-component': 'ActionBar',
82
+ 'x-component-props': {
83
+ style: {
84
+ marginBottom: 16,
85
+ },
86
+ },
87
+ properties: {
88
+ delete: {
89
+ type: 'void',
90
+ title: '{{t("Delete")}}',
91
+ 'x-component': 'Action',
92
+ 'x-component-props': {
93
+ useAction: '{{ cm.useBulkDestroyAction }}',
94
+ confirm: {
95
+ title: "{{t('Delete')}}",
96
+ content: "{{t('Are you sure you want to delete it?')}}",
97
+ },
98
+ },
99
+ },
100
+ create: {
101
+ type: 'void',
102
+ title: '{{t("Add new")}}',
103
+ 'x-component': 'Action',
104
+ 'x-component-props': {
105
+ type: 'primary',
106
+ },
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 = useActionContext();
115
+ return useRequest(
116
+ () =>
117
+ Promise.resolve({
118
+ data: {
119
+ name: `s_${uid()}`,
120
+ },
121
+ }),
122
+ { ...options, refreshDeps: [ctx.visible] },
123
+ );
124
+ },
125
+ },
126
+ title: '{{t("Add new")}}',
127
+ properties: {
128
+ id: {
129
+ 'x-component': 'CollectionField',
130
+ 'x-decorator': 'FormItem',
131
+ description: '{{t("Identifier for program usage. Support letters, numbers and underscores, must start with an letter.")}}',
132
+ },
133
+ title: {
134
+ 'x-component': 'CollectionField',
135
+ 'x-decorator': 'FormItem',
136
+ },
137
+ type: {
138
+ 'x-component': 'CollectionField',
139
+ 'x-decorator': 'FormItem',
140
+ },
141
+ options: {
142
+ type: 'object',
143
+ 'x-component': 'ProviderOptions',
144
+ },
145
+ default: {
146
+ 'x-component': 'CollectionField',
147
+ 'x-decorator': 'FormItem',
148
+ },
149
+ footer: {
150
+ type: 'void',
151
+ 'x-component': 'Action.Drawer.Footer',
152
+ properties: {
153
+ cancel: {
154
+ title: '{{t("Cancel")}}',
155
+ 'x-component': 'Action',
156
+ 'x-component-props': {
157
+ useAction: '{{ cm.useCancelAction }}',
158
+ },
159
+ },
160
+ submit: {
161
+ title: '{{t("Submit")}}',
162
+ 'x-component': 'Action',
163
+ 'x-component-props': {
164
+ type: 'primary',
165
+ useAction: '{{ cm.useCreateAction }}',
166
+ },
167
+ },
168
+ },
169
+ },
170
+ },
171
+ },
172
+ },
173
+ },
174
+ },
175
+ },
176
+ table: {
177
+ type: 'void',
178
+ 'x-uid': 'input',
179
+ 'x-component': 'Table.Void',
180
+ 'x-component-props': {
181
+ rowKey: 'id',
182
+ rowSelection: {
183
+ type: 'checkbox',
184
+ },
185
+ useDataSource: '{{ cm.useDataSourceFromRAC }}',
186
+ },
187
+ properties: {
188
+ id: {
189
+ type: 'void',
190
+ 'x-decorator': 'Table.Column.Decorator',
191
+ 'x-component': 'Table.Column',
192
+ properties: {
193
+ id: {
194
+ type: 'string',
195
+ 'x-component': 'CollectionField',
196
+ 'x-read-pretty': true,
197
+ },
198
+ },
199
+ },
200
+ title: {
201
+ type: 'void',
202
+ 'x-decorator': 'Table.Column.Decorator',
203
+ 'x-component': 'Table.Column',
204
+ properties: {
205
+ title: {
206
+ type: 'string',
207
+ 'x-component': 'CollectionField',
208
+ 'x-read-pretty': true,
209
+ },
210
+ },
211
+ },
212
+ type: {
213
+ type: 'void',
214
+ 'x-decorator': 'Table.Column.Decorator',
215
+ 'x-component': 'Table.Column',
216
+ properties: {
217
+ type: {
218
+ type: 'string',
219
+ 'x-component': 'CollectionField',
220
+ 'x-read-pretty': true,
221
+ },
222
+ },
223
+ },
224
+ default: {
225
+ type: 'void',
226
+ 'x-decorator': 'Table.Column.Decorator',
227
+ 'x-component': 'Table.Column',
228
+ properties: {
229
+ default: {
230
+ type: 'boolean',
231
+ 'x-component': 'CollectionField',
232
+ 'x-read-pretty': true,
233
+ }
234
+ }
235
+ },
236
+ actions: {
237
+ type: 'void',
238
+ title: '{{t("Actions")}}',
239
+ 'x-component': 'Table.Column',
240
+ properties: {
241
+ actions: {
242
+ type: 'void',
243
+ 'x-component': 'Space',
244
+ 'x-component-props': {
245
+ split: '|',
246
+ },
247
+ properties: {
248
+ update: {
249
+ type: 'void',
250
+ title: '{{t("Edit")}}',
251
+ 'x-component': 'Action.Link',
252
+ 'x-component-props': {
253
+ type: 'primary',
254
+ },
255
+ properties: {
256
+ drawer: {
257
+ type: 'void',
258
+ 'x-component': 'Action.Drawer',
259
+ 'x-decorator': 'Form',
260
+ 'x-decorator-props': {
261
+ useValues: '{{ cm.useValuesFromRecord }}',
262
+ },
263
+ title: '{{t("Edit")}}',
264
+ properties: {
265
+ id: {
266
+ 'x-component': 'CollectionField',
267
+ 'x-decorator': 'FormItem',
268
+ },
269
+ title: {
270
+ 'x-component': 'CollectionField',
271
+ 'x-decorator': 'FormItem',
272
+ },
273
+ type: {
274
+ 'x-component': 'CollectionField',
275
+ 'x-decorator': 'FormItem',
276
+ 'x-disabled': true,
277
+ },
278
+ options: {
279
+ type: 'object',
280
+ 'x-component': 'ProviderOptions',
281
+ },
282
+ default: {
283
+ 'x-component': 'CollectionField',
284
+ 'x-decorator': 'FormItem',
285
+ },
286
+ footer: {
287
+ type: 'void',
288
+ 'x-component': 'Action.Drawer.Footer',
289
+ properties: {
290
+ cancel: {
291
+ title: '{{t("Cancel")}}',
292
+ 'x-component': 'Action',
293
+ 'x-component-props': {
294
+ useAction: '{{ cm.useCancelAction }}',
295
+ },
296
+ },
297
+ submit: {
298
+ title: '{{t("Submit")}}',
299
+ 'x-component': 'Action',
300
+ 'x-component-props': {
301
+ type: 'primary',
302
+ useAction: '{{ cm.useUpdateAction }}',
303
+ },
304
+ },
305
+ },
306
+ },
307
+ },
308
+ },
309
+ },
310
+ },
311
+ delete: {
312
+ type: 'void',
313
+ title: '{{ t("Delete") }}',
314
+ 'x-component': 'Action.Link',
315
+ 'x-component-props': {
316
+ confirm: {
317
+ title: "{{t('Delete record')}}",
318
+ content: "{{t('Are you sure you want to delete it?')}}",
319
+ },
320
+ useAction: '{{cm.useDestroyAction}}',
321
+ },
322
+ },
323
+ },
324
+ },
325
+ },
326
+ },
327
+ },
328
+ },
329
+ },
330
+ };
package/src/index.ts CHANGED
@@ -1,5 +1 @@
1
- export * from './constants';
2
- export { Provider } from './providers';
3
- export { Interceptor, default } from './Plugin';
4
-
5
- export const namespace = require('../package.json').name;
1
+ export { default } from './server';
@@ -14,7 +14,6 @@ import initProviders, { Provider } from './providers';
14
14
 
15
15
  export interface Interceptor {
16
16
  manual?: boolean;
17
- provider: string;
18
17
  expiresIn?: number;
19
18
  getReceiver(ctx): string;
20
19
  getCode?(ctx): string;
@@ -56,7 +55,7 @@ export default class VerificationPlugin extends Plugin {
56
55
  });
57
56
 
58
57
  if (!item) {
59
- return context.throw(400, { code: 'InvalidSMSCode', message: 'verify by sms code failed' });
58
+ return context.throw(400, { code: 'InvalidVerificationCode', message: context.t('Verification code is invalid', { ns: namespace }) });
60
59
  }
61
60
 
62
61
  // TODO: code should be removed if exists in values
@@ -85,6 +84,7 @@ export default class VerificationPlugin extends Plugin {
85
84
  } = process.env;
86
85
 
87
86
  if (
87
+ DEFAULT_SMS_VERIFY_CODE_PROVIDER &&
88
88
  INIT_ALI_SMS_ACCESS_KEY &&
89
89
  INIT_ALI_SMS_ACCESS_KEY_SECRET &&
90
90
  INIT_ALI_SMS_VERIFY_CODE_TEMPLATE &&
@@ -103,6 +103,7 @@ export default class VerificationPlugin extends Plugin {
103
103
  sign: INIT_ALI_SMS_VERIFY_CODE_SIGN,
104
104
  template: INIT_ALI_SMS_VERIFY_CODE_TEMPLATE,
105
105
  },
106
+ default: true
106
107
  },
107
108
  });
108
109
  }
@@ -133,5 +134,15 @@ export default class VerificationPlugin extends Plugin {
133
134
  });
134
135
 
135
136
  app.acl.allow('verifications', 'create');
137
+ app.acl.allow('verifications_providers', '*', 'allowConfigure');
138
+ }
139
+
140
+ async getDefault() {
141
+ const providerRepo = this.db.getRepository('verifications_providers');
142
+ return providerRepo.findOne({
143
+ filter: {
144
+ default: true,
145
+ }
146
+ });
136
147
  }
137
148
  }
@@ -32,6 +32,7 @@ describe('verification > Plugin', () => {
32
32
  provider = await VerificationProviderModel.create({
33
33
  id: 'fake1',
34
34
  type: 'fake',
35
+ default: true
35
36
  });
36
37
  });
37
38
 
@@ -40,7 +41,6 @@ describe('verification > Plugin', () => {
40
41
  describe('auto intercept', () => {
41
42
  beforeEach(async () => {
42
43
  plugin.interceptors.register('authors:create', {
43
- provider: 'fake1',
44
44
  getReceiver(ctx) {
45
45
  return ctx.action.params.values.phone;
46
46
  },
@@ -103,7 +103,6 @@ describe('verification > Plugin', () => {
103
103
  beforeEach(async () => {
104
104
  plugin.interceptors.register('authors:create', {
105
105
  manual: true,
106
- provider: 'fake1',
107
106
  getReceiver(ctx) {
108
107
  return ctx.action.params.values.phone;
109
108
  },
@@ -131,7 +130,6 @@ describe('verification > Plugin', () => {
131
130
  describe('validate', () => {
132
131
  beforeEach(async () => {
133
132
  plugin.interceptors.register('authors:create', {
134
- provider: 'fake1',
135
133
  getReceiver(ctx) {
136
134
  return ctx.action.params.values.phone;
137
135
  },
File without changes
File without changes
@@ -21,7 +21,9 @@ export async function create(context: Context, next: Next) {
21
21
 
22
22
  const ProviderRepo = context.db.getRepository('verifications_providers');
23
23
  const providerItem = await ProviderRepo.findOne({
24
- filterByTk: interceptor.provider
24
+ filter: {
25
+ default: true
26
+ }
25
27
  });
26
28
  if (!providerItem) {
27
29
  console.error(`[verification] no provider for action (${values.type}) provided`);
@@ -30,7 +32,7 @@ export async function create(context: Context, next: Next) {
30
32
 
31
33
  const receiver = interceptor.getReceiver(context);
32
34
  if (!receiver) {
33
- return context.throw(400, { code: 'InvalidReceiver', message: 'Invalid receiver' });
35
+ return context.throw(400, { code: 'InvalidReceiver', message: context.t('Not a valid cellphone number, please re-enter', {ns: namespace }) });
34
36
  }
35
37
  const VerificationModel = context.db.getModel('verifications');
36
38
  const record = await VerificationModel.findOne({
@@ -68,7 +70,7 @@ export async function create(context: Context, next: Next) {
68
70
  switch (error.name) {
69
71
  case 'InvalidReceiver':
70
72
  // TODO: message should consider email and other providers, maybe use "receiver"
71
- return context.throw(400, context.t('Not a valid cellphone number, please re-enter', {ns: namespace }));
73
+ return context.throw(400, { code: 'InvalidReceiver', message: context.t('Not a valid cellphone number, please re-enter', {ns: namespace })});
72
74
  case 'RateLimit':
73
75
  return context.throw(429, context.t('You are trying so frequently, please slow down', { ns: namespace }));
74
76
  default: