@tachybase/module-user 1.3.19 → 1.3.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.js +8 -1
- package/dist/externalVersion.js +8 -8
- package/dist/locale/zh-CN.json +2 -0
- package/dist/server/actions/users.js +10 -0
- package/dist/server/server.js +23 -5
- package/package.json +12 -12
package/dist/client/index.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
(function(r,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@tachybase/client"),require("@tachybase/module-acl/client"),require("react/jsx-runtime"),require("react"),require("@tachybase/schema"),require("antd"),require("react-i18next"),require("@tachybase/utils/client")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/module-acl/client","react/jsx-runtime","react","@tachybase/schema","antd","react-i18next","@tachybase/utils/client"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r["@tachybase/module-user"]={},r["@tachybase/client"],r["@tachybase/module-acl"],r.jsxRuntime,r.react,r["@tachybase/schema"],r.antd,r["react-i18next"],r["@tachybase/utils"]))})(this,function(r,e,a,s,m,x,y,A,C){"use strict";var pe=Object.defineProperty,ce=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var q=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var U=(r,e,a)=>e in r?pe(r,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):r[e]=a,v=(r,e)=>{for(var a in e||(e={}))q.call(e,a)&&U(r,a,e[a]);if(P)for(var a of P(e))D.call(e,a)&&U(r,a,e[a]);return r},g=(r,e)=>ce(r,ie(e));var M=(r,e)=>{var a={};for(var s in r)q.call(r,s)&&e.indexOf(s)<0&&(a[s]=r[s]);if(r!=null&&P)for(var s of P(r))e.indexOf(s)<0&&D.call(r,s)&&(a[s]=r[s]);return a};var b=(r,e,a)=>new Promise((s,m)=>{var x=C=>{try{A(a.next(C))}catch(h){m(h)}},y=C=>{try{A(a.throw(C))}catch(h){m(h)}},A=C=>C.done?s(C.value):Promise.resolve(C.value).then(x,y);A((a=a.apply(r,e)).next())});function h(){return A.useTranslation(["user","core"],{nsMode:"fallback"})}const w={name:"users",fields:[{name:"id",type:"bigInt",autoIncrement:!0,primaryKey:!0,allowNull:!1,uiSchema:{type:"number",title:'{{t("ID")}}',"x-component":"InputNumber","x-read-pretty":!0},interface:"id"},{interface:"input",type:"string",name:"nickname",uiSchema:{type:"string",title:'{{t("Nickname")}}',"x-component":"Input"}},{interface:"input",type:"string",name:"username",unique:!0,uiSchema:{type:"string",title:'{{t("Username")}}',"x-component":"Input","x-validator":{username:!0},required:!0}},{interface:"email",type:"string",name:"email",unique:!0,uiSchema:{type:"string",title:'{{t("Email")}}',"x-component":"Input","x-validator":"email",required:!0}},{interface:"phone",type:"string",name:"phone",unique:!0,uiSchema:{type:"string",title:'{{t("Phone")}}',"x-component":"Input","x-validator":"phone",required:!0}},{interface:"password",type:"password",name:"password",hidden:!0,uiSchema:{type:"string",title:'{{t("Password")}}',"x-component":"Password"}},{interface:"m2m",type:"belongsToMany",name:"roles",target:"roles",foreignKey:"userId",otherKey:"roleName",onDelete:"CASCADE",sourceKey:"id",targetKey:"name",through:"rolesUsers",uiSchema:{type:"array",title:'{{t("Roles")}}',"x-component":"AssociationField","x-component-props":{multiple:!0,fieldNames:{label:"title",value:"name"}}}}]},E={type:"void",properties:{block1:{type:"void","x-decorator":"TableBlockProvider","x-component":"CardItem","x-decorator-props":{collection:w,action:"list",params:{pageSize:50,appends:["roles"]}},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{filter:{type:"void",title:'{{ t("Filter") }}',"x-action":"filter","x-component":"Filter.Action","x-use-component-props":"useFilterActionProps","x-component-props":{icon:"FilterOutlined"},"x-align":"left"},delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action","x-use-component-props":"useBulkDestroyActionProps","x-component-props":{confirm:{title:"{{t('Delete users')}}",content:"{{t('Are you sure you want to delete it?')}}"},icon:"DeleteOutlined"}},create:{type:"void","x-action":"create","x-acl-action":"create",title:"{{t('Add new')}}","x-component":"Action","x-decorator":"ACLActionProvider","x-component-props":{openMode:"drawer",type:"primary",component:"CreateRecordAction",icon:"PlusOutlined"},"x-align":"right","x-acl-action-props":{skipScopeCheck:!0},properties:{drawer:{type:"void",title:'{{ t("Add user") }}',"x-component":"Action.Container","x-component-props":{className:"tb-action-popup"},properties:{body:{type:"void","x-acl-action-props":{skipScopeCheck:!0},"x-acl-action":"users:create","x-decorator":"FormBlockProvider","x-use-decorator-props":"useCreateFormBlockDecoratorProps","x-decorator-props":{dataSource:"main",collection:w},"x-component":"CardItem",properties:{form:{type:"void","x-component":"FormV2","x-use-component-props":"useCreateFormBlockProps",properties:{actionBar:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:24}},properties:{cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{ t("Submit") }}',"x-component":"Action","x-use-component-props":"useCreateActionProps","x-component-props":{type:"primary",htmlType:"submit"},"x-action-settings":{assignedValues:{},triggerWorkflows:[],pageMode:!1}}}},nickname:{"x-component":"CollectionField","x-decorator":"FormItem"},username:{"x-component":"CollectionField","x-decorator":"FormItem"},email:{title:'{{t("Email")}}',"x-component":"Input","x-validator":"email","x-decorator":"FormItem",required:!1},phone:{title:'{{t("Phone")}}',"x-component":"Input","x-validator":"phone","x-decorator":"FormItem","x-component-props":{autocomplete:"off"},required:!1},password:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{autocomplete:"new-password"},required:!0},roles:{"x-component":"CollectionField","x-collection-field":"users.roles","x-decorator":"FormItem"}}}}}}}}}}},table:{type:"array","x-uid":"input","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"}},properties:{column1:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{nickname:{type:"number","x-component":"CollectionField","x-read-pretty":!0}}},column2:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{username:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},column3:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{email:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},column4:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:'{{t("Roles")}}',properties:{roles:{type:"array","x-component":"UserRolesField"}}},column5:{type:"void",title:'{{t("Actions")}}',"x-component":"TableV2.Column",properties:{actions:{type:"void","x-component":"Space",properties:{update:{type:"void",title:'{{t("Edit profile")}}',"x-acl-action-props":{skipScopeCheck:!1},"x-acl-action":"users:update","x-decorator":"FormBlockProvider","x-use-decorator-props":"useEditFormBlockDecoratorProps","x-decorator-props":{action:"get",dataSource:"main",collection:"users"},"x-component":"Action.Link","x-component-props":{type:"primary"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"FormV2","x-use-decorator-props":"useEditFormBlockProps",title:'{{t("Edit profile")}}',properties:{actionBar:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:24}},properties:{cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{ t("Submit") }}',"x-component":"Action","x-use-component-props":"useUpdateActionProps","x-component-props":{type:"primary"}}}},nickname:{"x-component":"CollectionField","x-decorator":"FormItem"},username:{"x-component":"CollectionField","x-decorator":"FormItem"},email:{title:'{{t("Email")}}',"x-component":"Input","x-validator":"email","x-decorator":"FormItem",required:!1},phone:{title:'{{t("Phone")}}',"x-component":"Input","x-validator":"phone","x-decorator":"FormItem",required:!1},roles:{"x-component":"CollectionField","x-decorator":"FormItem","x-collection-field":"users.roles"}}}}},changePassword:{type:"void",title:'{{ t("Change password") }}',"x-action":"update","x-component":"Action.Link","x-component-props":{openMode:"drawer"},"x-decorator":"ACLActionProvider",properties:{drawer:{type:"void",title:'{{ t("Change password") }}',"x-component":"Action.Container","x-component-props":{className:"tb-action-popup"},properties:{card:{type:"void","x-acl-action-props":{skipScopeCheck:!1},"x-acl-action":"users:update","x-decorator":"FormBlockProvider","x-use-decorator-props":"useEditFormBlockDecoratorProps","x-decorator-props":{action:"get",dataSource:"main",collection:w,params:{append:["password"]}},"x-component":"CardItem",properties:{form:{type:"void","x-component":"FormV2","x-use-component-props":"useEditFormBlockProps",properties:{actionBar:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:24}},properties:{cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{ t("Submit") }}',"x-component":"Action","x-use-component-props":"useUpdateActionProps","x-component-props":{type:"primary"}}}},password:{"x-component":"CollectionField","x-component-props":{component:"PasswordField"},"x-decorator":"FormItem",required:!0}}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-acl-action":"users:destroy","x-action":"destroy","x-decorator":"ACLActionProvider","x-component":"Action.Link","x-use-component-props":"useDestroyActionProps","x-component-props":{confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"}}}}}}}}}}}}},O=()=>({type:"void",properties:{[x.uid()]:{type:"void","x-decorator":"RoleUsersTableBlockProvider","x-component":"CardItem","x-use-decorator-props":"useRoleUsersServiceProps",properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{[x.uid()]:{type:"void",title:'{{ t("Filter") }}',"x-action":"filter","x-component":"Filter.Action","x-use-component-props":"useFilterActionProps","x-component-props":{icon:"FilterOutlined"},"x-align":"left"},actions:{type:"void","x-component":"Space",properties:{remove:{type:"void",title:'{{t("Remove")}}',"x-component":"Action","x-use-component-props":"useBulkRemoveUsers","x-component-props":{icon:"MinusOutlined",confirm:{title:"{{t('Remove')}}",content:"{{t('Are you sure you want to remove these users?')}}"},style:{marginRight:8}}},create:{type:"void",title:'{{t("Add users")}}',"x-component":"Action","x-component-props":{type:"primary",icon:"PlusOutlined"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"FormV2",title:'{{t("Add users")}}',properties:{resource:{type:"void","x-decorator":"TableBlockProvider","x-component":"CardItem","x-use-decorator-props":"useRoleUsersProps",properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{filter:{type:"void",title:'{{ t("Filter") }}',default:{$and:[{username:{$includes:""}},{nickname:{$includes:""}}]},"x-action":"filter","x-component":"Filter.Action","x-use-component-props":"useFilterActionProps","x-component-props":{icon:"FilterOutlined"},"x-align":"left"},cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{ t("Submit") }}',"x-component":"Action","x-use-component-props":"useAddRoleUsers","x-component-props":{type:"primary",htmlType:"submit"}}}},table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"}},properties:{username:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{username:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},nickname:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{nickname:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},phone:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{phone:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},email:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{email:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}}}}}}}}}}}}}},table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"}},properties:{username:{type:"void",title:'{{t("Username")}}',"x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{username:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},nickname:{type:"void",title:'{{t("Nickname")}}',"x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{nickname:{type:"string","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:{remove:{type:"void",title:'{{ t("Remove") }}',"x-component":"Action.Link","x-use-component-props":"useRemoveUser","x-component-props":{confirm:{title:"{{t('Remove user')}}",content:"{{t('Are you sure you want to remove it?')}}"}}}}}}}}}}}}}),R=()=>{var p,c;const t=m.useContext(e.CollectionContext),o=e.useFilterFieldOptions(t.fields),{service:n}=e.useTableBlockContext();return e.useFilterFieldProps({options:o,params:((c=(p=n.state)==null?void 0:p.params)==null?void 0:c[0])||n.params,service:n})},K=()=>{const t=e.useAPIClient(),{role:o}=m.useContext(a.RolesManagerContext),n=e.useCollectionRecordData(),{service:p}=e.useTableBlockContext();return{onClick(){return b(this,null,function*(){yield t.resource("roles.users",o==null?void 0:o.name).remove({values:[n.id]}),p==null||p.refresh()})}}},N=()=>{const{t}=h(),{message:o}=y.App.useApp(),n=e.useAPIClient(),{service:p,field:c}=e.useTableBlockContext(),{role:i}=m.useContext(a.RolesManagerContext);return{onClick(){return b(this,null,function*(){var d;const l=(d=c==null?void 0:c.data)==null?void 0:d.selectedRowKeys;if(!(l!=null&&l.length)){o.warning(t("Please select users"));return}yield n.resource("roles.users",i==null?void 0:i.name).remove({values:l}),c.data.selectedRowKeys=[],p==null||p.refresh()})}}},j=()=>{const{t}=h(),{role:o}=m.useContext(a.RolesManagerContext),{message:n}=y.App.useApp(),p=e.useAPIClient(),{setVisible:c}=e.useActionContext(),{field:i}=e.useTableBlockContext(),{__parent:u}=e.useBlockRequestContext();return{onClick(){return b(this,null,function*(){var f,F;const d=(f=i==null?void 0:i.data)==null?void 0:f.selectedRowKeys;if(!(d!=null&&d.length)){n.warning(t("Please select users"));return}yield p.resource("roles.users",o==null?void 0:o.name).add({values:d}),i.data.selectedRowKeys=[],c(!1),(F=u==null?void 0:u.props)==null||F.service.refresh()})}}},W=t=>{const{role:o}=m.useContext(a.RolesManagerContext);return g(v({},t),{collection:w,action:"listExcludeRole",params:{roleName:o==null?void 0:o.name}})},L=t=>{const{role:o}=m.useContext(a.RolesManagerContext),n=e.useRequest({resource:"roles.users",resourceOf:o==null?void 0:o.name,action:"list"},{ready:!!o});return g(v({},t),{service:n,collection:w,params:{pageSize:50}})},z=e.withDynamicSchemaProps(t=>{const B=t,{showIndex:o,dragSort:n,rowKey:p,fieldNames:c,collection:i,service:u}=B,l=M(B,["showIndex","dragSort","rowKey","fieldNames","collection","service"]),d=x.useField(),{role:f}=m.useContext(a.RolesManagerContext),F=e.useTableBlockParams(t);m.useEffect(()=>{u.run()},[f]);const k=x.useFieldSchema(),{treeTable:S}=(k==null?void 0:k["x-decorator-props"])||{},[T,ne]=m.useState(!!c);let I="children";if(i!=null&&i.tree&&S!==!1){const V=i.fields.find(ae=>ae.treeChildren);V&&(I=V.name),F.tree=!0}const se=m.useMemo(()=>x.createForm(),[S]);return s.jsx(e.SchemaComponentOptions,{scope:{treeTable:S},children:s.jsx(x.FormContext.Provider,{value:se,children:s.jsx(e.BlockProvider,g(v({name:t.name||"table"},t),{params:F,runWhenParamsChanged:!0,children:s.jsx(e.FixedBlockWrapper,{children:s.jsx(e.TableBlockContext.Provider,{value:g(v({},l),{field:d,service:u,params:F,showIndex:o,dragSort:n,rowKey:p,expandFlag:T,childrenColumnName:I,setExpandFlag:()=>ne(!T)}),children:s.jsx(e.RenderChildrenWithAssociationFilter,v({},t))})})}))})})}),$=()=>{const{t}=h(),{role:o}=m.useContext(a.RolesManagerContext),n=m.useMemo(()=>O(),[o]);return s.jsx(e.ExtendCollectionsProvider,{collections:[w],children:s.jsx(e.SchemaComponent,{schema:n,components:{RoleUsersTableBlockProvider:z},scope:{useBulkRemoveUsers:N,useRemoveUser:K,useAddRoleUsers:j,useRoleUsersProps:W,useFilterActionProps:R,useRoleUsersServiceProps:L,t}})})},G=()=>{var n,p;const t=e.useCurrentUserContext(),o=((p=(n=t==null?void 0:t.data)==null?void 0:n.data)==null?void 0:p.password)===null;return s.jsx(e.SchemaComponent,{schema:J,scope:{useSaveCurrentUserValues:H,hideOldPassword:o}})},H=()=>{var u,l;const t=x.useForm(),o=e.useAPIClient(),{message:n}=y.App.useApp(),{t:p}=e.useTranslation(),c=e.useCurrentUserContext(),i=((l=(u=c==null?void 0:c.data)==null?void 0:u.data)==null?void 0:l.password)===null;return{run(){return b(this,null,function*(){yield t.submit(),(yield o.resource("auth").changePassword({values:t.values})).status===200&&(n.success(p("Edited successfully")),i&&c.mutate({data:g(v({},c.data.data),{password:""})})),yield t.reset()})}}},J={type:"object",properties:{[C.uid()]:{type:"void","x-component":"CardItem","x-decorator":"Form",title:'{{t("Change password")}}',properties:{action:{type:"void",properties:{submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",style:{left:"96%"},useAction:"{{ useSaveCurrentUserValues }}"}}}},oldPassword:{type:"string",title:'{{t("Old password")}}',required:!0,"x-component":"Password","x-decorator":"FormItem","x-hidden":"{{ hideOldPassword }}"},newPassword:{type:"string",title:'{{t("New password")}}',required:!0,"x-component":"Password","x-decorator":"FormItem","x-component-props":{checkStrength:!0,style:{}},"x-reactions":[{dependencies:[".confirmPassword"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]},confirmPassword:{type:"string",required:!0,title:'{{t("Confirm password")}}',"x-component":"Password","x-decorator":"FormItem","x-component-props":{checkStrength:!0,style:{}},"x-reactions":[{dependencies:[".newPassword"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]}}}}},Q=()=>s.jsx(e.SchemaComponent,{schema:Z,scope:{useCurrentUserValues:X,useSaveCurrentUserValues:Y}}),X=t=>{const o=e.useCurrentUserContext();return e.useRequest(()=>Promise.resolve(o.data),t)},Y=()=>{const t=e.useCurrentUserContext(),o=x.useForm(),n=e.useAPIClient(),{message:p}=y.App.useApp(),{t:c}=e.useTranslation();return{run(){return b(this,null,function*(){var d;const u=yield o.submit();(yield n.resource("users").updateProfile({values:u})).status===200&&p.success(c("Edited successfully")),t.mutate({data:v(v({},(d=t==null?void 0:t.data)==null?void 0:d.data),u)})})}}},Z={type:"object",properties:{[C.uid()]:{type:"void","x-component":"CardItem","x-decorator":"Form","x-decorator-props":{useValues:"{{useCurrentUserValues}}"},title:'{{t("Edit profile")}}',properties:{action:{type:"void",properties:{submit:{title:"Submit","x-component":"Action","x-component-props":{type:"primary",style:{left:"96%"},useAction:"{{ useSaveCurrentUserValues }}"}}}},nickname:{type:"string",title:"{{t('Nickname')}}","x-decorator":"FormItem","x-component":"Input"},username:{type:"string",title:'{{t("Username")}}',"x-decorator":"FormItem","x-component":"Input","x-validator":{username:!0},required:!0},email:{type:"string",title:'{{t("Email")}}',"x-decorator":"FormItem","x-component":"Input","x-validator":"email"},phone:{type:"string",title:'{{t("Phone")}}',"x-decorator":"FormItem","x-component":"Input","x-validator":"phone"}}}}},_=(t=10)=>{const o="ABCDEFGHIJKLMNOPQRSTUVWXYZ",n="abcdefghijklmnopqrstuvwxyz",p="0123456789",c="!#$%^&*-_+=",i=o+n+p+c,u=new Uint32Array(t);crypto.getRandomValues(u);let l="";l+=o.charAt(u[0]%o.length),l+=n.charAt(u[1]%n.length),l+=p.charAt(u[2]%p.length),l+=c.charAt(u[3]%c.length);for(let d=4;d<t;d++){const f=u[d]%i.length;l+=i.charAt(f)}return l=l[0]+l.slice(1).split("").sort(()=>Math.random()-.5).join(""),l},ee=()=>{const{t}=h(),o=x.useField(),[n,p]=m.useState(!1),c=e.useActionContext();return m.useEffect(()=>{c.visible||o.reset()},[o,c.visible]),s.jsxs(y.Row,{gutter:10,children:[s.jsx(y.Col,{span:18,children:s.jsx(e.Password,{checkStrength:!0,visibilityToggle:{visible:n,onVisibleChange:p},value:o.value,onChange:i=>o.setValue(i.target.value),autoComplete:"off"})}),s.jsx(y.Col,{span:4,children:s.jsx(y.Button,{onClick:()=>{o.setValue(_()),p(!0)},children:t("Random password")})})]})},oe=()=>{const{t}=h();return(x.useField().value||[]).map(n=>s.jsx(y.Tag,{children:x.Schema.compile(n.title,{t})},n.name))},te=()=>{const{t}=h(),o=e.useSchemaComponentContext();return s.jsx(e.SchemaComponentContext.Provider,{value:g(v({},o),{designable:!1}),children:s.jsx(e.SchemaComponent,{schema:E,scope:{t},components:{UserRolesField:oe,PasswordField:ee}})})};class re extends e.Plugin{load(){return b(this,null,function*(){this.app.systemSettingsManager.add("id-auth.users",{title:e.tval("Users"),icon:"UserOutlined",Component:te,aclSnippet:"pm.users"}),this.userSettingsManager.add("user-change-password",{icon:"LockOutlined",title:e.tval("Change password"),Component:G}),this.userSettingsManager.add("user-profile",{icon:"UserOutlined",title:e.tval("Edit profile"),Component:Q}),this.app.pm.get(a).rolesManager.add("users",{title:e.tval("Users"),Component:$})})}}r.default=re,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(r,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@tachybase/client"),require("@tachybase/module-acl/client"),require("react/jsx-runtime"),require("react"),require("@tachybase/schema"),require("antd"),require("react-i18next"),require("@tachybase/utils/client")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/module-acl/client","react/jsx-runtime","react","@tachybase/schema","antd","react-i18next","@tachybase/utils/client"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r["@tachybase/module-user"]={},r["@tachybase/client"],r["@tachybase/module-acl"],r.jsxRuntime,r.react,r["@tachybase/schema"],r.antd,r["react-i18next"],r["@tachybase/utils"]))})(this,function(r,e,p,s,m,x,y,k,h){"use strict";var pe=Object.defineProperty,ie=Object.defineProperties;var ce=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var E=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var U=(r,e,p)=>e in r?pe(r,e,{enumerable:!0,configurable:!0,writable:!0,value:p}):r[e]=p,v=(r,e)=>{for(var p in e||(e={}))E.call(e,p)&&U(r,p,e[p]);if(S)for(var p of S(e))q.call(e,p)&&U(r,p,e[p]);return r},b=(r,e)=>ie(r,ce(e));var M=(r,e)=>{var p={};for(var s in r)E.call(r,s)&&e.indexOf(s)<0&&(p[s]=r[s]);if(r!=null&&S)for(var s of S(r))e.indexOf(s)<0&&q.call(r,s)&&(p[s]=r[s]);return p};var w=(r,e,p)=>new Promise((s,m)=>{var x=h=>{try{k(p.next(h))}catch(C){m(C)}},y=h=>{try{k(p.throw(h))}catch(C){m(C)}},k=h=>h.done?s(h.value):Promise.resolve(h.value).then(x,y);k((p=p.apply(r,e)).next())});function C(){return k.useTranslation(["user","core"],{nsMode:"fallback"})}const F={name:"users",fields:[{name:"id",type:"bigInt",autoIncrement:!0,primaryKey:!0,allowNull:!1,uiSchema:{type:"number",title:'{{t("ID")}}',"x-component":"InputNumber","x-read-pretty":!0},interface:"id"},{interface:"input",type:"string",name:"nickname",uiSchema:{type:"string",title:'{{t("Nickname")}}',"x-component":"Input"}},{interface:"input",type:"string",name:"username",unique:!0,uiSchema:{type:"string",title:'{{t("Username")}}',"x-component":"Input","x-validator":{username:!0},required:!0}},{interface:"email",type:"string",name:"email",unique:!0,uiSchema:{type:"string",title:'{{t("Email")}}',"x-component":"Input","x-validator":"email",required:!0}},{interface:"phone",type:"string",name:"phone",unique:!0,uiSchema:{type:"string",title:'{{t("Phone")}}',"x-component":"Input","x-validator":"phone",required:!0}},{interface:"password",type:"password",name:"password",hidden:!0,uiSchema:{type:"string",title:'{{t("Password")}}',"x-component":"Password"}},{interface:"m2m",type:"belongsToMany",name:"roles",target:"roles",foreignKey:"userId",otherKey:"roleName",onDelete:"CASCADE",sourceKey:"id",targetKey:"name",through:"rolesUsers",uiSchema:{type:"array",title:'{{t("Roles")}}',"x-component":"AssociationField","x-component-props":{multiple:!0,fieldNames:{label:"title",value:"name"}}}}]},D={type:"void",properties:{block1:{type:"void","x-decorator":"TableBlockProvider","x-component":"CardItem","x-decorator-props":{collection:F,action:"list",params:{pageSize:50,appends:["roles"]}},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{filter:{type:"void",title:'{{ t("Filter") }}',"x-action":"filter","x-component":"Filter.Action","x-use-component-props":"useFilterActionProps","x-component-props":{icon:"FilterOutlined"},"x-align":"left"},delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action","x-use-component-props":"useBulkDestroyActionProps","x-component-props":{confirm:{title:"{{t('Delete users')}}",content:"{{t('Are you sure you want to delete it?')}}"},icon:"DeleteOutlined"}},create:{type:"void","x-action":"create","x-acl-action":"create",title:"{{t('Add new')}}","x-component":"Action","x-decorator":"ACLActionProvider","x-component-props":{openMode:"drawer",type:"primary",component:"CreateRecordAction",icon:"PlusOutlined"},"x-align":"right","x-acl-action-props":{skipScopeCheck:!0},properties:{drawer:{type:"void",title:'{{ t("Add user") }}',"x-component":"Action.Container","x-component-props":{className:"tb-action-popup"},properties:{body:{type:"void","x-acl-action-props":{skipScopeCheck:!0},"x-acl-action":"users:create","x-decorator":"FormBlockProvider","x-use-decorator-props":"useCreateFormBlockDecoratorProps","x-decorator-props":{dataSource:"main",collection:F},"x-component":"CardItem",properties:{form:{type:"void","x-component":"FormV2","x-use-component-props":"useCreateFormBlockProps",properties:{actionBar:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:24}},properties:{cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{ t("Submit") }}',"x-component":"Action","x-use-component-props":"useCreateActionProps","x-component-props":{type:"primary",htmlType:"submit"},"x-action-settings":{assignedValues:{},triggerWorkflows:[],pageMode:!1}}}},nickname:{"x-component":"CollectionField","x-decorator":"FormItem"},username:{"x-component":"CollectionField","x-decorator":"FormItem"},email:{title:'{{t("Email")}}',"x-component":"Input","x-validator":"email","x-decorator":"FormItem",required:!1},phone:{title:'{{t("Phone")}}',"x-component":"Input","x-validator":"phone","x-decorator":"FormItem","x-component-props":{autocomplete:"off"},required:!1},password:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{autocomplete:"new-password"},required:!0},roles:{"x-component":"CollectionField","x-collection-field":"users.roles","x-decorator":"FormItem"}}}}}}}}}}},table:{type:"array","x-uid":"input","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"}},properties:{column1:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{nickname:{type:"number","x-component":"CollectionField","x-read-pretty":!0}}},column2:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{username:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},column3:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{email:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},column4:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:'{{t("Roles")}}',properties:{roles:{type:"array","x-component":"UserRolesField"}}},column5:{type:"void",title:'{{t("Actions")}}',"x-component":"TableV2.Column",properties:{actions:{type:"void","x-component":"Space",properties:{update:{type:"void",title:'{{t("Edit profile")}}',"x-acl-action-props":{skipScopeCheck:!1},"x-acl-action":"users:update","x-decorator":"FormBlockProvider","x-use-decorator-props":"useEditFormBlockDecoratorProps","x-decorator-props":{action:"get",dataSource:"main",collection:"users"},"x-component":"Action.Link","x-component-props":{type:"primary"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"FormV2","x-use-decorator-props":"useEditFormBlockProps",title:'{{t("Edit profile")}}',properties:{actionBar:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:24}},properties:{cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{ t("Submit") }}',"x-component":"Action","x-use-component-props":"useUpdateActionProps","x-component-props":{type:"primary"}}}},nickname:{"x-component":"CollectionField","x-decorator":"FormItem"},username:{"x-component":"CollectionField","x-decorator":"FormItem"},email:{title:'{{t("Email")}}',"x-component":"Input","x-validator":"email","x-decorator":"FormItem",required:!1},phone:{title:'{{t("Phone")}}',"x-component":"Input","x-validator":"phone","x-decorator":"FormItem",required:!1},roles:{"x-component":"CollectionField","x-decorator":"FormItem","x-collection-field":"users.roles"}}}}},changePassword:{type:"void",title:'{{ t("Change password") }}',"x-action":"update","x-component":"Action.Link","x-component-props":{openMode:"drawer"},"x-decorator":"ACLActionProvider",properties:{drawer:{type:"void",title:'{{ t("Change password") }}',"x-component":"Action.Container","x-component-props":{className:"tb-action-popup"},properties:{card:{type:"void","x-acl-action-props":{skipScopeCheck:!1},"x-acl-action":"users:update","x-decorator":"FormBlockProvider","x-use-decorator-props":"useEditFormBlockDecoratorProps","x-decorator-props":{action:"get",dataSource:"main",collection:F,params:{append:["password"]}},"x-component":"CardItem",properties:{form:{type:"void","x-component":"FormV2","x-use-component-props":"useEditFormBlockProps",properties:{actionBar:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:24}},properties:{cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{ t("Submit") }}',"x-component":"Action","x-use-component-props":"useUpdateActionProps","x-component-props":{type:"primary"}}}},password:{"x-component":"CollectionField","x-component-props":{component:"PasswordField"},"x-decorator":"FormItem",required:!0}}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-acl-action":"users:destroy","x-action":"destroy","x-decorator":"ACLActionProvider","x-component":"Action.Link","x-use-component-props":"useDestroyActionProps","x-component-props":{confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"}}}}}}}}}}}}},N=()=>({type:"void",properties:{[x.uid()]:{type:"void","x-decorator":"RoleUsersTableBlockProvider","x-component":"CardItem","x-use-decorator-props":"useRoleUsersServiceProps",properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{[x.uid()]:{type:"void",title:'{{ t("Filter") }}',"x-action":"filter","x-component":"Filter.Action","x-use-component-props":"useFilterActionProps","x-component-props":{icon:"FilterOutlined"},"x-align":"left"},actions:{type:"void","x-component":"Space",properties:{remove:{type:"void",title:'{{t("Remove")}}',"x-component":"Action","x-use-component-props":"useBulkRemoveUsers","x-component-props":{icon:"MinusOutlined",confirm:{title:"{{t('Remove')}}",content:"{{t('Are you sure you want to remove these users?')}}"},style:{marginRight:8}}},create:{type:"void",title:'{{t("Add users")}}',"x-component":"Action","x-component-props":{type:"primary",icon:"PlusOutlined"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"FormV2",title:'{{t("Add users")}}',properties:{resource:{type:"void","x-decorator":"TableBlockProvider","x-component":"CardItem","x-use-decorator-props":"useRoleUsersProps",properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{filter:{type:"void",title:'{{ t("Filter") }}',default:{$and:[{username:{$includes:""}},{nickname:{$includes:""}}]},"x-action":"filter","x-component":"Filter.Action","x-use-component-props":"useFilterActionProps","x-component-props":{icon:"FilterOutlined"},"x-align":"left"},cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{ t("Submit") }}',"x-component":"Action","x-use-component-props":"useAddRoleUsers","x-component-props":{type:"primary",htmlType:"submit"}}}},table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"}},properties:{username:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{username:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},nickname:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{nickname:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},phone:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{phone:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},email:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{email:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}}}}}}}}}}}}}},table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"}},properties:{username:{type:"void",title:'{{t("Username")}}',"x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{username:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},nickname:{type:"void",title:'{{t("Nickname")}}',"x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{nickname:{type:"string","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:{remove:{type:"void",title:'{{ t("Remove") }}',"x-component":"Action.Link","x-use-component-props":"useRemoveUser","x-component-props":{confirm:{title:"{{t('Remove user')}}",content:"{{t('Are you sure you want to remove it?')}}"}}}}}}}}}}}}}),O=()=>{var a,i;const o=m.useContext(e.CollectionContext),t=e.useFilterFieldOptions(o.fields),{service:n}=e.useTableBlockContext();return e.useFilterFieldProps({options:t,params:((i=(a=n.state)==null?void 0:a.params)==null?void 0:i[0])||n.params,service:n})},R=()=>{const o=e.useAPIClient(),{role:t}=m.useContext(p.RolesManagerContext),n=e.useCollectionRecordData(),{service:a}=e.useTableBlockContext();return{onClick(){return w(this,null,function*(){yield o.resource("roles.users",t==null?void 0:t.name).remove({values:[n.id]}),a==null||a.refresh()})}}},K=()=>{const{t:o}=C(),{message:t}=y.App.useApp(),n=e.useAPIClient(),{service:a,field:i}=e.useTableBlockContext(),{role:d}=m.useContext(p.RolesManagerContext);return{onClick(){return w(this,null,function*(){var u;const l=(u=i==null?void 0:i.data)==null?void 0:u.selectedRowKeys;if(!(l!=null&&l.length)){t.warning(o("Please select users"));return}yield n.resource("roles.users",d==null?void 0:d.name).remove({values:l}),i.data.selectedRowKeys=[],a==null||a.refresh()})}}},$=()=>{const{t:o}=C(),{role:t}=m.useContext(p.RolesManagerContext),{message:n}=y.App.useApp(),a=e.useAPIClient(),{setVisible:i}=e.useActionContext(),{field:d}=e.useTableBlockContext(),{__parent:c}=e.useBlockRequestContext();return{onClick(){return w(this,null,function*(){var f,g;const u=(f=d==null?void 0:d.data)==null?void 0:f.selectedRowKeys;if(!(u!=null&&u.length)){n.warning(o("Please select users"));return}yield a.resource("roles.users",t==null?void 0:t.name).add({values:u}),d.data.selectedRowKeys=[],i(!1),(g=c==null?void 0:c.props)==null||g.service.refresh()})}}},j=o=>{const{role:t}=m.useContext(p.RolesManagerContext);return b(v({},o),{collection:F,action:"listExcludeRole",params:{roleName:t==null?void 0:t.name}})},W=o=>{const{role:t}=m.useContext(p.RolesManagerContext),n=e.useRequest({resource:"roles.users",resourceOf:t==null?void 0:t.name,action:"list"},{ready:!!t});return b(v({},o),{service:n,collection:F,params:{pageSize:50}})},L=e.withDynamicSchemaProps(o=>{const T=o,{showIndex:t,dragSort:n,rowKey:a,fieldNames:i,collection:d,service:c}=T,l=M(T,["showIndex","dragSort","rowKey","fieldNames","collection","service"]),u=x.useField(),{role:f}=m.useContext(p.RolesManagerContext),g=e.useTableBlockParams(o);m.useEffect(()=>{c.run()},[f]);const P=x.useFieldSchema(),{treeTable:A}=(P==null?void 0:P["x-decorator-props"])||{},[V,ne]=m.useState(!!i);let I="children";if(d!=null&&d.tree&&A!==!1){const B=d.fields.find(ae=>ae.treeChildren);B&&(I=B.name),g.tree=!0}const se=m.useMemo(()=>x.createForm(),[A]);return s.jsx(e.SchemaComponentOptions,{scope:{treeTable:A},children:s.jsx(x.FormContext.Provider,{value:se,children:s.jsx(e.BlockProvider,b(v({name:o.name||"table"},o),{params:g,runWhenParamsChanged:!0,children:s.jsx(e.FixedBlockWrapper,{children:s.jsx(e.TableBlockContext.Provider,{value:b(v({},l),{field:u,service:c,params:g,showIndex:t,dragSort:n,rowKey:a,expandFlag:V,childrenColumnName:I,setExpandFlag:()=>ne(!V)}),children:s.jsx(e.RenderChildrenWithAssociationFilter,v({},o))})})}))})})}),z=()=>{const{t:o}=C(),{role:t}=m.useContext(p.RolesManagerContext),n=m.useMemo(()=>N(),[t]);return s.jsx(e.ExtendCollectionsProvider,{collections:[F],children:s.jsx(e.SchemaComponent,{schema:n,components:{RoleUsersTableBlockProvider:L},scope:{useBulkRemoveUsers:K,useRemoveUser:R,useAddRoleUsers:$,useRoleUsersProps:j,useFilterActionProps:O,useRoleUsersServiceProps:W,t:o}})})},G=()=>{var f,g,P,A;const o=e.useCurrentUserContext(),t=e.useApp().pluginManager,n=t.get("@tachybase/plugin-otp"),a=t.get("@tachybase/plugin-auth-sms"),i=!!n&&!!a,d=((g=(f=o==null?void 0:o.data)==null?void 0:f.data)==null?void 0:g.password)!==null,c=(A=(P=o==null?void 0:o.data)==null?void 0:P.data)==null?void 0:A.phone,{t:l}=e.useTranslation(),u=c?l("Send verification code to phone: {{phoneNumber}}",{phoneNumber:c}):l("Please fill in your mobile phone number in your personal information first");return s.jsx(e.SchemaComponent,{schema:J,scope:{useSaveCurrentUserValues:H,oldPassword:d,codeDescription:u,phoneNumber:c,smsVerifyEnabled:i},components:{VerificationCode:e.VerificationCode}})},H=()=>{var c,l;const o=x.useForm(),t=e.useAPIClient(),{message:n}=y.App.useApp(),{t:a}=e.useTranslation(),i=e.useCurrentUserContext(),d=((l=(c=i==null?void 0:i.data)==null?void 0:c.data)==null?void 0:l.password)===null;return{run(){return w(this,null,function*(){yield o.submit(),(yield t.resource("auth").changePassword({values:o.values})).status===200&&(n.success(a("Edited successfully")),d&&i.mutate({data:b(v({},i.data.data),{password:""})})),yield o.reset()})}}},J={type:"object",properties:{[h.uid()]:{type:"void","x-component":"CardItem","x-decorator":"Form",title:'{{t("Change password")}}',properties:{action:{type:"void",properties:{submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",style:{left:"96%"},useAction:"{{ useSaveCurrentUserValues }}"}}}},verifyMethod:{type:"string",required:!0,title:'{{t("Verify method")}}',enum:[{label:'{{t("Use old password")}}',value:"password"},{label:'{{t("Use verification code")}}',value:"code"}],"x-component":"Radio.Group","x-decorator":"FormItem","x-reactions":[{dependencies:[".phoneExist",".oldPasswordExist"],fulfill:{state:{hidden:"{{ !($deps[0] && $deps[1] && smsVerifyEnabled) }}",value:"{{ undefined }}"}}}]},phoneExist:{type:"boolean",default:"{{ !!phoneNumber }}","x-hidden":!0},phone:{type:"string",title:'{{t("Phone")}}',default:"{{ phoneNumber }}","x-component":"Input","x-validator":"phone","x-decorator":"FormItem","x-hidden":!0},code:{type:"string",title:'{{t("Verification code")}}',description:"{{codeDescription}}","x-component":"VerificationCode","x-component-props":{actionType:"auth:changePassword",targetFieldName:"phone"},required:!0,"x-decorator":"FormItem","x-reactions":[{dependencies:[".verifyMethod",".phoneExist"],fulfill:{state:{hidden:`{{
|
|
2
|
+
!$deps[1] ||
|
|
3
|
+
!smsVerifyEnabled ||
|
|
4
|
+
($deps[0] !== 'code' && $deps[0] !== undefined) // 有 verifyMethod 但未选 code
|
|
5
|
+
}}`}}}]},oldPasswordExist:{type:"boolean",default:"{{ oldPassword }}","x-hidden":!0},oldPassword:{type:"string",title:'{{t("Old password")}}',required:!0,"x-component":"Password","x-decorator":"FormItem","x-reactions":[{dependencies:[".verifyMethod",".oldPasswordExist"],fulfill:{state:{hidden:`{{
|
|
6
|
+
!$deps[1] ||
|
|
7
|
+
(smsVerifyEnabled && $deps[0] !== 'password' && $deps[0] !== undefined)
|
|
8
|
+
}}`}}}]},newPassword:{type:"string",title:'{{t("New password")}}',required:!0,"x-component":"Password","x-decorator":"FormItem","x-component-props":{checkStrength:!0,style:{}},"x-reactions":[{dependencies:[".confirmPassword"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]},confirmPassword:{type:"string",required:!0,title:'{{t("Confirm password")}}',"x-component":"Password","x-decorator":"FormItem","x-component-props":{checkStrength:!0,style:{}},"x-reactions":[{dependencies:[".newPassword"],fulfill:{state:{selfErrors:'{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'}}}]}}}}},Q=()=>{const o=e.useApp().pluginManager,t=o.get("@tachybase/plugin-otp"),n=o.get("@tachybase/plugin-auth-sms"),a=!!t&&!!n;return s.jsx(e.SchemaComponent,{schema:Z,scope:{useCurrentUserValues:X,useSaveCurrentUserValues:Y,smsVerifyEnabled:a},components:{VerificationCode:e.VerificationCode}})},X=o=>{const t=e.useCurrentUserContext();return e.useRequest(()=>Promise.resolve(t.data),o)},Y=()=>{const o=e.useCurrentUserContext(),t=x.useForm(),n=e.useAPIClient(),{message:a}=y.App.useApp(),{t:i}=e.useTranslation();return{run(){return w(this,null,function*(){var u;const c=yield t.submit();(yield n.resource("users").updateProfile({values:c})).status===200&&a.success(i("Edited successfully")),o.mutate({data:v(v({},(u=o==null?void 0:o.data)==null?void 0:u.data),c)})})}}},Z={type:"object",properties:{[h.uid()]:{type:"void","x-component":"CardItem","x-decorator":"Form","x-decorator-props":{useValues:"{{useCurrentUserValues}}"},title:'{{t("Edit profile")}}',properties:{action:{type:"void",properties:{submit:{title:"Submit","x-component":"Action","x-component-props":{type:"primary",style:{left:"96%"},useAction:"{{ useSaveCurrentUserValues }}"}}}},nickname:{type:"string",title:"{{t('Nickname')}}","x-decorator":"FormItem","x-component":"Input"},username:{type:"string",title:'{{t("Username")}}',"x-decorator":"FormItem","x-component":"Input","x-validator":{username:!0},required:!0},email:{type:"string",title:'{{t("Email")}}',"x-decorator":"FormItem","x-component":"Input","x-validator":"email"},phone:{type:"string",title:'{{t("Phone")}}',"x-decorator":"FormItem","x-component":"Input","x-validator":"phone"},code:{type:"string",title:'{{t("Verification code")}}',"x-component":"VerificationCode","x-component-props":{actionType:"users:updateProfile",targetFieldName:"phone"},required:!0,"x-decorator":"FormItem","x-reactions":[{dependencies:[".phone"],fulfill:{state:{hidden:"{{ $deps[0] === $form.initialValues?.phone || !smsVerifyEnabled}}"}}}]}}}}},_=(o=10)=>{const t="ABCDEFGHIJKLMNOPQRSTUVWXYZ",n="abcdefghijklmnopqrstuvwxyz",a="0123456789",i="!#$%^&*-_+=",d=t+n+a+i,c=new Uint32Array(o);crypto.getRandomValues(c);let l="";l+=t.charAt(c[0]%t.length),l+=n.charAt(c[1]%n.length),l+=a.charAt(c[2]%a.length),l+=i.charAt(c[3]%i.length);for(let u=4;u<o;u++){const f=c[u]%d.length;l+=d.charAt(f)}return l=l[0]+l.slice(1).split("").sort(()=>Math.random()-.5).join(""),l},ee=()=>{const{t:o}=C(),t=x.useField(),[n,a]=m.useState(!1),i=e.useActionContext();return m.useEffect(()=>{i.visible||t.reset()},[t,i.visible]),s.jsxs(y.Row,{gutter:10,children:[s.jsx(y.Col,{span:18,children:s.jsx(e.Password,{checkStrength:!0,visibilityToggle:{visible:n,onVisibleChange:a},value:t.value,onChange:d=>t.setValue(d.target.value),autoComplete:"off"})}),s.jsx(y.Col,{span:4,children:s.jsx(y.Button,{onClick:()=>{t.setValue(_()),a(!0)},children:o("Random password")})})]})},oe=()=>{const{t:o}=C();return(x.useField().value||[]).map(n=>s.jsx(y.Tag,{children:x.Schema.compile(n.title,{t:o})},n.name))},te=()=>{const{t:o}=C(),t=e.useSchemaComponentContext();return s.jsx(e.SchemaComponentContext.Provider,{value:b(v({},t),{designable:!1}),children:s.jsx(e.SchemaComponent,{schema:D,scope:{t:o},components:{UserRolesField:oe,PasswordField:ee}})})};class re extends e.Plugin{load(){return w(this,null,function*(){this.app.systemSettingsManager.add("id-auth.users",{title:e.tval("Users"),icon:"UserOutlined",Component:te,aclSnippet:"pm.users"}),this.userSettingsManager.add("user-change-password",{icon:"LockOutlined",title:e.tval("Change password"),Component:G}),this.userSettingsManager.add("user-profile",{icon:"UserOutlined",title:e.tval("Edit profile"),Component:Q}),this.app.pm.get(p).rolesManager.add("users",{title:e.tval("Users"),Component:z})})}}r.default=re,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/externalVersion.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
"react": "18.3.1",
|
|
3
|
-
"@tachybase/client": "1.3.
|
|
4
|
-
"@tachybase/schema": "1.3.
|
|
3
|
+
"@tachybase/client": "1.3.20",
|
|
4
|
+
"@tachybase/schema": "1.3.20",
|
|
5
5
|
"antd": "5.22.5",
|
|
6
|
-
"@tachybase/module-acl": "1.3.
|
|
7
|
-
"@tachybase/utils": "1.3.
|
|
6
|
+
"@tachybase/module-acl": "1.3.20",
|
|
7
|
+
"@tachybase/utils": "1.3.20",
|
|
8
8
|
"react-i18next": "15.2.0",
|
|
9
|
-
"@tachybase/cache": "1.3.
|
|
10
|
-
"@tachybase/database": "1.3.
|
|
11
|
-
"@tachybase/server": "1.3.
|
|
12
|
-
"@tachybase/actions": "1.3.
|
|
9
|
+
"@tachybase/cache": "1.3.20",
|
|
10
|
+
"@tachybase/database": "1.3.20",
|
|
11
|
+
"@tachybase/server": "1.3.20",
|
|
12
|
+
"@tachybase/actions": "1.3.20"
|
|
13
13
|
};
|
package/dist/locale/zh-CN.json
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
"Add users": "添加用户",
|
|
3
3
|
"Are you sure you want to remove it?": "你确定要移除吗?",
|
|
4
4
|
"Edited successfully": "编辑成功",
|
|
5
|
+
"Please fill in your mobile phone number in your personal information first": "请先在个人资料填写手机号",
|
|
5
6
|
"Random password": "随机密码",
|
|
6
7
|
"Remove user": "移除用户",
|
|
8
|
+
"Send verification code to phone: {{phoneNumber}}": "将发送验证码给手机:{{phoneNumber}}",
|
|
7
9
|
"Users & Permissions": "用户和权限",
|
|
8
10
|
"Users Settings": "用户设置"
|
|
9
11
|
}
|
|
@@ -22,6 +22,7 @@ __export(users_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(users_exports);
|
|
24
24
|
var import_actions = require("@tachybase/actions");
|
|
25
|
+
var import__ = require("..");
|
|
25
26
|
async function updateProfile(ctx, next) {
|
|
26
27
|
const { values } = ctx.action.params;
|
|
27
28
|
const { currentUser } = ctx.state;
|
|
@@ -29,6 +30,15 @@ async function updateProfile(ctx, next) {
|
|
|
29
30
|
ctx.throw(401);
|
|
30
31
|
}
|
|
31
32
|
const UserRepo = ctx.db.getRepository("users");
|
|
33
|
+
if (values == null ? void 0 : values.code) {
|
|
34
|
+
const verificationPlugin = ctx.app.getPlugin("otp");
|
|
35
|
+
try {
|
|
36
|
+
await verificationPlugin.intercept(ctx, async () => {
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
ctx.throw(401, ctx.t("The verification code is incorrect or expired", { ns: import__.namespace }));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
32
42
|
const result = await UserRepo.update({
|
|
33
43
|
filterByTk: currentUser.id,
|
|
34
44
|
values
|
package/dist/server/server.js
CHANGED
|
@@ -30,8 +30,8 @@ __export(server_exports, {
|
|
|
30
30
|
default: () => PluginUsersServer
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(server_exports);
|
|
33
|
-
var
|
|
34
|
-
var
|
|
33
|
+
var import_node_path = require("node:path");
|
|
34
|
+
var import_node_worker_threads = require("node:worker_threads");
|
|
35
35
|
var import_database = require("@tachybase/database");
|
|
36
36
|
var import_server = require("@tachybase/server");
|
|
37
37
|
var import_utils = require("@tachybase/utils");
|
|
@@ -143,15 +143,15 @@ class PluginUsersServer extends import_server.Plugin {
|
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
async load() {
|
|
146
|
-
await this.importCollections((0,
|
|
146
|
+
await this.importCollections((0, import_node_path.resolve)(__dirname, "collections"));
|
|
147
147
|
this.db.addMigrations({
|
|
148
148
|
namespace: "users",
|
|
149
|
-
directory: (0,
|
|
149
|
+
directory: (0, import_node_path.resolve)(__dirname, "migrations"),
|
|
150
150
|
context: {
|
|
151
151
|
plugin: this
|
|
152
152
|
}
|
|
153
153
|
});
|
|
154
|
-
if (!
|
|
154
|
+
if (!import_node_worker_threads.isMainThread) {
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
157
|
this.app.resourcer.use(
|
|
@@ -167,6 +167,24 @@ class PluginUsersServer extends import_server.Plugin {
|
|
|
167
167
|
},
|
|
168
168
|
{ tag: "roleCacheInvalidation" }
|
|
169
169
|
);
|
|
170
|
+
const verificationPlugin = this.app.getPlugin("otp");
|
|
171
|
+
if (!verificationPlugin) {
|
|
172
|
+
this.app.logger.warn("sms-auth: @tachybase/plugin-otp is required");
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
verificationPlugin.interceptors.register("users:updateProfile", {
|
|
176
|
+
manual: true,
|
|
177
|
+
getReceiver: (ctx) => {
|
|
178
|
+
return ctx.action.params.values.phone;
|
|
179
|
+
},
|
|
180
|
+
expiresIn: 120,
|
|
181
|
+
validate: async (ctx, phone) => {
|
|
182
|
+
if (!phone) {
|
|
183
|
+
throw new Error(ctx.t("Not a valid cellphone number, please re-enter"));
|
|
184
|
+
}
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
170
188
|
}
|
|
171
189
|
getInstallingData(options = {}) {
|
|
172
190
|
var _a;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tachybase/module-user",
|
|
3
3
|
"displayName": "Users",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.20",
|
|
5
5
|
"description": "Provides basic user model, as well as created by and updated by fields.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"Users & permissions"
|
|
@@ -14,19 +14,19 @@
|
|
|
14
14
|
"antd": "5.22.5",
|
|
15
15
|
"jsonwebtoken": "^8.5.1",
|
|
16
16
|
"react-i18next": "^15.2.0",
|
|
17
|
-
"@tachybase/schema": "1.3.
|
|
17
|
+
"@tachybase/schema": "1.3.20"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@tachybase/cache": "1.3.
|
|
21
|
-
"@tachybase/
|
|
22
|
-
"@tachybase/database": "1.3.
|
|
23
|
-
"@tachybase/
|
|
24
|
-
"@tachybase/
|
|
25
|
-
"@tachybase/
|
|
26
|
-
"@tachybase/
|
|
27
|
-
"@tachybase/
|
|
28
|
-
"@tachybase/test": "1.3.
|
|
29
|
-
"@tachybase/utils": "1.3.
|
|
20
|
+
"@tachybase/cache": "1.3.20",
|
|
21
|
+
"@tachybase/actions": "1.3.20",
|
|
22
|
+
"@tachybase/database": "1.3.20",
|
|
23
|
+
"@tachybase/client": "1.3.20",
|
|
24
|
+
"@tachybase/module-acl": "1.3.20",
|
|
25
|
+
"@tachybase/module-auth": "1.3.20",
|
|
26
|
+
"@tachybase/resourcer": "1.3.20",
|
|
27
|
+
"@tachybase/server": "1.3.20",
|
|
28
|
+
"@tachybase/test": "1.3.20",
|
|
29
|
+
"@tachybase/utils": "1.3.20"
|
|
30
30
|
},
|
|
31
31
|
"description.zh-CN": "提供了基础的用户模型,以及创建人和最后更新人字段。",
|
|
32
32
|
"displayName.zh-CN": "用户",
|