修复了2个bug
This commit is contained in:
1 parent
ce8372e878
commit
2a64dc7395
64 files changed
+1050
-39
No files matched your search
@@ -0,0 +1 @@
|
||||
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[321,335,830,974],{63:(e,t,r)=>{"use strict";var n=r(7260);r.o(n,"usePathname")&&r.d(t,{usePathname:function(){return n.usePathname}}),r.o(n,"useRouter")&&r.d(t,{useRouter:function(){return n.useRouter}})},4577:(e,t,r)=>{"use strict";r.d(t,{BrowserAuthGuard:()=>c,BrowserAuthProvider:()=>s,ClientRedirect:()=>h,a:()=>l});var n=r(5155),a=r(2115),u=r(63),o=r(6660);let i=(0,a.createContext)(null);function s(e){let{children:t}=e,[r,u]=(0,a.useState)(null),[s,l]=(0,a.useState)("loading"),[c,h]=(0,a.useState)(null),d=(0,a.useCallback)(async e=>{try{let t=await (0,o.uK)(e);u(t),l("ready"),h(null)}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;l("error"),h(e instanceof Error?e.message:"无法读取认证状态")}},[]);(0,a.useEffect)(()=>{let e=new AbortController;return d(e.signal),()=>e.abort()},[d]);let f=(0,a.useMemo)(()=>{var e,t;let n=(null==r?void 0:r.user)||null,a=null==(e=null==r?void 0:r.authRequired)||e,u=!a||(null==n?void 0:n.role)==="super_admin",o=u||(null==n?void 0:n.role)==="organization_admin";return{status:s,user:n,authMode:(null==r?void 0:r.authMode)||null,authRequired:a,authConfigured:null!=(t=null==r?void 0:r.authConfigured)&&t,isAdmin:o,isSuperAdmin:u,error:c,refresh:()=>d()}},[c,d,r,s]);return(0,n.jsx)(i.Provider,{value:f,children:t})}function l(){let e=(0,a.useContext)(i);if(!e)throw Error("useBrowserAuth must be used inside BrowserAuthProvider");return e}function c(e){let{children:t,role:r="user"}=e,i=l(),s=(0,u.usePathname)(),c=(0,u.useRouter)(),h="ready"===i.status&&i.authRequired&&!i.user;return((0,a.useEffect)(()=>{if(h){let e=(0,o.M6)(window.location,s||"/create");c.replace("/auth/login?next=".concat(encodeURIComponent(e)))}},[h,s,c]),"loading"===i.status||h)?(0,n.jsx)(d,{message:"正在确认登录状态…"}):"error"===i.status?(0,n.jsx)(d,{message:i.error||"无法读取认证状态",actionLabel:"重试",onAction:()=>void i.refresh()}):("admin"!==r||i.isAdmin)&&("super"!==r||i.isSuperAdmin)?(0,n.jsx)(n.Fragment,{children:t}):(0,n.jsx)(d,{message:"当前账号无权访问此页面。"})}function h(e){let{to:t,forwardNext:r=!1}=e;return(0,a.useEffect)(()=>{let e=r?new URLSearchParams(window.location.search).get("next"):null,n=e?"".concat(t,"?next=").concat(encodeURIComponent(e)):t;window.location.replace(n)},[r,t]),(0,n.jsx)(d,{message:"正在跳转…"})}function d(e){let{message:t,actionLabel:r,onAction:a}=e;return(0,n.jsxs)("section",{className:"panel",children:[(0,n.jsx)("p",{className:"muted",children:t}),r&&a?(0,n.jsx)("button",{className:"button",type:"button",onClick:a,children:r}):null]})}},6660:(e,t,r)=>{"use strict";async function n(e){let t=await fetch("/api/auth/me",{method:"GET",cache:"no-store",credentials:"same-origin",headers:{Accept:"application/json"},signal:e});if(!t.ok)throw Error("认证状态请求失败(".concat(t.status,")"));var r,n=await t.json();if(!o(n)||"boolean"!=typeof n.authenticated||"boolean"!=typeof n.authRequired||"boolean"!=typeof n.authConfigured)throw Error("认证状态响应格式无效");if(!n.authenticated){if(null!==n.authMode||null!==n.user)throw Error("认证状态响应格式无效");return{authenticated:!1,authRequired:n.authRequired,authConfigured:n.authConfigured,authMode:null,user:null}}if(!n.authConfigured||"user"!==n.authMode&&"admin"!==n.authMode||!(o(r=n.user)&&"string"==typeof r.id&&r.id.length>0&&"string"==typeof r.subject&&r.subject===r.id&&"string"==typeof r.displayName&&"string"==typeof r.clientId&&("user"===r.role||"organization_admin"===r.role||"super_admin"===r.role)&&"active"===r.status&&("super_admin"===r.role||"string"==typeof r.organizationId&&r.organizationId.length>0)&&Array.isArray(r.authorities)&&r.authorities.every(e=>"string"==typeof e)&&Array.isArray(r.scope)&&r.scope.every(e=>"string"==typeof e)))throw Error("认证用户响应格式无效");let a="user"===n.user.role?"user":"admin";if(n.authMode!==a)throw Error("认证用户响应格式无效");return{authenticated:!0,authRequired:n.authRequired,authConfigured:n.authConfigured,authMode:n.authMode,user:n.user}}function a(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/create";if(!e||!e.startsWith("/")||e.startsWith("//")||e.includes("\\"))return t;try{let r="http://zhinian.local",n=new URL(e,r);if(n.origin!==r)return t;let a="".concat(n.pathname).concat(n.search).concat(n.hash);if(n.pathname.startsWith("/api/auth")||n.pathname.startsWith("/auth/login")||n.pathname.startsWith("/auth/admin-login"))return t;return a}catch(e){return t}}function u(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/create";return a("".concat(e.pathname).concat(e.search).concat(e.hash),t)}function o(e){return"object"==typeof e&&null!==e}r.d(t,{M6:()=>u,uK:()=>n,z3:()=>a})},9656:(e,t,r)=>{Promise.resolve().then(r.bind(r,4577))}},e=>{e.O(0,[441,255,358],()=>e(e.s=9656)),_N_E=e.O()}]);
|
||||
@@ -0,0 +1 @@
|
||||
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[859],{820:(e,t,a)=>{Promise.resolve().then(a.bind(a,2985))},2985:(e,t,a)=>{"use strict";a.d(t,{AuthLoginPanel:()=>d});var r=a(5155),n=a(2115),s=a(5239),o=a(5299),i=a(9865),u=a(7612),l=a(4577),c=a(6660);function d(e){let{title:t="账户登录",submitLabel:a="登录"}=e,d=(0,l.a)(),[p,m]=(0,n.useState)(""),[g,y]=(0,n.useState)(""),[w,v]=(0,n.useState)(!1),[x,j]=(0,n.useState)(null),[b,C]=(0,n.useState)("/create"),[A,E]=(0,n.useState)(null),N=(0,n.useRef)(null),R=(0,n.useRef)(null),S="ready"===d.status&&d.authConfigured,M="ready"===d.status&&d.authRequired&&!d.authConfigured;async function _(e){if(e.preventDefault(),!S||w)return;let t=new FormData(e.currentTarget),a=h(t.get("phone")),r=h(t.get("password"));if(!a||!r)return void j("手机号和密码不能为空。");v(!0),j(null);try{let e=await fetch("/api/auth/password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({phone:a,password:r,next:b})}),t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error||"登录失败");window.location.assign((0,c.z3)(t.redirectTo,b))}catch(e){j(e instanceof Error?e.message:String(e))}finally{v(!1)}}return(0,n.useEffect)(()=>(0,u.It)(N,e=>(0,u.xr)(e)),[]),(0,n.useEffect)(()=>{let e=new URLSearchParams(window.location.search);C((0,c.z3)(e.get("next")));let t=e.get("error");t?E(f[t]||"登录失败,请重新登录。"):"1"===e.get("loggedOut")&&E("已退出登录。")},[]),(0,n.useEffect)(()=>{"ready"===d.status&&d.user&&window.location.replace(b)},[d.status,d.user,b]),(0,n.useEffect)(()=>{(0,u.Js)(R.current)},[x,A,M]),(0,r.jsxs)("div",{className:"auth-page",ref:N,children:[(0,r.jsxs)("section",{className:"auth-brand-panel","aria-label":"智念AIGC平台","data-animate":!0,children:[(0,r.jsx)(s.default,{className:"auth-brand-logo",src:"/logo/zhinian-logo.png",alt:"",width:168,height:38,priority:!0}),(0,r.jsx)("h1",{children:"智念AIGC平台"})]}),(0,r.jsxs)("section",{className:"panel auth-panel","data-animate":!0,children:[(0,r.jsx)("h2",{children:t}),A||M||"error"===d.status||x?(0,r.jsxs)("div",{ref:R,children:[A?(0,r.jsx)("div",{className:"callout",role:"alert",children:A}):null,M?(0,r.jsx)("div",{className:"callout",role:"alert",children:"账号认证配置不完整,请联系管理员。"}):null,"error"===d.status?(0,r.jsx)("div",{className:"callout",role:"alert",children:d.error||"无法读取认证状态。"}):null,x?(0,r.jsx)("div",{className:"callout",role:"alert",children:x}):null]}):null,(0,r.jsxs)("form",{className:"auth-password-form",onSubmit:_,children:[(0,r.jsxs)("label",{className:"field","data-animate":!0,children:[(0,r.jsx)("span",{children:"手机号"}),(0,r.jsx)("input",{autoComplete:"username",inputMode:"tel",name:"phone",required:!0,value:p,onChange:e=>m(e.target.value),disabled:!S||w,placeholder:"请输入手机号"})]}),(0,r.jsxs)("label",{className:"field","data-animate":!0,children:[(0,r.jsx)("span",{children:"密码"}),(0,r.jsx)("input",{autoComplete:"current-password",name:"password",required:!0,type:"password",value:g,onChange:e=>y(e.target.value),disabled:!S||w,placeholder:"请输入密码"})]}),(0,r.jsxs)("button",{className:"button primary auth-submit",type:"submit",disabled:!S||w,"data-animate":!0,children:[w?(0,r.jsx)(o.A,{className:"spin",size:18}):(0,r.jsx)(i.A,{size:18}),a]})]})]})]})}function h(e){return"string"==typeof e?e.trim():""}let f={auth_not_configured:"账号认证配置不完整,请联系管理员。",callback_failed:"登录失败,请重新登录。",state_invalid:"登录状态已失效,请重新登录。"}},4577:(e,t,a)=>{"use strict";a.d(t,{BrowserAuthGuard:()=>c,BrowserAuthProvider:()=>u,ClientRedirect:()=>d,a:()=>l});var r=a(5155),n=a(2115),s=a(63),o=a(6660);let i=(0,n.createContext)(null);function u(e){let{children:t}=e,[a,s]=(0,n.useState)(null),[u,l]=(0,n.useState)("loading"),[c,d]=(0,n.useState)(null),h=(0,n.useCallback)(async e=>{try{let t=await (0,o.uK)(e);s(t),l("ready"),d(null)}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;l("error"),d(e instanceof Error?e.message:"无法读取认证状态")}},[]);(0,n.useEffect)(()=>{let e=new AbortController;return h(e.signal),()=>e.abort()},[h]);let f=(0,n.useMemo)(()=>{var e,t;let r=(null==a?void 0:a.user)||null,n=null==(e=null==a?void 0:a.authRequired)||e,s=!n||(null==r?void 0:r.role)==="super_admin",o=s||(null==r?void 0:r.role)==="organization_admin";return{status:u,user:r,authMode:(null==a?void 0:a.authMode)||null,authRequired:n,authConfigured:null!=(t=null==a?void 0:a.authConfigured)&&t,isAdmin:o,isSuperAdmin:s,error:c,refresh:()=>h()}},[c,h,a,u]);return(0,r.jsx)(i.Provider,{value:f,children:t})}function l(){let e=(0,n.useContext)(i);if(!e)throw Error("useBrowserAuth must be used inside BrowserAuthProvider");return e}function c(e){let{children:t,role:a="user"}=e,i=l(),u=(0,s.usePathname)(),c=(0,s.useRouter)(),d="ready"===i.status&&i.authRequired&&!i.user;return((0,n.useEffect)(()=>{if(d){let e=(0,o.M6)(Line truncated
|
||||
Reference in new issue
Block a user