@nocobase/plugin-auth 1.5.0-alpha.5 → 1.5.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.js +27 -1
- package/dist/externalVersion.js +10 -9
- package/dist/locale/en-US.json +1 -1
- package/dist/locale/zh-CN.json +1 -1
- package/dist/node_modules/cron/package.json +1 -1
- package/dist/server/actions/authenticators.js +2 -2
- package/dist/server/basic-auth.d.ts +1 -0
- package/dist/server/basic-auth.js +25 -9
- package/dist/server/plugin.js +29 -3
- package/package.json +2 -2
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,30 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client"),require("@ant-design/icons"),require("@formily/react"),require("@formily/antd-v5"),require("@emotion/css"),require("react-i18next"),require("react"),require("@formily/shared"),require("@nocobase/utils/client"),require("antd"),require("react-router-dom")):"function"==typeof define&&define.amd?define("@nocobase/plugin-auth",["@nocobase/client","@ant-design/icons","@formily/react","@formily/antd-v5","@emotion/css","react-i18next","react","@formily/shared","@nocobase/utils/client","antd","react-router-dom"],t):"object"==typeof exports?exports["@nocobase/plugin-auth"]=t(require("@nocobase/client"),require("@ant-design/icons"),require("@formily/react"),require("@formily/antd-v5"),require("@emotion/css"),require("react-i18next"),require("react"),require("@formily/shared"),require("@nocobase/utils/client"),require("antd"),require("react-router-dom")):e["@nocobase/plugin-auth"]=t(e["@nocobase/client"],e["@ant-design/icons"],e["@formily/react"],e["@formily/antd-v5"],e["@emotion/css"],e["react-i18next"],e.react,e["@formily/shared"],e["@nocobase/utils/client"],e.antd,e["react-router-dom"])}(self,function(e,t,n,r,o,i,a,c,u,l,s){return function(){"use strict";var p={482:function(e){e.exports=t},964:function(e){e.exports=o},632:function(e){e.exports=r},505:function(e){e.exports=n},875:function(e){e.exports=c},772:function(t){t.exports=e},584:function(e){e.exports=u},721:function(e){e.exports=l},156:function(e){e.exports=a},238:function(e){e.exports=i},128:function(e){e.exports=s}},f={};function m(e){var t=f[e];if(void 0!==t)return t.exports;var n=f[e]={exports:{}};return p[e](n,n.exports,m),n.exports}m.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return m.d(t,{a:t}),t},m.d=function(e,t){for(var n in t)m.o(t,n)&&!m.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},m.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},m.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var y={};m.r(y),m.d(y,{AuthLayout:function(){return k},useSignIn:function(){return H},PluginAuthClient:function(){return eE},AuthenticatorsContextProvider:function(){return I},default:function(){return eF},AuthenticatorsContext:function(){return T},useAuthenticator:function(){return E}});var d=m("772"),b=m("584"),v=m("156"),h=m.n(v),x=function(e){var t=(0,d.useLocationSearch)(),n=(0,d.useApp)();return(0,v.useEffect)(function(){var e=new URLSearchParams(t),r=e.get("authenticator"),o=e.get("token");o&&(n.apiClient.auth.setToken(o),n.apiClient.auth.setAuthenticator(r))}),h().createElement(h().Fragment,null,e.children)},g=m("238"),w="auth";function O(){return(0,g.useTranslation)([w,"client"],{nsMode:"fallback"})}function S(e){return d.i18n.t(e,{ns:[w,"client"],nsMode:"fallback"})}var P=m("128"),A=m("505"),j=m("964"),C=m("721"),T=(0,v.createContext)([]);T.displayName="AuthenticatorsContext";var E=function(e){return(0,v.useContext)(T).find(function(t){return t.name===e})};function F(){var e,t,n=(e=["\n position: absolute;\n bottom: 24px;\n width: 100%;\n left: 0;\n text-align: center;\n "],!t&&(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}})));return F=function(){return n},n}var I=function(e){var t=e.children,n=(0,d.useAPIClient)(),r=(0,d.useRequest)(function(){return n.resource("authenticators").publicList().then(function(e){var t;return(null==e?void 0:null===(t=e.data)||void 0===t?void 0:t.data)||[]})}),o=r.data,i=r.error;if(r.loading)return h().createElement("div",{style:{textAlign:"center",marginTop:20}},h().createElement(C.Spin,null));if(i)throw i;return h().createElement(T.Provider,{value:void 0===o?[]:o},t)};function k(){var e,t=(0,d.useSystemSettings)().data;return h().createElement("div",{style:{maxWidth:320,margin:"0 auto",paddingTop:"20vh"}},h().createElement("div",{style:{position:"fixed",top:"2em",right:"2em"}},h().createElement(d.SwitchLanguage,null)),h().createElement("h1",{style:{textAlign:"center"}},h().createElement(d.ReadPretty.TextArea,{value:null==t?void 0:null===(e=t.data)||void 0===e?void 0:e.title})),h().createElement(I,null,h().createElement(P.Outlet,null)),h().createElement("div",{className:(0,j.css)(F())},h().createElement(d.PoweredBy,null)))}function D(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function q(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],a=!0,c=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,r=e}finally{try{!a&&null!=o.return&&o.return()}finally{if(c)throw r}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return D(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return D(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function U(e,t){return!t&&(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function N(){var e=U(["\n display: flex;\n "]);return N=function(){return e},e}function _(){var e=U(["\n display: flex;\n "]);return _=function(){return e},e}var R=function(){var e=(0,d.usePlugin)(eF).authTypes.getEntities(),t={},n=!0,r=!1,o=void 0;try{for(var i,a=e[Symbol.iterator]();!(n=(i=a.next()).done);n=!0){var c,u=q(i.value,2),l=u[0],s=u[1];(null===(c=s.components)||void 0===c?void 0:c.SignInForm)&&(t[l]=s.components.SignInForm)}}catch(e){r=!0,o=e}finally{try{!n&&null!=a.return&&a.return()}finally{if(r)throw o}}return t},L=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=(0,d.usePlugin)(eF).authTypes.getEntities(),n={},r=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(r=(a=c.next()).done);r=!0){var u,l=q(a.value,2),s=l[0],p=l[1];(null===(u=p.components)||void 0===u?void 0:u.SignInButton)&&(n[s]=p.components.SignInButton)}}catch(e){o=!0,i=e}finally{try{!r&&null!=c.return&&c.return()}finally{if(o)throw i}}var f=Object.keys(n);return e.filter(function(e){return f.includes(e.authType)}).map(function(e,t){return h().createElement(n[e.authType],{key:t,authenticator:e})})},$=function(){var e=O().t;(0,d.useCurrentDocumentTitle)("Signin"),(0,d.useViewport)();var t=R(),n=(0,v.useContext)(T),r=L(n);if(!n.length)return h().createElement("div",{style:{color:"#ccc"}},e("No authentication methods available."));var o=n.map(function(n){var r=t[n.authType];if(!!r){var o="".concat(e("Sign-in")," (").concat(A.Schema.compile(n.authTypeTitle||n.authType,{t:e}),")");return function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r,o,i;r=e,o=t,i=n[t],o in r?Object.defineProperty(r,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):r[o]=i})}return e}({component:(0,v.createElement)(r,{authenticator:n}),tabTitle:n.title||o},n)}}).filter(function(e){return e});return h().createElement(C.Space,{direction:"vertical",className:(0,j.css)(N())},o.length>1?h().createElement(C.Tabs,{items:o.map(function(e){return{label:e.tabTitle,key:e.name,children:e.component}})}):o.length?h().createElement("div",null,o[0].component):h().createElement(h().Fragment,null),h().createElement(C.Space,{direction:"vertical",className:(0,j.css)(_())},r))};function B(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function M(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],a=!0,c=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,r=e}finally{try{!a&&null!=o.return&&o.return()}finally{if(c)throw r}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return B(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return B(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(0,v.createContext)({}).displayName="SignupPageContext";var V=function(){var e=(0,d.usePlugin)(eF).authTypes.getEntities(),t={},n=!0,r=!1,o=void 0;try{for(var i,a=e[Symbol.iterator]();!(n=(i=a.next()).done);n=!0){var c,u=M(i.value,2),l=u[0],s=u[1];(null===(c=s.components)||void 0===c?void 0:c.SignUpForm)&&(t[l]=s.components.SignUpForm)}}catch(e){r=!0,o=e}finally{try{!n&&null!=a.return&&a.return()}finally{if(r)throw o}}return t},z=function(){(0,d.useViewport)(),(0,d.useCurrentDocumentTitle)("Signup");var e=V(),t=M((0,P.useSearchParams)(),1)[0].get("name"),n=(E(t)||{}).authType;return e[n]?(0,v.createElement)(e[n],{authenticatorName:t}):h().createElement(P.Navigate,{to:"/not-found",replace:!0})};function G(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Z(e,t,n,r,o,i,a){try{var c=e[i](a),u=c.value}catch(e){n(e);return}c.done?t(u):Promise.resolve(u).then(r,o)}var H=function(e){var t=(0,A.useForm)(),n=(0,d.useAPIClient)(),r=function(){arguments.length>0&&void 0!==arguments[0]&&arguments[0];var e,t,n=(0,P.useNavigate)();var r=(e=(0,P.useSearchParams)(),t=1,function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],a=!0,c=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,r=e}finally{try{!a&&null!=o.return&&o.return()}finally{if(c)throw r}}return i}}(e,1)||function(e,t){if(e){if("string"==typeof e)return G(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return G(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())[0];return(0,v.useCallback)(function(){n(r.get("redirect")||"/admin",{replace:!0})},[n,r])}(),o=(0,d.useCurrentUserContext)().refreshAsync;return{run:function(){var i;return(i=function(){return function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(i){switch(i.label){case 0:return[4,t.submit()];case 1:return i.sent(),[4,n.auth.signIn(t.values,e)];case 2:return i.sent(),[4,o()];case 3:return i.sent(),r(),[2]}})},function(){var e=this,t=arguments;return new Promise(function(n,r){var o=i.apply(e,t);function a(e){Z(o,n,r,a,c,"next",e)}function c(e){Z(o,n,r,a,c,"throw",e)}a(void 0)})})()}}},K={type:"object",name:"passwordForm","x-component":"FormV2",properties:{account:{type:"string","x-component":"Input","x-validator":'{{(value) => {\n if (!value) {\n return t("Please enter your username or email");\n }\n if (value.includes(\'@\')) {\n if (!/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/.test(value)) {\n return t("Please enter a valid email");\n }\n } else {\n return /^[^@.<>"\'/]{1,50}$/.test(value) || t("Please enter a valid username");\n }\n }}}',"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 }}"}}},W=function(e){var t=O().t,n=e.authenticator,r=n.authType,o=n.name,i=n.options,a=!!V()[r]&&null!=i&&!!i.allowSignUp,c="/signup?name=".concat(o);return h().createElement(d.SchemaComponent,{schema:K,scope:{useBasicSignIn:function(){return H(o)},allowSignUp:a,signUpLink:c,t:t}})},J=m("875");function Q(e,t,n,r,o,i,a){try{var c=e[i](a),u=c.value}catch(e){n(e);return}c.done?t(u):Promise.resolve(u).then(r,o)}var X={username:{type:"string","x-component":"Input","x-validator":{username:!0},"x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Username")}}',style:{}}},email:{type:"string","x-component":"Input","x-validator":"email","x-decorator":"FormItem","x-component-props":{placeholder:'{{t("Email")}}',style:{}}}},Y=function(e){var t=(0,P.useNavigate)(),n=(0,A.useForm)(),r=(0,d.useAPIClient)(),o=(0,g.useTranslation)().t;return{run:function(){var i;return(i=function(){var i;return function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(a){switch(a.label){case 0:return[4,n.submit()];case 1:return a.sent(),[4,r.auth.signUp(n.values,null==e?void 0:e.authenticator)];case 2:return a.sent(),C.message.success((null==e?void 0:null===(i=e.message)||void 0===i?void 0:i.success)||o("Sign up successfully, and automatically jump to the sign in page")),setTimeout(function(){t("/signin")},2e3),[2]}})},function(){var e=this,t=arguments;return new Promise(function(n,r){var o=i.apply(e,t);function a(e){Q(o,n,r,a,c,"next",e)}function c(e){Q(o,n,r,a,c,"throw",e)}a(void 0)})})()}}},ee=function(e){var t,n;return{type:"object",name:(0,J.uid)(),"x-component":"FormV2",properties:(t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r,o,i;r=e,o=t,i=n[t],o in r?Object.defineProperty(r,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):r[o]=i})}return e}({},e),n=(n={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")}}'}}}},n),Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t)}},et=function(e){var t=e.authenticatorName,n=O().t,r=E(t).options,o=r.signupForm;!((null==o?void 0:o.length)&&o.some(function(e){return e.show&&e.required}))&&(o=[{field:"username",show:!0,required:!0}]);var i=(0,v.useMemo)(function(){return o.filter(function(e){return e.show}).reduce(function(e,t){var n=t.field;if(X[n])return e[n]=X[n],t.required&&(e[n].required=!0),e},{})},[o]);if(!(null==r?void 0:r.allowSignUp))return h().createElement(P.Navigate,{to:"/not-found",replace:!0});var a=ee(i);return h().createElement(d.SchemaComponent,{schema:a,scope:{useBasicSignUp:function(){return Y({authenticator:t})},t:n}})},en=m("632"),er=function(){var e=O().t;return h().createElement(d.SchemaComponent,{scope:{t:e},components:{Alert:C.Alert,FormTab:en.FormTab,ArrayTable:en.ArrayTable},schema:{type:"object",properties:{notice:{type:"void","x-decorator":"FormItem","x-component":"Alert","x-component-props":{showIcon:!0,message:'{{t("The authentication allows users to sign in via username or email.")}}'}},public:{type:"object",properties:{collapse:{type:"void","x-component":"FormTab",properties:{basic:{type:"void","x-component":"FormTab.TabPane","x-component-props":{tab:S("Sign up settings")},properties:{allowSignUp:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Allow to sign up")}}',"x-component":"Checkbox",default:!0},signupForm:{title:'{{t("Sign up form")}}',type:"array","x-decorator":"FormItem","x-component":"ArrayTable","x-component-props":{bordered:!1},"x-validator":"{{ (value) => {\n const field = value?.filter((item) => item.show && item.required);\n if (!field?.length) {\n return t('At least one field is required');\n }\n} }}",default:[{field:"username",show:!0,required:!0},{field:"email",show:!1,required:!1}],items:{type:"object","x-decorator":"ArrayItems.Item",properties:{column0:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:20,align:"center"},properties:{sort:{type:"void","x-component":"ArrayTable.SortHandle"}}},column1:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:100,title:S("Field")},properties:{field:{type:"string","x-decorator":"FormItem","x-component":"Select",enum:[{label:S("Username"),value:"username"},{label:S("Email"),value:"email"}],"x-read-pretty":!0}}},column2:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:80,title:S("Show")},properties:{show:{type:"boolean","x-decorator":"FormItem","x-component":"Checkbox"}}},column3:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:80,title:S("Required")},properties:{required:{type:"boolean","x-decorator":"FormItem","x-component":"Checkbox"}}}}}}}}}}}}}}})},eo=(0,v.createContext)({type:""});eo.displayName="AuthTypeContext";var ei=(0,v.createContext)({types:[]});ei.displayName="AuthTypesContext";function ea(e,t,n,r,o,i,a){try{var c=e[i](a),u=c.value}catch(e){n(e);return}c.done?t(u):Promise.resolve(u).then(r,o)}var ec={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":function(e){return/^[a-zA-Z0-9_-]+$/.test(e)?"":d.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"}}]},eu={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:function(e){var t,n,r=(0,d.useActionContext)(),o=(0,v.useContext)(eo).type;return(0,d.useRequest)(function(){return Promise.resolve({data:{name:"s_".concat((0,J.uid)()),authType:o}})},(t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r,o,i;r=e,o=t,i=n[t],o in r?Object.defineProperty(r,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):r[o]=i})}return e}({},e),n=(n={refreshDeps:[r.visible]},n),Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t))}},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 }}"}}}}}}}},el={type:"void",name:"authenticators","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:ec,resourceName:"authenticators",dragSort:!0,request:{resource:"authenticators",action:"list",params:{pageSize:50,sort:"sort",appends:[]}}},"x-component":"CollectionProvider_deprecated","x-component-props":{collection:ec},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":{icon:"DeleteOutlined",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:function(){var e=(0,d.useAPIClient)(),t=(0,g.useTranslation)().t;return{move:function(n,r){var o;return(o=function(){return function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(o){switch(o.label){case 0:return[4,e.resource("authenticators").move({sourceId:n.id,targetId:r.id})];case 1:return o.sent(),C.message.success(t("Saved successfully"),.2),[2]}})},function(){var e=this,t=arguments;return new Promise(function(n,r){var i=o.apply(e,t);function a(e){ea(i,n,r,a,c,"next",e)}function c(e){ea(i,n,r,a,c,"throw",e)}a(void 0)})})()}}}},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() }}"}}}}}}}}},es=m("482");function ep(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r,o,i;r=e,o=t,i=n[t],o in r?Object.defineProperty(r,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):r[o]=i})}return e}var ef=function(e){var t,n,r=(0,d.useRecord)();var o=(0,d.useRequest)(function(){return Promise.resolve({data:ep({},r.options)})},(t=ep({},e),n=(n={manual:!0},n),Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t)),i=o.run,a=(0,d.useActionContext)();return(0,v.useEffect)(function(){a.visible&&i()},[a.visible,i]),o},em=function(e){var t,n=(0,d.usePlugin)(eF).authTypes.get(e);return null==n?void 0:null===(t=n.components)||void 0===t?void 0:t.AdminSettingsForm},ey=(0,A.observer)(function(){var e=(0,A.useForm)(),t=(0,d.useRecord)(),n=em(e.values.authType||t.authType);return n?h().createElement(n,null):null},{displayName:"Options"});function ed(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function eb(e,t,n,r,o,i,a){try{var c=e[i](a),u=c.value}catch(e){n(e);return}c.done?t(u):Promise.resolve(u).then(r,o)}function ev(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var i=[],a=!0,c=!1;try{for(o=o.call(e);!(a=(n=o.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,r=e}finally{try{!a&&null!=o.return&&o.return()}finally{if(c)throw r}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return ed(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return ed(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var eh=function(){var e=(0,d.useActionContext)().setVisible;return{run:function(){var t;return(t=function(){return function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(t){return e(!1),[2]})},function(){var e=this,n=arguments;return new Promise(function(r,o){var i=t.apply(e,n);function a(e){eb(i,r,o,a,c,"next",e)}function c(e){eb(i,r,o,a,c,"throw",e)}a(void 0)})})()}}},ex=function(){var e=(0,g.useTranslation)().t,t=ev((0,v.useState)(!1),2),n=t[0],r=t[1],o=ev((0,v.useState)(""),2),i=o[0],a=o[1],c=(0,v.useContext)(ei).types,u=c.map(function(e){var t,n;return t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r,o,i;r=e,o=t,i=n[t],o in r?Object.defineProperty(r,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):r[o]=i})}return e}({},e),n=(n={onClick:function(){r(!0),a(e.value)}},n),Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t});return h().createElement(d.ActionContextProvider,{value:{visible:n,setVisible:r}},h().createElement(eo.Provider,{value:{type:i}},h().createElement(C.Dropdown,{menu:{items:u}},h().createElement(C.Button,{icon:h().createElement(es.PlusOutlined,null),type:"primary"},e("Add new")," ",h().createElement(es.DownOutlined,null))),h().createElement(d.SchemaComponent,{scope:{useCloseAction:eh,types:c,setType:a},schema:eu})))},eg=function(){return(0,d.useAsyncData)().data,!1},ew=function(){var e=O().t,t=ev((0,v.useState)([]),2),n=t[0],r=t[1],o=(0,d.useAPIClient)();return(0,d.useRequest)(function(){return o.resource("authenticators").listTypes().then(function(t){var n;return((null==t?void 0:null===(n=t.data)||void 0===n?void 0:n.data)||[]).map(function(t){return{key:t.name,label:A.Schema.compile(t.title||t.name,{t:e}),value:t.name}})})},{onSuccess:function(e){r(e)}}),h().createElement(C.Card,{bordered:!1},h().createElement(ei.Provider,{value:{types:n}},h().createElement(d.SchemaComponent,{schema:el,components:{AddNew:ex,Options:ey},scope:{types:n,useValuesFromOptions:ef,useCanNotDelete:eg,t:e}})))};function eO(e,t,n,r,o,i,a){try{var c=e[i](a),u=c.value}catch(e){n(e);return}c.done?t(u):Promise.resolve(u).then(r,o)}function eS(e,t,n){return(eS=eT()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&ej(o,n.prototype),o}).apply(null,arguments)}function eP(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function eA(e){return(eA=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function ej(e,t){return(ej=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function eC(e){var t="function"==typeof Map?new Map:void 0;return(eC=function(e){var n;if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return eS(e,arguments,eA(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),ej(r,e)})(e)}function eT(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(eT=function(){return!!e})()}var eE=function(e){var t,n,r;function o(){var e,t,n,r,i,a,c;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),t=this,n=o,r=arguments,n=eA(n),i=e=function(e,t){return t&&("object"===function(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}(t)||"function"==typeof t)?t:function(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(t,eT()?Reflect.construct(n,r||[],eA(t).constructor):n.apply(t,r)),a="authTypes",c=new b.Registry,a in i?Object.defineProperty(i,a,{value:c,enumerable:!0,configurable:!0,writable:!0}):i[a]=c,e}return!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&ej(e,t)}(o,e),t=o,n=[{key:"registerType",value:function(e,t){this.authTypes.register(e,t)}},{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(e){return t.app.pluginSettingsManager.add(w,{icon:"LoginOutlined",title:'{{t("Authentication", { ns: "'.concat(w,'" })}}'),Component:ew,aclSnippet:"pm.auth.authenticators"}),t.router.add("auth",{Component:"AuthLayout"}),t.router.add("auth.signin",{path:"/signin",Component:"SignInPage"}),t.router.add("auth.signup",{path:"/signup",Component:"SignUpPage"}),t.app.addComponents({AuthLayout:k,SignInPage:$,SignUpPage:z}),t.app.providers.unshift([x,{}]),t.registerType("Email/Password",{components:{SignInForm:W,SignUpForm:et,AdminSettingsForm:er}}),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){eO(i,r,o,a,c,"next",e)}function c(e){eO(i,r,o,a,c,"throw",e)}a(void 0)})})()}}],eP(t.prototype,n),o}(eC(d.Plugin)),eF=eE;return y}()});
|
|
10
|
+
(function(c,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@nocobase/client"),require("@nocobase/utils/client"),require("react/jsx-runtime"),require("react"),require("react-i18next"),require("react-router-dom"),require("@formily/react"),require("@emotion/css"),require("antd"),require("@formily/shared"),require("@formily/antd-v5"),require("@ant-design/icons")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@nocobase/utils/client","react/jsx-runtime","react","react-i18next","react-router-dom","@formily/react","@emotion/css","antd","@formily/shared","@formily/antd-v5","@ant-design/icons"],t):(c=typeof globalThis!="undefined"?globalThis:c||self,t(c["@nocobase/plugin-auth"]={},c["@nocobase/client"],c["@nocobase/utils"],c.jsxRuntime,c.react,c["react-i18next"],c["react-router-dom"],c["@formily/react"],c["@emotion/css"],c.antd,c["@formily/shared"],c["@formily/antd-v5"],c["@ant-design/icons"]))})(this,function(c,t,m,a,l,A,g,x,y,d,k,$,E){"use strict";var he=Object.defineProperty,ge=Object.defineProperties;var fe=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var ve=Object.prototype.hasOwnProperty,Ce=Object.prototype.propertyIsEnumerable;var N=(c,t,m)=>t in c?he(c,t,{enumerable:!0,configurable:!0,writable:!0,value:m}):c[t]=m,h=(c,t)=>{for(var m in t||(t={}))ve.call(t,m)&&N(c,m,t[m]);if(_)for(var m of _(t))Ce.call(t,m)&&N(c,m,t[m]);return c},C=(c,t)=>ge(c,fe(t));var z=(c,t,m)=>(N(c,typeof t!="symbol"?t+"":t,m),m);var T=(c,t,m)=>new Promise((a,l)=>{var A=y=>{try{x(m.next(y))}catch(d){l(d)}},g=y=>{try{x(m.throw(y))}catch(d){l(d)}},x=y=>y.done?a(y.value):Promise.resolve(y.value).then(A,g);x((m=m.apply(c,t)).next())});const Z="Email/Password",H=e=>{const s=t.useLocationSearch(),o=t.useApp();return l.useEffect(()=>{const n=new URLSearchParams(s),r=n.get("authenticator"),i=n.get("token");i&&(o.apiClient.auth.setToken(i),o.apiClient.auth.setAuthenticator(r))}),a.jsx(a.Fragment,{children:e.children})},P="auth";function F(){return A.useTranslation([P,"client"],{nsMode:"fallback"})}function I(e){return t.i18n.t(e,{ns:[P,"client"],nsMode:"fallback"})}const w=l.createContext([]);w.displayName="AuthenticatorsContext";const q=e=>l.useContext(w).find(o=>o.name===e),L=({children:e})=>{const s=t.useAPIClient(),{data:o=[],error:n,loading:r}=t.useRequest(()=>s.resource("authenticators").publicList().then(i=>{var p;return((p=i==null?void 0:i.data)==null?void 0:p.data)||[]}));if(r)return a.jsx("div",{style:{textAlign:"center",marginTop:20},children:a.jsx(d.Spin,{})});if(n)throw n;return a.jsx(w.Provider,{value:o,children:e})};function j(){var s;const{data:e}=t.useSystemSettings();return a.jsxs("div",{style:{maxWidth:320,margin:"0 auto",paddingTop:"20vh"},children:[a.jsx("div",{style:{position:"fixed",top:"2em",right:"2em"},children:a.jsx(t.SwitchLanguage,{})}),a.jsx("h1",{style:{textAlign:"center"},children:a.jsx(t.ReadPretty.TextArea,{value:(s=e==null?void 0:e.data)==null?void 0:s.title})}),a.jsx(L,{children:a.jsx(g.Outlet,{})}),a.jsx("div",{className:y.css`
|
|
11
|
+
position: absolute;
|
|
12
|
+
bottom: 24px;
|
|
13
|
+
width: 100%;
|
|
14
|
+
left: 0;
|
|
15
|
+
text-align: center;
|
|
16
|
+
`,children:a.jsx(t.PoweredBy,{})})]})}const K=()=>{var n;const s=t.usePlugin(S).authTypes.getEntities(),o={};for(const[r,i]of s)(n=i.components)!=null&&n.SignInForm&&(o[r]=i.components.SignInForm);return o},W=(e=[])=>{var i;const o=t.usePlugin(S).authTypes.getEntities(),n={};for(const[p,u]of o)(i=u.components)!=null&&i.SignInButton&&(n[p]=u.components.SignInButton);const r=Object.keys(n);return e.filter(p=>r.includes(p.authType)).map((p,u)=>l.createElement(n[p.authType],{key:u,authenticator:p}))},G=()=>{const{t:e}=F();t.useCurrentDocumentTitle("Signin"),t.useViewport();const s=K(),o=l.useContext(w),n=W(o);if(!o.length)return a.jsx("div",{style:{color:"#ccc"},children:e("No authentication methods available.")});const r=o.map(i=>{const p=s[i.authType];if(!p)return;const u=`${e("Sign-in")} (${x.Schema.compile(i.authTypeTitle||i.authType,{t:e})})`;return h({component:l.createElement(p,{authenticator:i}),tabTitle:i.title||u},i)}).filter(i=>i);return a.jsxs(d.Space,{direction:"vertical",className:y.css`
|
|
17
|
+
display: flex;
|
|
18
|
+
`,children:[r.length>1?a.jsx(d.Tabs,{items:r.map(i=>({label:i.tabTitle,key:i.name,children:i.component}))}):r.length?a.jsx("div",{children:r[0].component}):a.jsx(a.Fragment,{}),a.jsx(d.Space,{direction:"vertical",className:y.css`
|
|
19
|
+
display: flex;
|
|
20
|
+
`,children:n})]})},J=l.createContext({});J.displayName="SignupPageContext";const B=()=>{var n;const s=t.usePlugin(S).authTypes.getEntities(),o={};for(const[r,i]of s)(n=i.components)!=null&&n.SignUpForm&&(o[r]=i.components.SignUpForm);return o},Q=()=>{t.useViewport(),t.useCurrentDocumentTitle("Signup");const e=B(),[s]=g.useSearchParams(),o=s.get("name"),n=q(o),{authType:r}=n||{};return e[r]?l.createElement(e[r],{authenticatorName:o}):a.jsx(g.Navigate,{to:"/not-found",replace:!0})};function X(e="/admin"){const s=g.useNavigate(),[o]=g.useSearchParams();return l.useCallback(()=>{s(o.get("redirect")||"/admin",{replace:!0})},[s,o])}const O=e=>{const s=x.useForm(),o=t.useAPIClient(),n=X(),{refreshAsync:r}=t.useCurrentUserContext();return{run(){return T(this,null,function*(){yield s.submit(),yield o.auth.signIn(s.values,e),yield r(),n()})}}},Y={type:"object",name:"passwordForm","x-component":"FormV2",properties:{account:{type:"string","x-component":"Input","x-validator":`{{(value) => {
|
|
21
|
+
if (!value) {
|
|
22
|
+
return t("Please enter your username or email");
|
|
23
|
+
}
|
|
24
|
+
if (value.includes('@')) {
|
|
25
|
+
if (!/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/.test(value)) {
|
|
26
|
+
return t("Please enter a valid email");
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
return /^[^@.<>"'/]{1,50}$/.test(value) || t("Please enter a valid username");
|
|
30
|
+
}
|
|
31
|
+
}}}`,"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 }}"}}},R=e=>{const{t:s}=F(),o=e.authenticator,{authType:n,name:r,options:i}=o,u=!!(B()[n]&&(i!=null&&i.allowSignUp)),f=`/signup?name=${r}`,v=()=>O(r);return a.jsx(t.SchemaComponent,{schema:Y,scope:{useBasicSignIn:v,allowSignUp:u,signUpLink:f,t:s}})},ee=e=>{const s=g.useNavigate(),o=x.useForm(),n=t.useAPIClient(),{t:r}=A.useTranslation();return{run(){return T(this,null,function*(){var p;yield o.submit(),yield n.auth.signUp(o.values,e==null?void 0:e.authenticator),d.message.success(((p=e==null?void 0:e.message)==null?void 0:p.success)||r("Sign up successfully, and automatically jump to the sign in page")),setTimeout(()=>{s("/signin")},2e3)})}}},te=e=>({type:"object",name:k.uid(),"x-component":"FormV2",properties:C(h({},e),{password:{type:"string",required:!0,title:'{{t("Password")}}',"x-component":"Password","x-decorator":"FormItem","x-component-props":{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",title:'{{t("Confirm password")}}',"x-component-props":{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")}}'}}}})}),oe=({authenticatorName:e})=>{const{t:s}=F(),o=()=>ee({authenticator:e}),n=q(e),{options:r}=n,{signupForm:i}=r,p=l.useMemo(()=>i.filter(f=>f.show).reduce((f,v)=>(f[v.field]=C(h({},v.uiSchema),{required:v.required,"x-decorator":"FormItem"}),f),{}),[i]);if(!(r!=null&&r.allowSignUp))return a.jsx(g.Navigate,{to:"/not-found",replace:!0});const u=te(p);return a.jsx(t.SchemaComponent,{schema:u,scope:{useBasicSignUp:o,t:s}})},ne=()=>{const e=t.useRecord(),n=t.useCollectionManager().getCollection("users").fields.filter(p=>{var u;return!p.hidden&&!p.target&&p.interface&&!((u=p.uiSchema)!=null&&u["x-read-pretty"])}),r=n.map(p=>{var u;return{value:p.name,label:(u=p.uiSchema)==null?void 0:u.title}}),i=l.useMemo(()=>{var f,v;const u=(((v=(f=e.options)==null?void 0:f.public)==null?void 0:v.signupForm)||[]).filter(b=>n.find(M=>M.name===b.field));for(const b of n)u.find(xe=>xe.field===b.name)||u.push({field:b.name,show:b.name==="username",required:b.name==="username"});return u},[n,e]);return l.useEffect(()=>{var p;e.options=C(h({},e.options),{public:C(h({},(p=e.options)==null?void 0:p.public),{signupForm:i})})},[e,i]),a.jsx(t.SchemaComponent,{components:{ArrayTable:$.ArrayTable},schema:{type:"void",properties:{signupForm:{title:'{{t("Sign up form")}}',type:"array","x-decorator":"FormItem","x-component":"ArrayTable","x-component-props":{bordered:!1},"x-validator":`{{ (value) => {
|
|
32
|
+
const check = value?.some((item) => ['username', 'email'].includes(item.field) && item.show && item.required);
|
|
33
|
+
if (!check) {
|
|
34
|
+
return t('At least one of the username or email fields is required');
|
|
35
|
+
}
|
|
36
|
+
} }}`,default:i,items:{type:"object","x-decorator":"ArrayItems.Item",properties:{column0:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:20,align:"center"},properties:{sort:{type:"void","x-component":"ArrayTable.SortHandle"}}},column1:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:100,title:I("Field")},properties:{field:{type:"string","x-decorator":"FormItem","x-component":"Select",enum:r,"x-read-pretty":!0}}},column2:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:80,title:I("Show")},properties:{show:{type:"boolean","x-decorator":"FormItem","x-component":"Checkbox","x-reactions":{dependencies:[".required"],fulfill:{state:{value:"{{ $deps[0] || $self.value }}"}}}}}},column3:{type:"void","x-component":"ArrayTable.Column","x-component-props":{width:80,title:I("Required")},properties:{required:{type:"boolean","x-decorator":"FormItem","x-component":"Checkbox","x-reactions":{dependencies:[".show"],fulfill:{state:{value:"{{ !$deps[0] ? false : $self.value }}"}}}}}}}}}}}})},re=()=>{const{t:e}=F();return a.jsx(t.SchemaComponent,{scope:{t:e},components:{Alert:d.Alert,SignupFormSettings:ne,FormTab:$.FormTab},schema:{type:"object",properties:{notice:{type:"void","x-decorator":"FormItem","x-component":"Alert","x-component-props":{showIcon:!0,message:'{{t("The authentication allows users to sign in via username or email.")}}'}},public:{type:"object",properties:{collapse:{type:"void","x-component":"FormTab",properties:{basic:{type:"void","x-component":"FormTab.TabPane","x-component-props":{tab:I("Sign up settings")},properties:{allowSignUp:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Allow to sign up")}}',"x-component":"Checkbox",default:!0},[k.uid()]:{type:"void","x-component":"SignupFormSettings"}}}}}}}}}})},U=l.createContext({type:""});U.displayName="AuthTypeContext";const D=l.createContext({types:[]});D.displayName="AuthTypesContext";const se=()=>{const{types:e}=l.useContext(D);return e},V={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":e=>/^[a-zA-Z0-9_-]+$/.test(e)?"":t.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"}}]},ie={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues(e){const s=t.useActionContext(),{type:o}=l.useContext(U);return t.useRequest(()=>Promise.resolve({data:{name:`s_${k.uid()}`,authType:o}}),C(h({},e),{refreshDeps:[s.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 }}"}}}}}}}},ae={type:"void",name:"authenticators","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:V,resourceName:"authenticators",dragSort:!0,request:{resource:"authenticators",action:"list",params:{pageSize:50,sort:"sort",appends:[]}}},"x-component":"CollectionProvider_deprecated","x-component-props":{collection:V},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":{icon:"DeleteOutlined",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 e=t.useAPIClient(),{t:s}=A.useTranslation();return{move(n,r){return T(this,null,function*(){yield e.resource("authenticators").move({sourceId:n.id,targetId:r.id}),d.message.success(s("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() }}"}}}}}}}}},ce=e=>{const s=t.useRecord(),o=t.useRequest(()=>Promise.resolve({data:h({},s.options)}),C(h({},e),{manual:!0})),{run:n}=o,r=t.useActionContext();return l.useEffect(()=>{r.visible&&n()},[r.visible,n]),o},pe=e=>{var n;const o=t.usePlugin(S).authTypes.get(e);return(n=o==null?void 0:o.components)==null?void 0:n.AdminSettingsForm},ue=x.observer(()=>{const e=x.useForm(),s=t.useRecord(),o=pe(e.values.authType||s.authType);return o?a.jsx(o,{}):null},{displayName:"Options"}),le=()=>{const{setVisible:e}=t.useActionContext();return{run(){return T(this,null,function*(){e(!1)})}}},me=()=>{const{t:e}=A.useTranslation(),[s,o]=l.useState(!1),[n,r]=l.useState(""),i=se(),p=i.map(u=>C(h({},u),{onClick:()=>{o(!0),r(u.value)}}));return a.jsx(t.ActionContextProvider,{value:{visible:s,setVisible:o},children:a.jsxs(U.Provider,{value:{type:n},children:[a.jsx(d.Dropdown,{menu:{items:p},children:a.jsxs(d.Button,{icon:a.jsx(E.PlusOutlined,{}),type:"primary",children:[e("Add new")," ",a.jsx(E.DownOutlined,{})]})}),a.jsx(t.SchemaComponent,{scope:{useCloseAction:le,types:i,setType:r},schema:ie})]})})},de=()=>(t.useAsyncData(),!1),ye=()=>{const{t:e}=F(),[s,o]=l.useState([]),n=t.useAPIClient();return t.useRequest(()=>n.resource("authenticators").listTypes().then(r=>{var p;return(((p=r==null?void 0:r.data)==null?void 0:p.data)||[]).map(u=>({key:u.name,label:x.Schema.compile(u.title||u.name,{t:e}),value:u.name}))}),{onSuccess:r=>{o(r)}}),a.jsx(d.Card,{bordered:!1,children:a.jsx(D.Provider,{value:{types:s},children:a.jsx(t.SchemaComponent,{schema:ae,components:{AddNew:me,Options:ue},scope:{types:s,useValuesFromOptions:ce,useCanNotDelete:de,t:e}})})})};class S extends t.Plugin{constructor(){super(...arguments);z(this,"authTypes",new m.Registry)}registerType(o,n){this.authTypes.register(o,n)}load(){return T(this,null,function*(){this.app.pluginSettingsManager.add(P,{icon:"LoginOutlined",title:`{{t("Authentication", { ns: "${P}" })}}`,Component:ye,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:j,SignInPage:G,SignUpPage:Q}),this.app.providers.unshift([H,{}]),this.registerType(Z,{components:{SignInForm:R,SignUpForm:oe,AdminSettingsForm:re}})})}}c.AuthLayout=j,c.AuthenticatorsContext=w,c.AuthenticatorsContextProvider=L,c.PluginAuthClient=S,c.default=S,c.useAuthenticator=q,c.useSignIn=O,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/externalVersion.js
CHANGED
|
@@ -8,21 +8,22 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "1.5.0-
|
|
11
|
+
"@nocobase/client": "1.5.0-beta.2",
|
|
12
12
|
"react": "18.2.0",
|
|
13
|
-
"@nocobase/utils": "1.5.0-
|
|
14
|
-
"@nocobase/auth": "1.5.0-
|
|
15
|
-
"@nocobase/database": "1.5.0-
|
|
16
|
-
"
|
|
17
|
-
"@nocobase/
|
|
18
|
-
"@nocobase/
|
|
13
|
+
"@nocobase/utils": "1.5.0-beta.2",
|
|
14
|
+
"@nocobase/auth": "1.5.0-beta.2",
|
|
15
|
+
"@nocobase/database": "1.5.0-beta.2",
|
|
16
|
+
"lodash": "4.17.21",
|
|
17
|
+
"@nocobase/cache": "1.5.0-beta.2",
|
|
18
|
+
"@nocobase/server": "1.5.0-beta.2",
|
|
19
|
+
"@nocobase/test": "1.5.0-beta.2",
|
|
19
20
|
"@formily/antd-v5": "1.1.9",
|
|
20
21
|
"antd": "5.12.8",
|
|
22
|
+
"@formily/shared": "2.3.2",
|
|
21
23
|
"@formily/react": "2.3.0",
|
|
22
24
|
"react-router-dom": "6.21.0",
|
|
23
|
-
"@formily/shared": "2.3.2",
|
|
24
25
|
"react-i18next": "11.18.6",
|
|
25
26
|
"@emotion/css": "11.13.0",
|
|
26
27
|
"@ant-design/icons": "5.2.6",
|
|
27
|
-
"@nocobase/actions": "1.5.0-
|
|
28
|
+
"@nocobase/actions": "1.5.0-beta.2"
|
|
28
29
|
};
|
package/dist/locale/en-US.json
CHANGED
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"Show": "Show",
|
|
29
29
|
"Sign up settings": "Sign up settings",
|
|
30
30
|
"Sign up form": "Sign up form",
|
|
31
|
-
"At least one
|
|
31
|
+
"At least one of the username or email fields is required": "At least one of the username or email fields is required"
|
|
32
32
|
}
|
package/dist/locale/zh-CN.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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":"2024-
|
|
1
|
+
{"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":"2024-12-06T08:56:48.230Z"}
|
|
@@ -59,14 +59,14 @@ var authenticators_default = {
|
|
|
59
59
|
sort: "sort"
|
|
60
60
|
});
|
|
61
61
|
ctx.body = authenticators.map((authenticator) => {
|
|
62
|
-
var _a;
|
|
62
|
+
var _a, _b;
|
|
63
63
|
const authType = authManager.getAuthConfig(authenticator.authType);
|
|
64
64
|
return {
|
|
65
65
|
name: authenticator.name,
|
|
66
66
|
authType: authenticator.authType,
|
|
67
67
|
authTypeTitle: (authType == null ? void 0 : authType.title) || "",
|
|
68
68
|
title: authenticator.title,
|
|
69
|
-
options: ((_a = authenticator.options) == null ? void 0 :
|
|
69
|
+
options: ((_a = authType == null ? void 0 : authType.getPublicOptions) == null ? void 0 : _a.call(authType, authenticator.options)) || ((_b = authenticator.options) == null ? void 0 : _b.public) || {}
|
|
70
70
|
};
|
|
71
71
|
});
|
|
72
72
|
await next();
|
|
@@ -10,6 +10,7 @@ import { AuthConfig, BaseAuth } from '@nocobase/auth';
|
|
|
10
10
|
export declare class BasicAuth extends BaseAuth {
|
|
11
11
|
constructor(config: AuthConfig);
|
|
12
12
|
validate(): Promise<any>;
|
|
13
|
+
private getSignupFormSettings;
|
|
13
14
|
private verfiySignupParams;
|
|
14
15
|
signUp(): Promise<any>;
|
|
15
16
|
lostPassword(): Promise<any>;
|
|
@@ -42,6 +42,7 @@ module.exports = __toCommonJS(basic_auth_exports);
|
|
|
42
42
|
var import_auth = require("@nocobase/auth");
|
|
43
43
|
var import_crypto = __toESM(require("crypto"));
|
|
44
44
|
var import_preset = require("../preset");
|
|
45
|
+
var import_lodash = __toESM(require("lodash"));
|
|
45
46
|
class BasicAuth extends import_auth.BaseAuth {
|
|
46
47
|
constructor(config) {
|
|
47
48
|
const userCollection = config.ctx.db.getCollection("users");
|
|
@@ -75,21 +76,27 @@ class BasicAuth extends import_auth.BaseAuth {
|
|
|
75
76
|
}
|
|
76
77
|
return user;
|
|
77
78
|
}
|
|
78
|
-
|
|
79
|
+
getSignupFormSettings() {
|
|
79
80
|
var _a;
|
|
80
81
|
const options = ((_a = this.authenticator.options) == null ? void 0 : _a.public) || {};
|
|
81
|
-
let { signupForm } = options;
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
let { signupForm = [] } = options;
|
|
83
|
+
signupForm = signupForm.filter((item) => item.show);
|
|
84
|
+
if (!(signupForm.length && signupForm.some(
|
|
85
|
+
(item) => ["username", "email"].includes(item.field) && item.show && item.required
|
|
86
|
+
))) {
|
|
87
|
+
signupForm.push({ field: "username", show: true, required: true });
|
|
84
88
|
}
|
|
89
|
+
return signupForm;
|
|
90
|
+
}
|
|
91
|
+
verfiySignupParams(signupFormSettings, values) {
|
|
85
92
|
const { username, email } = values;
|
|
86
|
-
const usernameSetting =
|
|
93
|
+
const usernameSetting = signupFormSettings.find((item) => item.field === "username");
|
|
87
94
|
if (usernameSetting && usernameSetting.show) {
|
|
88
95
|
if (username && !this.validateUsername(username) || usernameSetting.required && !username) {
|
|
89
96
|
throw new Error("Please enter a valid username");
|
|
90
97
|
}
|
|
91
98
|
}
|
|
92
|
-
const emailSetting =
|
|
99
|
+
const emailSetting = signupFormSettings.find((item) => item.field === "email");
|
|
93
100
|
if (emailSetting && emailSetting.show) {
|
|
94
101
|
if (email && !/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(email)) {
|
|
95
102
|
throw new Error("Please enter a valid email address");
|
|
@@ -98,6 +105,12 @@ class BasicAuth extends import_auth.BaseAuth {
|
|
|
98
105
|
throw new Error("Please enter a valid email address");
|
|
99
106
|
}
|
|
100
107
|
}
|
|
108
|
+
const requiredFields = signupFormSettings.filter((item) => item.show && item.required);
|
|
109
|
+
requiredFields.forEach((item) => {
|
|
110
|
+
if (!values[item.field]) {
|
|
111
|
+
throw new Error(`Please enter ${item.field}`);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
101
114
|
}
|
|
102
115
|
async signUp() {
|
|
103
116
|
var _a;
|
|
@@ -108,9 +121,10 @@ class BasicAuth extends import_auth.BaseAuth {
|
|
|
108
121
|
}
|
|
109
122
|
const User = ctx.db.getRepository("users");
|
|
110
123
|
const { values } = ctx.action.params;
|
|
111
|
-
const {
|
|
124
|
+
const { password, confirm_password } = values;
|
|
125
|
+
const signupFormSettings = this.getSignupFormSettings();
|
|
112
126
|
try {
|
|
113
|
-
this.verfiySignupParams(values);
|
|
127
|
+
this.verfiySignupParams(signupFormSettings, values);
|
|
114
128
|
} catch (error) {
|
|
115
129
|
ctx.throw(400, this.ctx.t(error.message, { ns: import_preset.namespace }));
|
|
116
130
|
}
|
|
@@ -120,7 +134,9 @@ class BasicAuth extends import_auth.BaseAuth {
|
|
|
120
134
|
if (password !== confirm_password) {
|
|
121
135
|
ctx.throw(400, ctx.t("The password is inconsistent, please re-enter", { ns: import_preset.namespace }));
|
|
122
136
|
}
|
|
123
|
-
const
|
|
137
|
+
const fields = signupFormSettings.map((item) => item.field);
|
|
138
|
+
const userValues = import_lodash.default.pick(values, fields);
|
|
139
|
+
const user = await User.create({ values: { ...userValues, password } });
|
|
124
140
|
return user;
|
|
125
141
|
}
|
|
126
142
|
/* istanbul ignore next -- @preserve */
|
package/dist/server/plugin.js
CHANGED
|
@@ -72,16 +72,42 @@ class PluginAuthServer extends import_server.Plugin {
|
|
|
72
72
|
}
|
|
73
73
|
this.app.authManager.registerTypes(import_preset.presetAuthType, {
|
|
74
74
|
auth: import_basic_auth.BasicAuth,
|
|
75
|
-
title: (0, import_utils.tval)("Password", { ns: import_preset.namespace })
|
|
75
|
+
title: (0, import_utils.tval)("Password", { ns: import_preset.namespace }),
|
|
76
|
+
getPublicOptions: (options) => {
|
|
77
|
+
var _a;
|
|
78
|
+
const usersCollection = this.db.getCollection("users");
|
|
79
|
+
let signupForm = ((_a = options == null ? void 0 : options.public) == null ? void 0 : _a.signupForm) || [];
|
|
80
|
+
signupForm = signupForm.filter((item) => item.show);
|
|
81
|
+
if (!(signupForm.length && signupForm.some(
|
|
82
|
+
(item) => ["username", "email"].includes(item.field) && item.show && item.required
|
|
83
|
+
))) {
|
|
84
|
+
signupForm.unshift({ field: "username", show: true, required: true });
|
|
85
|
+
}
|
|
86
|
+
signupForm = signupForm.filter((field) => field.show).map((item) => {
|
|
87
|
+
var _a2;
|
|
88
|
+
const field = usersCollection.getField(item.field);
|
|
89
|
+
return {
|
|
90
|
+
...item,
|
|
91
|
+
uiSchema: {
|
|
92
|
+
...(_a2 = field.options) == null ? void 0 : _a2.uiSchema,
|
|
93
|
+
required: item.required
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
...options == null ? void 0 : options.public,
|
|
99
|
+
signupForm
|
|
100
|
+
};
|
|
101
|
+
}
|
|
76
102
|
});
|
|
77
103
|
Object.entries(import_auth.default).forEach(
|
|
78
104
|
([action, handler]) => {
|
|
79
105
|
var _a;
|
|
80
|
-
return (_a = this.app.
|
|
106
|
+
return (_a = this.app.resourceManager.getResource("auth")) == null ? void 0 : _a.addAction(action, handler);
|
|
81
107
|
}
|
|
82
108
|
);
|
|
83
109
|
Object.entries(import_authenticators.default).forEach(
|
|
84
|
-
([action, handler]) => this.app.
|
|
110
|
+
([action, handler]) => this.app.resourceManager.registerActionHandler(`authenticators:${action}`, handler)
|
|
85
111
|
);
|
|
86
112
|
["check", "signIn", "signUp"].forEach((action) => this.app.acl.allow("auth", action));
|
|
87
113
|
["signOut", "changePassword"].forEach((action) => this.app.acl.allow("auth", action, "loggedIn"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-auth",
|
|
3
|
-
"version": "1.5.0-
|
|
3
|
+
"version": "1.5.0-beta.2",
|
|
4
4
|
"main": "./dist/server/index.js",
|
|
5
5
|
"homepage": "https://docs.nocobase.com/handbook/auth",
|
|
6
6
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/auth",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"displayName.zh-CN": "用户认证",
|
|
27
27
|
"description": "User authentication management, including password, SMS, and support for Single Sign-On (SSO) protocols, with extensibility.",
|
|
28
28
|
"description.zh-CN": "用户认证管理,包括基础的密码认证、短信认证、SSO 协议的认证等,可扩展。",
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "8a9c29fdac5c6295dcc7abf00c3fa81bd9e01a36",
|
|
30
30
|
"keywords": [
|
|
31
31
|
"Authentication"
|
|
32
32
|
]
|