@nocobase/plugin-auth 0.12.0-alpha.5 → 0.13.0-alpha.10

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.
@@ -1,729 +1,12 @@
1
- (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@nocobase/client"), require("react"), require("antd"), require("@formily/shared"), require("react-i18next"), require("@ant-design/icons"), require("@formily/react")) : typeof define === "function" && define.amd ? define(["exports", "@nocobase/client", "react", "antd", "@formily/shared", "react-i18next", "@ant-design/icons", "@formily/react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@nocobase/plugin-auth"] = {}, global["@nocobase/client"], global.react, global.antd, global["@formily/shared"], global["react-i18next"], global["@ant-design/icons"], global["@formily/react"]));
3
- })(this, function(exports2, client, require$$0, antd, shared, reactI18next, icons, react) {
4
- "use strict";
5
- var jsxRuntime = { exports: {} };
6
- var reactJsxRuntime_production_min = {};
7
- /**
8
- * @license React
9
- * react-jsx-runtime.production.min.js
10
- *
11
- * Copyright (c) Facebook, Inc. and its affiliates.
12
- *
13
- * This source code is licensed under the MIT license found in the
14
- * LICENSE file in the root directory of this source tree.
15
- */
16
- var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
17
- function q(c, a, g) {
18
- var b, d = {}, e = null, h = null;
19
- void 0 !== g && (e = "" + g);
20
- void 0 !== a.key && (e = "" + a.key);
21
- void 0 !== a.ref && (h = a.ref);
22
- for (b in a)
23
- m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
24
- if (c && c.defaultProps)
25
- for (b in a = c.defaultProps, a)
26
- void 0 === d[b] && (d[b] = a[b]);
27
- return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
28
- }
29
- reactJsxRuntime_production_min.Fragment = l;
30
- reactJsxRuntime_production_min.jsx = q;
31
- reactJsxRuntime_production_min.jsxs = q;
32
- {
33
- jsxRuntime.exports = reactJsxRuntime_production_min;
34
- }
35
- var jsxRuntimeExports = jsxRuntime.exports;
36
- const AuthTypeContext = require$$0.createContext({ type: "" });
37
- const AuthTypesContext = require$$0.createContext({ types: [] });
38
- const useAuthTypes = () => {
39
- const { types } = require$$0.useContext(AuthTypesContext);
40
- return types;
41
- };
42
- const collection = {
43
- name: "authenticators",
44
- sortable: true,
45
- fields: [
46
- {
47
- name: "id",
48
- type: "string",
49
- interface: "id"
50
- },
51
- {
52
- interface: "input",
53
- type: "string",
54
- name: "name",
55
- uiSchema: {
56
- type: "string",
57
- title: '{{t("Name")}}',
58
- "x-component": "Input",
59
- required: true
1
+ (function(o,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("antd"),require("react"),require("@formily/shared"),require("react-i18next"),require("@ant-design/icons"),require("@formily/react")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","antd","react","@formily/shared","react-i18next","@ant-design/icons","@formily/react"],e):(o=typeof globalThis!="undefined"?globalThis:o||self,e(o["@nocobase/plugin-auth"]={},o["@nocobase/client"],o.jsxRuntime,o.antd,o.react,o["@formily/shared"],o["react-i18next"],o["@ant-design/icons"],o["@formily/react"]))})(this,function(o,e,t,l,p,A,y,d,a){"use strict";var G=Object.defineProperty,H=Object.defineProperties;var J=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var P=(o,e,t)=>e in o?G(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,C=(o,e)=>{for(var t in e||(e={}))Q.call(e,t)&&P(o,t,e[t]);if(F)for(var t of F(e))W.call(e,t)&&P(o,t,e[t]);return o},g=(o,e)=>H(o,J(e));var b=(o,e,t)=>new Promise((l,p)=>{var A=a=>{try{d(t.next(a))}catch(x){p(x)}},y=a=>{try{d(t.throw(a))}catch(x){p(x)}},d=a=>a.done?l(a.value):Promise.resolve(a.value).then(A,y);d((t=t.apply(o,e)).next())});const x=p.createContext({type:""}),S=p.createContext({types:[]}),I=()=>{const{types:n}=p.useContext(S);return n},w={name:"authenticators",sortable:!0,fields:[{name:"id",type:"string",interface:"id"},{interface:"input",type:"string",name:"name",uiSchema:{type:"string",title:'{{t("Auth UID")}}',"x-component":"Input","x-validator":n=>/^[a-zA-Z0-9_-]+$/.test(n)?"":e.i18n.t("a-z, A-Z, 0-9, _, -"),required:!0}},{interface:"input",type:"string",name:"authType",uiSchema:{type:"string",title:'{{t("Auth Type")}}',"x-component":"Select",dataSource:"{{ types }}",required:!0}},{interface:"input",type:"string",name:"title",uiSchema:{type:"string",title:'{{t("Title")}}',"x-component":"Input"}},{interface:"textarea",type:"string",name:"description",uiSchema:{type:"string",title:'{{t("Description")}}',"x-component":"Input"}},{type:"boolean",name:"enabled",uiSchema:{type:"boolean",title:'{{t("Enabled")}}',"x-component":"Checkbox"}}]},D={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(n){const r=e.useActionContext(),{type:i}=p.useContext(x);return e.useRequest(()=>Promise.resolve({data:{name:`s_${A.uid()}`,authType:i}}),g(C({},n),{refreshDeps:[r.visible]}))}},title:'{{t("Add new")}}',properties:{name:{"x-component":"CollectionField","x-decorator":"FormItem"},authType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},title:{"x-component":"CollectionField","x-decorator":"FormItem"},description:{"x-component":"CollectionField","x-decorator":"FormItem"},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useCreateAction }}"}}}}}}}},k={type:"void",name:"authenticators","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:w,resourceName:"authenticators",dragSort:!0,request:{resource:"authenticators",action:"list",params:{pageSize:50,sort:"sort",appends:[]}}},"x-component":"CollectionProvider","x-component-props":{collection:w},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{delete:{type:"void",title:'{{t("Delete")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useBulkDestroyAction }}",confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"}}},create:{type:"void",title:'{{t("Add new")}}',"x-component":"AddNew","x-component-props":{type:"primary"}}}},table:{type:"void","x-uid":"input","x-component":"Table.Void","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"},useDataSource:"{{ cm.useDataSourceFromRAC }}",useAction(){const n=e.useAPIClient(),{t:r}=y.useTranslation();return{move(c,s){return b(this,null,function*(){yield n.resource("authenticators").move({sourceId:c.id,targetId:s.id}),l.message.success(r("Saved successfully"),.2)})}}}},properties:{id:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{id:{type:"number","x-component":"CollectionField","x-read-pretty":!0}}},name:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{name:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},authType:{title:'{{t("Auth Type")}}',type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{authType:{type:"string","x-component":"Select","x-read-pretty":!0,enum:"{{ types }}"}}},title:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{title:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},description:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{description:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},enabled:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{enabled:{type:"boolean","x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"Table.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{update:{type:"void",title:'{{t("Configure")}}',"x-component":"Action.Link","x-component-props":{type:"primary"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:"{{ cm.useValuesFromRecord }}"},title:'{{t("Configure")}}',properties:{name:{"x-component":"CollectionField","x-decorator":"FormItem"},authType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},title:{"x-component":"CollectionField","x-decorator":"FormItem"},description:{"x-component":"CollectionField","x-decorator":"FormItem"},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ cm.useUpdateAction }}"}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:"{{t('Delete record')}}",content:"{{t('Are you sure you want to delete it?')}}"},useAction:"{{cm.useDestroyAction}}"},"x-disabled":"{{ useCanNotDelete() }}"}}}}}}}}},q=n=>{const r=e.useRecord(),i=e.useRequest(()=>Promise.resolve({data:C({},r.options)}),g(C({},n),{manual:!0})),{run:c}=i,s=e.useActionContext();return p.useEffect(()=>{s.visible&&c()},[s.visible,c]),i},$=a.observer(()=>{const n=a.useForm(),r=e.useRecord();return e.useOptionsComponent(n.values.authType||r.authType)}),j="auth";function h(){return y.useTranslation(j)}const O=()=>{const{setVisible:n}=e.useActionContext();return{run(){return b(this,null,function*(){n(!1)})}}},V=()=>{const{t:n}=y.useTranslation(),[r,i]=p.useState(!1),[c,s]=p.useState(""),m=I(),v=m.map(u=>g(C({},u),{onClick:()=>{i(!0),s(u.value)}}));return t.jsx(e.ActionContextProvider,{value:{visible:r,setVisible:i},children:t.jsxs(x.Provider,{value:{type:c},children:[t.jsx(l.Dropdown,{menu:{items:v},children:t.jsxs(l.Button,{icon:t.jsx(d.PlusOutlined,{}),type:"primary",children:[n("Add new")," ",t.jsx(d.DownOutlined,{})]})}),t.jsx(e.SchemaComponent,{scope:{useCloseAction:O,types:m,setType:s},schema:D})]})})},B=()=>(e.useAsyncData(),!1),E=()=>{const{t:n}=h(),[r,i]=p.useState([]),c=e.useAPIClient();return e.useRequest(()=>c.resource("authenticators").listTypes().then(s=>{var v;return(((v=s==null?void 0:s.data)==null?void 0:v.data)||[]).map(u=>({key:u.name,label:n(u.title||u.name),value:u.name}))}),{onSuccess:s=>{i(s)}}),t.jsx(l.Card,{bordered:!1,children:t.jsx(S.Provider,{value:{types:r},children:t.jsx(e.SchemaComponent,{schema:k,components:{AddNew:V,Options:$},scope:{types:r,useValuesFromOptions:q,useCanNotDelete:B,t:n}})})})},L={type:"object",name:"passwordForm","x-component":"FormV2",properties:{account:{type:"string","x-component":"Input","x-validator":`{{(value) => {
2
+ if (!value) {
3
+ return t("Please enter your username or email");
60
4
  }
61
- },
62
- {
63
- interface: "input",
64
- type: "string",
65
- name: "authType",
66
- uiSchema: {
67
- type: "string",
68
- title: '{{t("Auth Type", {ns: "auth"})}}',
69
- "x-component": "Select",
70
- required: true
71
- }
72
- },
73
- {
74
- interface: "input",
75
- type: "string",
76
- name: "title",
77
- uiSchema: {
78
- type: "string",
79
- title: '{{t("Title")}}',
80
- "x-component": "Input"
81
- }
82
- },
83
- {
84
- interface: "textarea",
85
- type: "string",
86
- name: "description",
87
- uiSchema: {
88
- type: "string",
89
- title: '{{t("Description")}}',
90
- "x-component": "Input"
91
- }
92
- },
93
- {
94
- type: "boolean",
95
- name: "enabled",
96
- uiSchema: {
97
- type: "boolean",
98
- title: '{{t("Enabled")}}',
99
- "x-component": "Checkbox"
100
- }
101
- }
102
- ]
103
- };
104
- const createFormSchema = {
105
- type: "object",
106
- properties: {
107
- drawer: {
108
- type: "void",
109
- "x-component": "Action.Drawer",
110
- "x-decorator": "Form",
111
- "x-decorator-props": {
112
- useValues(options) {
113
- const ctx = client.useActionContext();
114
- const { type: authType } = require$$0.useContext(AuthTypeContext);
115
- return client.useRequest(
116
- () => Promise.resolve({
117
- data: {
118
- name: `s_${shared.uid()}`,
119
- authType
120
- }
121
- }),
122
- { ...options, refreshDeps: [ctx.visible] }
123
- );
5
+ if (value.includes('@')) {
6
+ if (!/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/.test(value)) {
7
+ return t("Please enter a valid email");
124
8
  }
125
- },
126
- title: '{{t("Add new")}}',
127
- properties: {
128
- name: {
129
- "x-component": "CollectionField",
130
- "x-decorator": "FormItem"
131
- },
132
- authType: {
133
- "x-component": "CollectionField",
134
- "x-decorator": "FormItem",
135
- "x-component-props": {
136
- options: "{{ types }}"
137
- }
138
- },
139
- title: {
140
- "x-component": "CollectionField",
141
- "x-decorator": "FormItem"
142
- },
143
- description: {
144
- "x-component": "CollectionField",
145
- "x-decorator": "FormItem"
146
- },
147
- enabled: {
148
- "x-component": "CollectionField",
149
- "x-decorator": "FormItem"
150
- },
151
- options: {
152
- type: "object",
153
- "x-component": "Options"
154
- },
155
- footer: {
156
- type: "void",
157
- "x-component": "Action.Drawer.Footer",
158
- properties: {
159
- cancel: {
160
- title: '{{t("Cancel")}}',
161
- "x-component": "Action",
162
- "x-component-props": {
163
- useAction: "{{ cm.useCancelAction }}"
164
- }
165
- },
166
- submit: {
167
- title: '{{t("Submit")}}',
168
- "x-component": "Action",
169
- "x-component-props": {
170
- type: "primary",
171
- useAction: "{{ cm.useCreateAction }}"
172
- }
173
- }
174
- }
175
- }
176
- }
177
- }
178
- }
179
- };
180
- const authenticatorsSchema = {
181
- type: "void",
182
- name: "authenticators",
183
- "x-decorator": "ResourceActionProvider",
184
- "x-decorator-props": {
185
- collection,
186
- resourceName: "authenticators",
187
- dragSort: true,
188
- request: {
189
- resource: "authenticators",
190
- action: "list",
191
- params: {
192
- pageSize: 50,
193
- sort: "sort",
194
- appends: []
195
- }
196
- }
197
- },
198
- "x-component": "CollectionProvider",
199
- "x-component-props": {
200
- collection
201
- },
202
- properties: {
203
- actions: {
204
- type: "void",
205
- "x-component": "ActionBar",
206
- "x-component-props": {
207
- style: {
208
- marginBottom: 16
209
- }
210
- },
211
- properties: {
212
- delete: {
213
- type: "void",
214
- title: '{{t("Delete")}}',
215
- "x-component": "Action",
216
- "x-component-props": {
217
- useAction: "{{ cm.useBulkDestroyAction }}",
218
- confirm: {
219
- title: "{{t('Delete')}}",
220
- content: "{{t('Are you sure you want to delete it?')}}"
221
- }
222
- }
223
- },
224
- create: {
225
- type: "void",
226
- title: '{{t("Add new")}}',
227
- "x-component": "AddNew",
228
- "x-component-props": {
229
- type: "primary"
230
- }
231
- }
232
- }
233
- },
234
- table: {
235
- type: "void",
236
- "x-uid": "input",
237
- "x-component": "Table.Void",
238
- "x-component-props": {
239
- rowKey: "id",
240
- rowSelection: {
241
- type: "checkbox"
242
- },
243
- useDataSource: "{{ cm.useDataSourceFromRAC }}",
244
- useAction() {
245
- const api = client.useAPIClient();
246
- const { t } = reactI18next.useTranslation();
247
- return {
248
- async move(from, to) {
249
- await api.resource("authenticators").move({
250
- sourceId: from.id,
251
- targetId: to.id
252
- });
253
- antd.message.success(t("Saved successfully"), 0.2);
254
- }
255
- };
256
- }
257
- },
258
- properties: {
259
- id: {
260
- type: "void",
261
- "x-decorator": "Table.Column.Decorator",
262
- "x-component": "Table.Column",
263
- properties: {
264
- id: {
265
- type: "number",
266
- "x-component": "CollectionField",
267
- "x-read-pretty": true
268
- }
269
- }
270
- },
271
- name: {
272
- type: "void",
273
- "x-decorator": "Table.Column.Decorator",
274
- "x-component": "Table.Column",
275
- properties: {
276
- name: {
277
- type: "string",
278
- "x-component": "CollectionField",
279
- "x-read-pretty": true
280
- }
281
- }
282
- },
283
- authType: {
284
- type: "void",
285
- "x-decorator": "Table.Column.Decorator",
286
- "x-component": "Table.Column",
287
- properties: {
288
- authType: {
289
- type: "string",
290
- "x-component": "CollectionField",
291
- "x-read-pretty": true
292
- }
293
- }
294
- },
295
- title: {
296
- type: "void",
297
- "x-decorator": "Table.Column.Decorator",
298
- "x-component": "Table.Column",
299
- properties: {
300
- title: {
301
- type: "string",
302
- "x-component": "CollectionField",
303
- "x-read-pretty": true
304
- }
305
- }
306
- },
307
- description: {
308
- type: "void",
309
- "x-decorator": "Table.Column.Decorator",
310
- "x-component": "Table.Column",
311
- properties: {
312
- description: {
313
- type: "boolean",
314
- "x-component": "CollectionField",
315
- "x-read-pretty": true
316
- }
317
- }
318
- },
319
- enabled: {
320
- type: "void",
321
- "x-decorator": "Table.Column.Decorator",
322
- "x-component": "Table.Column",
323
- properties: {
324
- enabled: {
325
- type: "boolean",
326
- "x-component": "CollectionField",
327
- "x-read-pretty": true
328
- }
329
- }
330
- },
331
- actions: {
332
- type: "void",
333
- title: '{{t("Actions")}}',
334
- "x-component": "Table.Column",
335
- properties: {
336
- actions: {
337
- type: "void",
338
- "x-component": "Space",
339
- "x-component-props": {
340
- split: "|"
341
- },
342
- properties: {
343
- update: {
344
- type: "void",
345
- title: '{{t("Configure")}}',
346
- "x-component": "Action.Link",
347
- "x-component-props": {
348
- type: "primary"
349
- },
350
- properties: {
351
- drawer: {
352
- type: "void",
353
- "x-component": "Action.Drawer",
354
- "x-decorator": "Form",
355
- "x-decorator-props": {
356
- useValues: "{{ cm.useValuesFromRecord }}"
357
- },
358
- title: '{{t("Configure")}}',
359
- properties: {
360
- name: {
361
- "x-component": "CollectionField",
362
- "x-decorator": "FormItem"
363
- },
364
- authType: {
365
- "x-component": "CollectionField",
366
- "x-decorator": "FormItem",
367
- "x-component-props": {
368
- options: "{{ types }}"
369
- }
370
- },
371
- title: {
372
- "x-component": "CollectionField",
373
- "x-decorator": "FormItem"
374
- },
375
- description: {
376
- "x-component": "CollectionField",
377
- "x-decorator": "FormItem"
378
- },
379
- enabled: {
380
- "x-component": "CollectionField",
381
- "x-decorator": "FormItem"
382
- },
383
- options: {
384
- type: "object",
385
- "x-component": "Options"
386
- },
387
- footer: {
388
- type: "void",
389
- "x-component": "Action.Drawer.Footer",
390
- properties: {
391
- cancel: {
392
- title: '{{t("Cancel")}}',
393
- "x-component": "Action",
394
- "x-component-props": {
395
- useAction: "{{ cm.useCancelAction }}"
396
- }
397
- },
398
- submit: {
399
- title: '{{t("Submit")}}',
400
- "x-component": "Action",
401
- "x-component-props": {
402
- type: "primary",
403
- useAction: "{{ cm.useUpdateAction }}"
404
- }
405
- }
406
- }
407
- }
408
- }
409
- }
410
- }
411
- },
412
- delete: {
413
- type: "void",
414
- title: '{{ t("Delete") }}',
415
- "x-component": "Action.Link",
416
- "x-component-props": {
417
- confirm: {
418
- title: "{{t('Delete record')}}",
419
- content: "{{t('Are you sure you want to delete it?')}}"
420
- },
421
- useAction: "{{cm.useDestroyAction}}"
422
- },
423
- "x-disabled": "{{ useCanNotDelete() }}"
424
- }
425
- }
426
- }
427
- }
428
- }
429
- }
430
- }
431
- }
432
- };
433
- const useValuesFromOptions = (options) => {
434
- const record = client.useRecord();
435
- const result = client.useRequest(
436
- () => Promise.resolve({
437
- data: {
438
- ...record.options
9
+ } else {
10
+ return /^[^@.<>"'/]{2,16}$/.test(value) || t("Please enter a valid username");
439
11
  }
440
- }),
441
- {
442
- ...options,
443
- manual: true
444
- }
445
- );
446
- const { run } = result;
447
- const ctx = client.useActionContext();
448
- require$$0.useEffect(() => {
449
- if (ctx.visible) {
450
- run();
451
- }
452
- }, [ctx.visible, run]);
453
- return result;
454
- };
455
- const Options$1 = react.observer(() => {
456
- const form = react.useForm();
457
- const record = client.useRecord();
458
- const component = client.useOptionsComponent(form.values.authType || record.authType);
459
- return component;
460
- });
461
- const useCloseAction = () => {
462
- const { setVisible } = client.useActionContext();
463
- return {
464
- async run() {
465
- setVisible(false);
466
- }
467
- };
468
- };
469
- const AddNew = () => {
470
- const { t } = reactI18next.useTranslation();
471
- const [visible, setVisible] = require$$0.useState(false);
472
- const [type, setType] = require$$0.useState("");
473
- const types = useAuthTypes();
474
- const items = types.map((item) => ({
475
- ...item,
476
- onClick: () => {
477
- setVisible(true);
478
- setType(item.value);
479
- }
480
- }));
481
- return /* @__PURE__ */ jsxRuntimeExports.jsx(client.ActionContextProvider, { value: { visible, setVisible }, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(AuthTypeContext.Provider, { value: { type }, children: [
482
- /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Dropdown, { menu: { items }, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(antd.Button, { icon: /* @__PURE__ */ jsxRuntimeExports.jsx(icons.PlusOutlined, {}), type: "primary", children: [
483
- t("Add new"),
484
- " ",
485
- /* @__PURE__ */ jsxRuntimeExports.jsx(icons.DownOutlined, {})
486
- ] }) }),
487
- /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaComponent, { scope: { useCloseAction, types, setType }, schema: createFormSchema })
488
- ] }) });
489
- };
490
- const useCanNotDelete = () => {
491
- client.useAsyncData();
492
- return false;
493
- };
494
- const Authenticator = () => {
495
- const [types, setTypes] = require$$0.useState([]);
496
- const api = client.useAPIClient();
497
- client.useRequest(
498
- () => api.resource("authenticators").listTypes().then((res) => {
499
- var _a;
500
- const types2 = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.data) || [];
501
- return types2.map((type) => ({
502
- key: type,
503
- label: type,
504
- value: type
505
- }));
506
- }),
507
- {
508
- onSuccess: (types2) => {
509
- setTypes(types2);
510
- }
511
- }
512
- );
513
- return /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Card, { bordered: false, children: /* @__PURE__ */ jsxRuntimeExports.jsx(AuthTypesContext.Provider, { value: { types }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
514
- client.SchemaComponent,
515
- {
516
- schema: authenticatorsSchema,
517
- components: { AddNew, Options: Options$1 },
518
- scope: { types, useValuesFromOptions, useCanNotDelete }
519
- }
520
- ) }) });
521
- };
522
- const passwordForm = {
523
- type: "object",
524
- name: "passwordForm",
525
- "x-component": "FormV2",
526
- properties: {
527
- email: {
528
- type: "string",
529
- required: true,
530
- "x-component": "Input",
531
- "x-validator": "email",
532
- "x-decorator": "FormItem",
533
- "x-component-props": { placeholder: '{{t("Email")}}', style: {} }
534
- },
535
- password: {
536
- type: "string",
537
- "x-component": "Password",
538
- required: true,
539
- "x-decorator": "FormItem",
540
- "x-component-props": { placeholder: '{{t("Password")}}', style: {} }
541
- },
542
- actions: {
543
- type: "void",
544
- "x-component": "div",
545
- properties: {
546
- submit: {
547
- title: '{{t("Sign in")}}',
548
- type: "void",
549
- "x-component": "Action",
550
- "x-component-props": {
551
- htmlType: "submit",
552
- block: true,
553
- type: "primary",
554
- useAction: `{{ useBasicSignIn }}`,
555
- style: { width: "100%" }
556
- }
557
- }
558
- }
559
- },
560
- signup: {
561
- type: "void",
562
- "x-component": "Link",
563
- "x-component-props": {
564
- to: "{{ signupLink }}"
565
- },
566
- "x-content": '{{t("Create an account")}}',
567
- "x-visible": "{{ allowSignUp }}"
568
- }
569
- }
570
- };
571
- const SigninPage = (props) => {
572
- const authenticator = props.authenticator;
573
- const { authType, name, options } = authenticator;
574
- const signupPages = require$$0.useContext(client.SignupPageContext);
575
- const allowSignUp = !!signupPages[authType] && (options == null ? void 0 : options.allowSignup);
576
- const signupLink = `/signup?authType=${authType}&name=${name}`;
577
- const useBasicSignIn = () => {
578
- return client.useSignIn(name);
579
- };
580
- return /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaComponent, { schema: passwordForm, scope: { useBasicSignIn, allowSignUp, signupLink } });
581
- };
582
- const presetAuthType = "Email/Password";
583
- const signupPageSchema = {
584
- type: "object",
585
- name: shared.uid(),
586
- "x-component": "FormV2",
587
- properties: {
588
- email: {
589
- type: "string",
590
- required: true,
591
- "x-component": "Input",
592
- "x-validator": "email",
593
- "x-decorator": "FormItem",
594
- "x-component-props": { placeholder: '{{t("Email")}}', style: {} }
595
- },
596
- password: {
597
- type: "string",
598
- required: true,
599
- "x-component": "Password",
600
- "x-decorator": "FormItem",
601
- "x-component-props": { placeholder: '{{t("Password")}}', checkStrength: true, style: {} },
602
- "x-reactions": [
603
- {
604
- dependencies: [".confirm_password"],
605
- fulfill: {
606
- state: {
607
- selfErrors: '{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'
608
- }
609
- }
610
- }
611
- ]
612
- },
613
- confirm_password: {
614
- type: "string",
615
- required: true,
616
- "x-component": "Password",
617
- "x-decorator": "FormItem",
618
- "x-component-props": { placeholder: '{{t("Confirm password")}}', style: {} },
619
- "x-reactions": [
620
- {
621
- dependencies: [".password"],
622
- fulfill: {
623
- state: {
624
- selfErrors: '{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'
625
- }
626
- }
627
- }
628
- ]
629
- },
630
- actions: {
631
- type: "void",
632
- "x-component": "div",
633
- properties: {
634
- submit: {
635
- title: '{{t("Sign up")}}',
636
- type: "void",
637
- "x-component": "Action",
638
- "x-component-props": {
639
- block: true,
640
- type: "primary",
641
- htmlType: "submit",
642
- useAction: "{{ useBasicSignup }}",
643
- style: { width: "100%" }
644
- }
645
- }
646
- }
647
- },
648
- link: {
649
- type: "void",
650
- "x-component": "div",
651
- properties: {
652
- link: {
653
- type: "void",
654
- "x-component": "Link",
655
- "x-component-props": { to: "/signin" },
656
- "x-content": '{{t("Log in with an existing account")}}'
657
- }
658
- }
659
- }
660
- }
661
- };
662
- const SignupPage = (props) => {
663
- const useBasicSignup = () => {
664
- return client.useSignup({ authenticator: props.name });
665
- };
666
- return /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaComponent, { schema: signupPageSchema, scope: { useBasicSignup } });
667
- };
668
- const NAMESPACE = "auth";
669
- function useAuthTranslation() {
670
- return reactI18next.useTranslation(NAMESPACE);
671
- }
672
- const Options = () => {
673
- const { t } = useAuthTranslation();
674
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
675
- client.SchemaComponent,
676
- {
677
- scope: { t },
678
- schema: {
679
- type: "object",
680
- properties: {
681
- public: {
682
- type: "object",
683
- properties: {
684
- allowSignup: {
685
- "x-decorator": "FormItem",
686
- type: "boolean",
687
- title: '{{t("Allow to sign up")}}',
688
- "x-component": "Checkbox",
689
- "x-component-props": {
690
- defaultChecked: true
691
- }
692
- }
693
- }
694
- }
695
- }
696
- }
697
- }
698
- );
699
- };
700
- const AuthProvider = (props) => {
701
- const { t } = useAuthTranslation();
702
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
703
- client.SettingsCenterProvider,
704
- {
705
- settings: {
706
- auth: {
707
- title: t("Authentication"),
708
- icon: "LoginOutlined",
709
- tabs: {
710
- authenticators: {
711
- title: t("Authenticators"),
712
- component: () => /* @__PURE__ */ jsxRuntimeExports.jsx(Authenticator, {})
713
- }
714
- }
715
- }
716
- },
717
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.OptionsComponentProvider, { authType: presetAuthType, component: Options, children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.SigninPageProvider, { authType: presetAuthType, tabTitle: t("Sign in via email"), component: SigninPage, children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.SignupPageProvider, { authType: presetAuthType, component: SignupPage, children: props.children }) }) })
718
- }
719
- );
720
- };
721
- class AuthPlugin extends client.Plugin {
722
- async load() {
723
- this.app.use(AuthProvider);
724
- }
725
- }
726
- exports2.AuthPlugin = AuthPlugin;
727
- exports2.default = AuthPlugin;
728
- Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
729
- });
12
+ }}}`,"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Username/Email")}}',style:{}}},password:{type:"string","x-component":"Password",required:!0,"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Password")}}',style:{}}},actions:{type:"void","x-component":"div",properties:{submit:{title:'{{t("Sign in")}}',type:"void","x-component":"Action","x-component-props":{htmlType:"submit",block:!0,type:"primary",useAction:"{{ useBasicSignIn }}",style:{width:"100%"}}}}},signup:{type:"void","x-component":"Link","x-component-props":{to:"{{ signupLink }}"},"x-content":'{{t("Create an account")}}',"x-visible":"{{ allowSignUp }}"}}},_=n=>{const{t:r}=h(),i=n.authenticator,{authType:c,name:s,options:m}=i,u=!!p.useContext(e.SignupPageContext)[c]&&(m==null?void 0:m.allowSignup),Z=`/signup?authType=${c}&name=${s}`,K=()=>e.useSignIn(s);return t.jsx(e.SchemaComponent,{schema:L,scope:{useBasicSignIn:K,allowSignUp:u,signupLink:Z,t:r}})},f="Email/Password",N={type:"object",name:A.uid(),"x-component":"FormV2",properties:{username:{type:"string",required:!0,"x-component":"Input","x-validator":{username:!0},"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Username")}}',style:{}}},password:{type:"string",required:!0,"x-component":"Password","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Password")}}',checkStrength:!0,style:{}},"x-reactions":[{dependencies:[".confirm_password"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]},confirm_password:{type:"string",required:!0,"x-component":"Password","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Confirm password")}}',style:{}},"x-reactions":[{dependencies:[".password"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]},actions:{type:"void","x-component":"div",properties:{submit:{title:'{{t("Sign up")}}',type:"void","x-component":"Action","x-component-props":{block:!0,type:"primary",htmlType:"submit",useAction:"{{ useBasicSignup }}",style:{width:"100%"}}}}},link:{type:"void","x-component":"div",properties:{link:{type:"void","x-component":"Link","x-component-props":{to:"/signin"},"x-content":'{{t("Log in with an existing account")}}'}}}}},U=n=>{const{t:r}=h(),i=()=>e.useSignup({authenticator:n.name});return t.jsx(e.SchemaComponent,{schema:N,scope:{useBasicSignup:i,t:r}})},z=()=>{const{t:n}=h();return t.jsx(e.SchemaComponent,{scope:{t:n},components:{Alert:l.Alert},schema:{type:"object",properties:{public:{type:"object",properties:{allowSignup:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Allow to sign up")}}',"x-component":"Checkbox","x-component-props":{defaultChecked:!0}}}},notice:{type:"void","x-component":"Alert","x-component-props":{showIcon:!0,message:'{{t("The authentication allows users to sign in via username or email.")}}'}}}}})},M=n=>{const{t:r}=h();return t.jsx(e.SettingsCenterProvider,{settings:{auth:{title:r("Authentication"),icon:"LoginOutlined",tabs:{authenticators:{title:r("Authenticators"),component:()=>t.jsx(E,{})}}}},children:t.jsx(e.OptionsComponentProvider,{authType:f,component:z,children:t.jsx(e.SigninPageProvider,{authType:f,tabTitle:r("Sign in via password"),component:_,children:t.jsx(e.SignupPageProvider,{authType:f,component:U,children:n.children})})})})};class T extends e.Plugin{load(){return b(this,null,function*(){this.app.use(M)})}}o.AuthPlugin=T,o.default=T,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});