@nocobase/plugin-auth
Advanced tools
Comparing version 0.17.0-alpha.7 to 0.18.0-alpha.1
import { Plugin } from '@nocobase/client'; | ||
import { ComponentType } from 'react'; | ||
import { Authenticator as AuthenticatorType } from './authenticator'; | ||
export type AuthOptions = { | ||
components: Partial<{ | ||
SignInForm: ComponentType<{ | ||
authenticator: AuthenticatorType; | ||
}>; | ||
SignInButton: ComponentType<{ | ||
authenticator: AuthenticatorType; | ||
}>; | ||
SignUpForm: ComponentType<{ | ||
authenticatorName: string; | ||
}>; | ||
AdminSettingsForm: ComponentType; | ||
}>; | ||
}; | ||
export declare class AuthPlugin extends Plugin { | ||
authTypes: any; | ||
registerType(authType: string, options: AuthOptions): void; | ||
load(): Promise<void>; | ||
} | ||
export default AuthPlugin; | ||
export { useSignIn } from './basic'; | ||
export { useAuthenticator, AuthenticatorsContext } from './authenticator'; | ||
export type { Authenticator } from './authenticator'; |
@@ -1,2 +0,12 @@ | ||
(function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("react-i18next"),require("antd"),require("react"),require("@formily/shared"),require("react-router-dom"),require("@ant-design/icons"),require("@formily/react")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","react-i18next","antd","react","@formily/shared","react-router-dom","@ant-design/icons","@formily/react"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n["@nocobase/plugin-auth"]={},n["@nocobase/client"],n.jsxRuntime,n["react-i18next"],n.antd,n.react,n["@formily/shared"],n["react-router-dom"],n["@ant-design/icons"],n["@formily/react"]))})(this,function(n,e,t,x,l,c,A,y,a,d){"use strict";var J=Object.defineProperty,Q=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var D=(n,e,t)=>e in n?J(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,g=(n,e)=>{for(var t in e||(e={}))X.call(e,t)&&D(n,t,e[t]);if(I)for(var t of I(e))Y.call(e,t)&&D(n,t,e[t]);return n},C=(n,e)=>Q(n,W(e));var f=(n,e,t)=>new Promise((x,l)=>{var c=a=>{try{y(t.next(a))}catch(d){l(d)}},A=a=>{try{y(t.throw(a))}catch(d){l(d)}},y=a=>a.done?x(a.value):Promise.resolve(a.value).then(c,A);y((t=t.apply(n,e)).next())});const b="Email/Password",S="auth";function h(){return x.useTranslation([S,"client"],{nsMode:"fallback"})}const k=()=>{const{t:o}=h();return t.jsx(e.SchemaComponent,{scope:{t:o},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.")}}'}}}}})},q={type:"object",name:"passwordForm","x-component":"FormV2",properties:{account:{type:"string","x-component":"Input","x-validator":`{{(value) => { | ||
(function(c,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("react"),require("react-router-dom"),require("react-i18next"),require("antd"),require("@formily/shared"),require("@ant-design/icons"),require("@formily/react"),require("@emotion/css"),require("@nocobase/utils/client")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","react","react-router-dom","react-i18next","antd","@formily/shared","@ant-design/icons","@formily/react","@emotion/css","@nocobase/utils/client"],e):(c=typeof globalThis!="undefined"?globalThis:c||self,e(c["@nocobase/plugin-auth"]={},c["@nocobase/client"],c.jsxRuntime,c.react,c["react-router-dom"],c["react-i18next"],c.antd,c["@formily/shared"],c["@ant-design/icons"],c["@formily/react"],c["@emotion/css"],c["@nocobase/utils"]))})(this,function(c,e,n,u,m,x,d,g,y,h,b,E){"use strict";var ae=Object.defineProperty,pe=Object.defineProperties;var ue=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var le=Object.prototype.hasOwnProperty,me=Object.prototype.propertyIsEnumerable;var P=(c,e,n)=>e in c?ae(c,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):c[e]=n,v=(c,e)=>{for(var n in e||(e={}))le.call(e,n)&&P(c,n,e[n]);if($)for(var n of $(e))me.call(e,n)&&P(c,n,e[n]);return c},T=(c,e)=>pe(c,ue(e));var N=(c,e,n)=>(P(c,typeof e!="symbol"?e+"":e,n),n);var C=(c,e,n)=>new Promise((u,m)=>{var x=y=>{try{g(n.next(y))}catch(h){m(h)}},d=y=>{try{g(n.throw(y))}catch(h){m(h)}},g=y=>y.done?u(y.value):Promise.resolve(y.value).then(x,d);g((n=n.apply(c,e)).next())});const j=t=>{const r=m.useLocation(),o=e.useAPIClient();return u.useEffect(()=>{const i=new URLSearchParams(r.search),s=i.get("authenticator"),a=i.get("token");a&&(o.auth.setToken(a),o.auth.setAuthenticator(s))}),n.jsx(n.Fragment,{children:t.children})},F="auth";function A(){return x.useTranslation([F,"client"],{nsMode:"fallback"})}const I=u.createContext({type:""}),U=u.createContext({types:[]}),B=()=>{const{types:t}=u.useContext(U);return t},k={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":t=>/^[a-zA-Z0-9_-]+$/.test(t)?"":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"}}]},L={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(t){const r=e.useActionContext(),{type:o}=u.useContext(I);return e.useRequest(()=>Promise.resolve({data:{name:`s_${g.uid()}`,authType:o}}),T(v({},t),{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 }}"}}}}}}}},O={type:"void",name:"authenticators","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:k,resourceName:"authenticators",dragSort:!0,request:{resource:"authenticators",action:"list",params:{pageSize:50,sort:"sort",appends:[]}}},"x-component":"CollectionProvider","x-component-props":{collection:k},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 t=e.useAPIClient(),{t:r}=x.useTranslation();return{move(i,s){return C(this,null,function*(){yield t.resource("authenticators").move({sourceId:i.id,targetId:s.id}),d.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() }}"}}}}}}}}},V=t=>{const r=e.useRecord(),o=e.useRequest(()=>Promise.resolve({data:v({},r.options)}),T(v({},t),{manual:!0})),{run:i}=o,s=e.useActionContext();return u.useEffect(()=>{s.visible&&i()},[s.visible,i]),o},_=t=>{var i;const o=e.usePlugin(f).authTypes.get(t);return(i=o==null?void 0:o.components)==null?void 0:i.AdminSettingsForm},M=h.observer(()=>{const t=h.useForm(),r=e.useRecord(),o=_(t.values.authType||r.authType);return o?n.jsx(o,{}):null}),z=()=>{const{setVisible:t}=e.useActionContext();return{run(){return C(this,null,function*(){t(!1)})}}},Z=()=>{const{t}=x.useTranslation(),[r,o]=u.useState(!1),[i,s]=u.useState(""),a=B(),p=a.map(l=>T(v({},l),{onClick:()=>{o(!0),s(l.value)}}));return n.jsx(e.ActionContextProvider,{value:{visible:r,setVisible:o},children:n.jsxs(I.Provider,{value:{type:i},children:[n.jsx(d.Dropdown,{menu:{items:p},children:n.jsxs(d.Button,{icon:n.jsx(y.PlusOutlined,{}),type:"primary",children:[t("Add new")," ",n.jsx(y.DownOutlined,{})]})}),n.jsx(e.SchemaComponent,{scope:{useCloseAction:z,types:a,setType:s},schema:L})]})})},K=()=>(e.useAsyncData(),!1),W=()=>{const{t}=A(),[r,o]=u.useState([]),i=e.useAPIClient();return e.useRequest(()=>i.resource("authenticators").listTypes().then(s=>{var p;return(((p=s==null?void 0:s.data)==null?void 0:p.data)||[]).map(l=>({key:l.name,label:t(l.title||l.name),value:l.name}))}),{onSuccess:s=>{o(s)}}),n.jsx(d.Card,{bordered:!1,children:n.jsx(U.Provider,{value:{types:r},children:n.jsx(e.SchemaComponent,{schema:O,components:{AddNew:Z,Options:M},scope:{types:r,useValuesFromOptions:V,useCanNotDelete:K,t}})})})},S=u.createContext([]),w=t=>u.useContext(S).find(o=>o.name===t);function G(t){var a;const{data:r}=e.useSystemSettings(),o=e.useAPIClient(),{data:i=[],error:s}=e.useRequest(()=>o.resource("authenticators").publicList().then(p=>{var l;return((l=p==null?void 0:p.data)==null?void 0:l.data)||[]}));if(s)throw s;return n.jsxs("div",{style:{maxWidth:320,margin:"0 auto",paddingTop:"20vh"},children:[n.jsx("h1",{children:(a=r==null?void 0:r.data)==null?void 0:a.title}),n.jsx(S.Provider,{value:i,children:n.jsx(m.Outlet,{})}),n.jsx("div",{className:b.css` | ||
position: absolute; | ||
bottom: 24px; | ||
width: 100%; | ||
left: 0; | ||
text-align: center; | ||
`,children:n.jsx(e.PoweredBy,{})})]})}const H=()=>{var i;const r=e.usePlugin(f).authTypes.getEntities(),o={};for(const[s,a]of r)(i=a.components)!=null&&i.SignInForm&&(o[s]=a.components.SignInForm);return o},J=(t=[])=>{var a;const o=e.usePlugin(f).authTypes.getEntities(),i={};for(const[p,l]of o)(a=l.components)!=null&&a.SignInButton&&(i[p]=l.components.SignInButton);const s=Object.keys(i);return t.filter(p=>s.includes(p.authType)).map((p,l)=>u.createElement(i[p.authType],{key:l,authenticator:p}))},Q=()=>{const{t}=A();e.useCurrentDocumentTitle("Signin"),e.useViewport();const r=H(),o=u.useContext(S),i=J(o);if(!o.length)return n.jsx("div",{style:{color:"#ccc"},children:t("No authentication methods available.")});const s=o.map(a=>{const p=r[a.authType];if(!p)return;const l=`${t("Sign-in")} (${t(a.authTypeTitle||a.authType)})`;return v({component:u.createElement(p,{authenticator:a}),tabTitle:a.title||l},a)}).filter(a=>a);return n.jsxs(d.Space,{direction:"vertical",className:b.css` | ||
display: flex; | ||
`,children:[s.length>1?n.jsx(d.Tabs,{items:s.map(a=>({label:a.tabTitle,key:a.name,children:a.component}))}):s.length?n.jsx("div",{children:s[0].component}):n.jsx(n.Fragment,{}),n.jsx(d.Space,{direction:"vertical",className:b.css` | ||
display: flex; | ||
`,children:i})]})};u.createContext({});const q=()=>{var i;const r=e.usePlugin(f).authTypes.getEntities(),o={};for(const[s,a]of r)(i=a.components)!=null&&i.SignUpForm&&(o[s]=a.components.SignUpForm);return o},X=()=>{e.useViewport(),e.useCurrentDocumentTitle("Signup");const t=q(),[r]=m.useSearchParams(),o=r.get("name"),i=w(o),{authType:s}=i||{};return t[s]?u.createElement(t[s],{authenticatorName:o}):n.jsx(m.Navigate,{to:"/not-found",replace:!0})},Y="Email/Password";function R(t="/admin"){const r=m.useNavigate(),[o]=m.useSearchParams();return u.useCallback(()=>{r(o.get("redirect")||"/admin",{replace:!0})},[r,o])}const D=t=>{const r=h.useForm(),o=e.useAPIClient(),i=R(),{refreshAsync:s}=e.useCurrentUserContext();return{run(){return C(this,null,function*(){yield r.submit(),yield o.auth.signIn(r.values,t),yield s(),i()})}}},ee={type:"object",name:"passwordForm","x-component":"FormV2",properties:{account:{type:"string","x-component":"Input","x-validator":`{{(value) => { | ||
if (!value) { | ||
@@ -12,2 +22,2 @@ return t("Please enter your username or email"); | ||
} | ||
}}}`,"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 }}"}}},$=o=>{const{t:r}=h(),i=o.authenticator,{authType:p,name:s,options:u}=i,m=!!c.useContext(e.SignupPageContext)[p]&&(u==null?void 0:u.allowSignup),G=`/signup?authType=${p}&name=${s}`,H=()=>e.useSignIn(s);return t.jsx(e.SchemaComponent,{schema:q,scope:{useBasicSignIn:H,allowSignUp:m,signupLink:G,t:r}})},j={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")}}'}}}}},O=o=>{const{t:r}=h(),i=()=>e.useSignup({authenticator:o.name});return t.jsx(e.SchemaComponent,{schema:j,scope:{useBasicSignup:i,t:r}})},L=o=>{const{t:r}=h();return t.jsx(e.OptionsComponentProvider,{authType:b,component:k,children:t.jsx(e.SigninPageProvider,{authType:b,tabTitle:r("Sign in via password"),component:$,children:t.jsx(e.SignupPageProvider,{authType:b,component:O,children:o.children})})})},E=o=>{const r=y.useLocation(),i=e.useAPIClient();return c.useEffect(()=>{const p=new URLSearchParams(r.search),s=p.get("authenticator"),u=p.get("token");u&&(i.auth.setToken(u),i.auth.setAuthenticator(s))}),t.jsx(t.Fragment,{children:o.children})},w=c.createContext({type:""}),T=c.createContext({types:[]}),V=()=>{const{types:o}=c.useContext(T);return o},F={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":o=>/^[a-zA-Z0-9_-]+$/.test(o)?"":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"}}]},B={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(o){const r=e.useActionContext(),{type:i}=c.useContext(w);return e.useRequest(()=>Promise.resolve({data:{name:`s_${A.uid()}`,authType:i}}),C(g({},o),{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 }}"}}}}}}}},U={type:"void",name:"authenticators","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:F,resourceName:"authenticators",dragSort:!0,request:{resource:"authenticators",action:"list",params:{pageSize:50,sort:"sort",appends:[]}}},"x-component":"CollectionProvider","x-component-props":{collection:F},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 o=e.useAPIClient(),{t:r}=x.useTranslation();return{move(p,s){return f(this,null,function*(){yield o.resource("authenticators").move({sourceId:p.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() }}"}}}}}}}}},_=o=>{const r=e.useRecord(),i=e.useRequest(()=>Promise.resolve({data:g({},r.options)}),C(g({},o),{manual:!0})),{run:p}=i,s=e.useActionContext();return c.useEffect(()=>{s.visible&&p()},[s.visible,p]),i},N=d.observer(()=>{const o=d.useForm(),r=e.useRecord();return e.useOptionsComponent(o.values.authType||r.authType)}),M=()=>{const{setVisible:o}=e.useActionContext();return{run(){return f(this,null,function*(){o(!1)})}}},z=()=>{const{t:o}=x.useTranslation(),[r,i]=c.useState(!1),[p,s]=c.useState(""),u=V(),v=u.map(m=>C(g({},m),{onClick:()=>{i(!0),s(m.value)}}));return t.jsx(e.ActionContextProvider,{value:{visible:r,setVisible:i},children:t.jsxs(w.Provider,{value:{type:p},children:[t.jsx(l.Dropdown,{menu:{items:v},children:t.jsxs(l.Button,{icon:t.jsx(a.PlusOutlined,{}),type:"primary",children:[o("Add new")," ",t.jsx(a.DownOutlined,{})]})}),t.jsx(e.SchemaComponent,{scope:{useCloseAction:M,types:u,setType:s},schema:B})]})})},Z=()=>(e.useAsyncData(),!1),K=()=>{const{t:o}=h(),[r,i]=c.useState([]),p=e.useAPIClient();return e.useRequest(()=>p.resource("authenticators").listTypes().then(s=>{var v;return(((v=s==null?void 0:s.data)==null?void 0:v.data)||[]).map(m=>({key:m.name,label:o(m.title||m.name),value:m.name}))}),{onSuccess:s=>{i(s)}}),t.jsx(l.Card,{bordered:!1,children:t.jsx(T.Provider,{value:{types:r},children:t.jsx(e.SchemaComponent,{schema:U,components:{AddNew:z,Options:N},scope:{types:r,useValuesFromOptions:_,useCanNotDelete:Z,t:o}})})})};class P extends e.Plugin{load(){return f(this,null,function*(){this.app.pluginSettingsManager.add(S,{icon:"LoginOutlined",title:`{{t("Authentication", { ns: "${S}" })}}`,Component:K,aclSnippet:"pm.auth.authenticators"}),this.app.providers.unshift([E,{}]),this.app.use(L)})}}n.AuthPlugin=P,n.default=P,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
}}}`,"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 }}"}}},te=t=>{const{t:r}=A(),o=t.authenticator,{authType:i,name:s,options:a}=o,l=!!q()[i]&&(a==null?void 0:a.allowSignUp),ie=`/signup?name=${s}`,ce=()=>D(s);return n.jsx(e.SchemaComponent,{schema:ee,scope:{useBasicSignIn:ce,allowSignUp:l,signUpLink:ie,t:r}})},oe=t=>{const r=m.useNavigate(),o=h.useForm(),i=e.useAPIClient(),{t:s}=x.useTranslation();return{run(){return C(this,null,function*(){var p;yield o.submit(),yield i.auth.signUp(o.values,t==null?void 0:t.authenticator),d.message.success(((p=t==null?void 0:t.message)==null?void 0:p.success)||s("Sign up successfully, and automatically jump to the sign in page")),setTimeout(()=>{r("/signin")},2e3)})}}},ne={type:"object",name:g.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")}}'}}}}},se=({authenticatorName:t})=>{const{t:r}=A(),o=()=>oe({authenticator:t}),i=w(t),{options:s}=i;return s!=null&&s.allowSignUp?n.jsx(e.SchemaComponent,{schema:ne,scope:{useBasicSignUp:o,t:r}}):n.jsx(m.Navigate,{to:"/not-found",replace:!0})},re=()=>{const{t}=A();return n.jsx(e.SchemaComponent,{scope:{t},components:{Alert:d.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.")}}'}}}}})};class f extends e.Plugin{constructor(){super(...arguments);N(this,"authTypes",new E.Registry)}registerType(o,i){this.authTypes.register(o,i)}load(){return C(this,null,function*(){this.app.pluginSettingsManager.add(F,{icon:"LoginOutlined",title:`{{t("Authentication", { ns: "${F}" })}}`,Component:W,aclSnippet:"pm.auth.authenticators"}),this.router.add("auth",{Component:"AuthLayout"}),this.router.add("auth.signin",{path:"/signin",Component:"SignInPage"}),this.router.add("auth.signup",{path:"/signup",Component:"SignUpPage"}),this.app.addComponents({AuthLayout:G,SignInPage:Q,SignUpPage:X}),this.app.providers.unshift([j,{}]),this.registerType(Y,{components:{SignInForm:te,SignUpForm:se,AdminSettingsForm:re}})})}}c.AuthPlugin=f,c.AuthenticatorsContext=S,c.default=f,c.useAuthenticator=w,c.useSignIn=D,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
@@ -1,2 +0,2 @@ | ||
/// <reference types="react" /> | ||
import React from 'react'; | ||
export declare const useValuesFromOptions: (options: any) => { | ||
@@ -16,2 +16,3 @@ state: {}; | ||
}; | ||
export declare const Options: import("react").MemoExoticComponent<import("@formily/react").ReactFC<unknown>>; | ||
export declare const useAdminSettingsForm: (authType: string) => any; | ||
export declare const Options: React.MemoExoticComponent<import("@formily/react").ReactFC<unknown>>; |
module.exports = { | ||
"@nocobase/client": "0.17.0-alpha.7", | ||
"@nocobase/client": "0.18.0-alpha.1", | ||
"react": "18.2.0", | ||
"react-router-dom": "6.14.1", | ||
"@nocobase/auth": "0.17.0-alpha.7", | ||
"@nocobase/database": "0.17.0-alpha.7", | ||
"@nocobase/server": "0.17.0-alpha.7", | ||
"@nocobase/cache": "0.17.0-alpha.7", | ||
"@nocobase/test": "0.17.0-alpha.7", | ||
"antd": "5.8.6", | ||
"@formily/react": "2.2.27", | ||
"@formily/shared": "2.2.27", | ||
"react-router-dom": "6.21.0", | ||
"@nocobase/utils": "0.18.0-alpha.1", | ||
"@nocobase/auth": "0.18.0-alpha.1", | ||
"@nocobase/database": "0.18.0-alpha.1", | ||
"@nocobase/server": "0.18.0-alpha.1", | ||
"@nocobase/cache": "0.18.0-alpha.1", | ||
"@nocobase/test": "0.18.0-alpha.1", | ||
"antd": "5.12.2", | ||
"@formily/react": "2.3.0", | ||
"@formily/shared": "2.3.0", | ||
"react-i18next": "11.18.6", | ||
"@ant-design/icons": "5.1.4", | ||
"@nocobase/actions": "0.17.0-alpha.7" | ||
"@emotion/css": "11.11.2", | ||
"@ant-design/icons": "5.2.6", | ||
"@nocobase/actions": "0.18.0-alpha.1" | ||
}; |
@@ -22,3 +22,6 @@ { | ||
"Auth UID": "Auth UID", | ||
"The authentication allows users to sign in via username or email.": "The authentication allows users to sign in via username or email." | ||
"The authentication allows users to sign in via username or email.": "The authentication allows users to sign in via username or email.", | ||
"No authentication methods available.": "No authentication methods available.", | ||
"The password is inconsistent, please re-enter": "The password is inconsistent, please re-enter", | ||
"Sign-in": "Sign-in" | ||
} |
@@ -22,3 +22,6 @@ { | ||
"Auth UID": "认证标识", | ||
"The authentication allows users to sign in via username or email.": "该认证方式支持用户通过用户名或邮箱登录。" | ||
"The authentication allows users to sign in via username or email.": "该认证方式支持用户通过用户名或邮箱登录。", | ||
"No authentication methods available.": "没有可用的认证方式。", | ||
"The password is inconsistent, please re-enter": "密码不一致,请重新输入", | ||
"Sign-in": "登录" | ||
} |
@@ -155,13 +155,22 @@ const CONSTRAINTS = [ | ||
if (typeof this.utcOffset !== 'undefined') { | ||
let offset = | ||
const offsetHours = parseInt( | ||
this.utcOffset >= 60 || this.utcOffset <= -60 | ||
? this.utcOffset / 60 | ||
: this.utcOffset; | ||
offset = parseInt(offset); | ||
: this.utcOffset | ||
); | ||
const offsetMins = | ||
this.utcOffset >= 60 || this.utcOffset <= -60 | ||
? Math.abs(this.utcOffset - offsetHours * 60) | ||
: 0; | ||
const offsetMinsStr = offsetMins >= 10 ? offsetMins : '0' + offsetMins; | ||
let utcZone = 'UTC'; | ||
if (offset < 0) { | ||
utcZone += offset; | ||
} else if (offset > 0) { | ||
utcZone += `+${offset}`; | ||
if (parseInt(this.utcOffset) < 0) { | ||
utcZone += `${ | ||
offsetHours === 0 ? '-0' : offsetHours | ||
}:${offsetMinsStr}`; | ||
} else { | ||
utcZone += `+${offsetHours}:${offsetMinsStr}`; | ||
} | ||
@@ -263,6 +272,10 @@ | ||
// it shouldn't take more than 5 seconds to find the next execution time | ||
// being very generous with this. Throw error if it takes too long to find the next time to protect from | ||
// infinite loop. | ||
const timeout = Date.now() + 5000; | ||
/** | ||
* maximum match interval is 8 years: | ||
* crontab has '* * 29 2 *' and we are on 1 March 2096: | ||
* next matching time will be 29 February 2104 | ||
* source: https://github.com/cronie-crond/cronie/blob/0d669551680f733a4bdd6bab082a0b3d6d7f089c/src/cronnext.c#L401-L403 | ||
*/ | ||
const maxMatch = luxon.DateTime.now().plus({ years: 8 }); | ||
// determine next date | ||
@@ -272,7 +285,7 @@ while (true) { | ||
// hard stop if the current date is after the expected execution | ||
if (Date.now() > timeout) { | ||
// hard stop if the current date is after the maximum match interval | ||
if (date > maxMatch) { | ||
throw new Error( | ||
`Something went wrong. It took over five seconds to find the next execution time for the cron job. | ||
Please refer to the canonical issue (https://github.com/kelektiv/node-cron/issues/467) and provide the following string if you would like to help debug: | ||
`Something went wrong. No execution date was found in the next 8 years. | ||
Please provide the following string if you would like to help debug: | ||
Time Zone: ${zone || '""'} - Cron String: ${this} - UTC offset: ${date.offset} | ||
@@ -770,3 +783,3 @@ - current Date: ${luxon.DateTime.local().toString()}` | ||
lower = parseInt(lower, 10); | ||
upper = parseInt(upper, 10) || undefined; | ||
upper = upper !== undefined ? parseInt(upper, 10) : undefined; | ||
@@ -779,3 +792,3 @@ const wasStepDefined = !isNaN(parseInt(step, 10)); | ||
if (upper && lower > upper) { | ||
if (upper !== undefined && lower > upper) { | ||
throw new Error(`Field (${type}) has an invalid range`); | ||
@@ -786,4 +799,4 @@ } | ||
lower < low || | ||
(upper && upper > high) || | ||
(!upper && lower > high); | ||
(upper !== undefined && upper > high) || | ||
(upper === undefined && lower > high); | ||
@@ -798,3 +811,3 @@ if (outOfRangeError) { | ||
// Positive integer lower than constraints[1] | ||
if (upper) { | ||
if (upper !== undefined) { | ||
upper = Math.min(high, ~~Math.abs(upper)); | ||
@@ -801,0 +814,0 @@ } else { |
@@ -1,1 +0,1 @@ | ||
{"name":"cron","description":"Cron jobs for your node","version":"2.3.1","author":"Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)","bugs":{"url":"https://github.com/kelektiv/node-cron/issues"},"repository":{"type":"git","url":"https://github.com/kelektiv/node-cron.git"},"main":"lib/cron","scripts":{"lint":"eslint {lib,tests}/*.js","test":"jest --coverage","test:watch":"jest --watch --coverage"},"dependencies":{"luxon":"^3.2.1"},"devDependencies":{"chai":"~4.2.x","eslint":"~8.36.x","eslint-config-prettier":"^8.7.x","eslint-config-standard":"~17.0.x","eslint-plugin-import":"~2.27.x","eslint-plugin-jest":"~27.2.x","eslint-plugin-n":"~15.6.x","eslint-plugin-prettier":"~4.2.x","eslint-plugin-promise":"~6.1.x","jest":"~29.5.x","prettier":"~2.8.x","sinon":"^15.0.x"},"keywords":["cron","node cron","node-cron","schedule","scheduler","cronjob","cron job"],"license":"MIT","contributors":["Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)","Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)","James Padolsey <> (https://github.com/jamespadolsey)","Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)","Clifton Cunningham <clifton.cunningham@gmail.com> (https://github.com/cliftonc)","Eric Abouaf <eric.abouaf@gmail.com> (https://github.com/neyric)","humanchimp <morphcham@gmail.com> (https://github.com/humanchimp)","Craig Condon <craig@spiceapps.com> (https://github.com/spiceapps)","Dan Bear <daniel@hulu.com> (https://github.com/danhbear)","Vadim Baryshev <vadimbaryshev@gmail.com> (https://github.com/baryshev)","Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)","Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)","Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)","Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)","Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"],"jest":{"collectCoverage":true,"collectCoverageFrom":["lib/*.js"],"coverageThreshold":{"global":{"statements":80,"branches":80,"functions":70,"lines":80}}},"files":["lib","CHANGELOG.md","LICENSE","README.md"],"_lastModified":"2023-12-15T03:54:22.719Z"} | ||
{"name":"cron","description":"Cron jobs for your node","version":"2.4.4","author":"Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)","bugs":{"url":"https://github.com/kelektiv/node-cron/issues"},"repository":{"type":"git","url":"https://github.com/kelektiv/node-cron.git"},"main":"lib/cron","scripts":{"lint":"eslint {lib,tests}/*.js","test":"jest --coverage","test:watch":"jest --watch --coverage","test:types":"tsd","prepare":"husky install","release":"semantic-release"},"types":"types/index.d.ts","dependencies":{"@types/luxon":"~3.3.0","luxon":"~3.3.0"},"devDependencies":{"@commitlint/cli":"~17.6.6","@insurgentlab/commitlint-config":"^18.1.0","@insurgentlab/conventional-changelog-preset":"~6.0.3","@semantic-release/changelog":"~6.0.x","@semantic-release/commit-analyzer":"~9.0.x","@semantic-release/git":"~10.0.x","@semantic-release/github":"~8.1.x","@semantic-release/npm":"~10.0.x","@semantic-release/release-notes-generator":"~11.0.x","chai":"~4.2.x","eslint":"~8.36.x","eslint-config-prettier":"^8.7.x","eslint-config-standard":"~17.0.x","eslint-plugin-import":"~2.27.x","eslint-plugin-jest":"~27.2.x","eslint-plugin-n":"~15.6.x","eslint-plugin-prettier":"~4.2.x","eslint-plugin-promise":"~6.1.x","husky":"^8.0.3","jest":"~29.5.x","prettier":"~2.8.x","semantic-release":"~21.0.x","sinon":"^15.0.x","tsd":"^0.28.1"},"keywords":["cron","node cron","node-cron","schedule","scheduler","cronjob","cron job"],"license":"MIT","contributors":["Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)","Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)","James Padolsey <> (https://github.com/jamespadolsey)","Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)","Clifton Cunningham <clifton.cunningham@gmail.com> (https://github.com/cliftonc)","Eric Abouaf <eric.abouaf@gmail.com> (https://github.com/neyric)","humanchimp <morphcham@gmail.com> (https://github.com/humanchimp)","Craig Condon <craig@spiceapps.com> (https://github.com/spiceapps)","Dan Bear <daniel@hulu.com> (https://github.com/danhbear)","Vadim Baryshev <vadimbaryshev@gmail.com> (https://github.com/baryshev)","Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)","Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)","Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)","Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)","Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"],"jest":{"collectCoverage":true,"collectCoverageFrom":["lib/*.js"],"coverageThreshold":{"global":{"statements":80,"branches":80,"functions":70,"lines":80}}},"files":["lib","types","CHANGELOG.md","LICENSE","README.md"],"_lastModified":"2023-12-21T12:48:00.637Z"} |
@@ -44,2 +44,3 @@ var __defProp = Object.defineProperty; | ||
const repo = ctx.db.getRepository("authenticators"); | ||
const authManager = ctx.app.authManager; | ||
const authenticators = await repo.find({ | ||
@@ -54,5 +55,7 @@ fields: ["name", "authType", "title", "options", "sort"], | ||
var _a; | ||
const authType = authManager.getAuthConfig(authenticator.authType); | ||
return { | ||
name: authenticator.name, | ||
authType: authenticator.authType, | ||
authTypeTitle: (authType == null ? void 0 : authType.title) || "", | ||
title: authenticator.title, | ||
@@ -59,0 +62,0 @@ options: ((_a = authenticator.options) == null ? void 0 : _a.public) || {} |
@@ -80,7 +80,10 @@ var __create = Object.create; | ||
const { values } = ctx.action.params; | ||
const { username } = values; | ||
const { username, password, confirm_password } = values; | ||
if (!/^[^@.<>"'/]{2,16}$/.test(username)) { | ||
ctx.throw(400, ctx.t("Please enter a valid username", { ns: import_preset.namespace })); | ||
} | ||
const user = await User.create({ values }); | ||
if (password !== confirm_password) { | ||
ctx.throw(400, ctx.t("The password is inconsistent, please re-enter", { ns: import_preset.namespace })); | ||
} | ||
const user = await User.create({ values: { username, password } }); | ||
return user; | ||
@@ -87,0 +90,0 @@ } |
@@ -0,6 +1,9 @@ | ||
import { Authenticator } from '@nocobase/auth'; | ||
import { Model } from '@nocobase/database'; | ||
export declare class AuthModel extends Model { | ||
export declare class AuthModel extends Model implements Authenticator { | ||
authType: string; | ||
options: any; | ||
findUser(uuid: string): Promise<Model<any, any>>; | ||
newUser(uuid: string, values?: any): Promise<Model<any, any>>; | ||
newUser(uuid: string, userValues?: any): Promise<Model<any, any>>; | ||
findOrCreateUser(uuid: string, userValues?: any): Promise<Model<any, any>>; | ||
} |
@@ -37,3 +37,3 @@ var __defProp = Object.defineProperty; | ||
} | ||
async newUser(uuid, values) { | ||
async newUser(uuid, userValues) { | ||
let user; | ||
@@ -43,3 +43,3 @@ const db = this.constructor.database; | ||
user = await this.createUser( | ||
values || { | ||
userValues || { | ||
nickname: uuid | ||
@@ -46,0 +46,0 @@ }, |
{ | ||
"name": "@nocobase/plugin-auth", | ||
"version": "0.17.0-alpha.7", | ||
"version": "0.18.0-alpha.1", | ||
"main": "./dist/server/index.js", | ||
@@ -27,3 +27,3 @@ "devDependencies": { | ||
"description.zh-CN": "提供基础认证功能和扩展认证器管理功能", | ||
"gitHead": "91377a3abd1124f79fb3819f2d0e80905e091a32" | ||
"gitHead": "0f5f1c0a37dc397a9dc4c8eec0c4ec20fd8107b0" | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1851039
111
46627
2