Files
NianAIGC/out/_next/static/chunks/app/auth/login/page-4dd3b2b5ad75ce4d.js
T
2026-09-02 17:02:02 +08:00

1 line
8.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(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)(window.location,u||"/create");c.replace("/auth/login?next=".concat(encodeURIComponent(e)))}},[d,u,c]),"loading"===i.status||d)?(0,r.jsx)(h,{message:"正在确认登录状态…"}):"error"===i.status?(0,r.jsx)(h,{message:i.error||"无法读取认证状态",actionLabel:"重试",onAction:()=>void i.refresh()}):("admin"!==a||i.isAdmin)&&("super"!==a||i.isSuperAdmin)?(0,r.jsx)(r.Fragment,{children:t}):(0,r.jsx)(h,{message:"当前账号无权访问此页面。"})}function d(e){let{to:t,forwardNext:a=!1}=e;return(0,n.useEffect)(()=>{let e=a?new URLSearchParams(window.location.search).get("next"):null,r=e?"".concat(t,"?next=").concat(encodeURIComponent(e)):t;window.location.replace(r)},[a,t]),(0,r.jsx)(h,{message:"正在跳转…"})}function h(e){let{message:t,actionLabel:a,onAction:n}=e;return(0,r.jsxs)("section",{className:"panel",children:[(0,r.jsx)("p",{className:"muted",children:t}),a&&n?(0,r.jsx)("button",{className:"button",type:"button",onClick:n,children:a}):null]})}},6660:(e,t,a)=>{"use strict";async function r(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 a,r=await t.json();if(!o(r)||"boolean"!=typeof r.authenticated||"boolean"!=typeof r.authRequired||"boolean"!=typeof r.authConfigured)throw Error("认证状态响应格式无效");if(!r.authenticated){if(null!==r.authMode||null!==r.user)throw Error("认证状态响应格式无效");return{authenticated:!1,authRequired:r.authRequired,authConfigured:r.authConfigured,authMode:null,user:null}}if(!r.authConfigured||"user"!==r.authMode&&"admin"!==r.authMode||!(o(a=r.user)&&"string"==typeof a.id&&a.id.length>0&&"string"==typeof a.subject&&a.subject===a.id&&"string"==typeof a.displayName&&"string"==typeof a.clientId&&("user"===a.role||"organization_admin"===a.role||"super_admin"===a.role)&&"active"===a.status&&("super_admin"===a.role||"string"==typeof a.organizationId&&a.organizationId.length>0)&&Array.isArray(a.authorities)&&a.authorities.every(e=>"string"==typeof e)&&Array.isArray(a.scope)&&a.scope.every(e=>"string"==typeof e)))throw Error("认证用户响应格式无效");let n="user"===r.user.role?"user":"admin";if(r.authMode!==n)throw Error("认证用户响应格式无效");return{authenticated:!0,authRequired:r.authRequired,authConfigured:r.authConfigured,authMode:r.authMode,user:r.user}}function n(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 a="http://zhinian.local",r=new URL(e,a);if(r.origin!==a)return t;let n="".concat(r.pathname).concat(r.search).concat(r.hash);if(r.pathname.startsWith("/api/auth")||r.pathname.startsWith("/auth/login")||r.pathname.startsWith("/auth/admin-login"))return t;return n}catch(e){return t}}function s(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/create";return n("".concat(e.pathname).concat(e.search).concat(e.hash),t)}function o(e){return"object"==typeof e&&null!==e}a.d(t,{M6:()=>s,uK:()=>r,z3:()=>n})},7612:(e,t,a)=>{"use strict";a.d(t,{It:()=>o,Js:()=>l,c8:()=>u,xr:()=>i});var r=a(7605);let n="power2.out";function s(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function o(e,t){let a=e.current;if(!a||s())return;let n=r.os.context(()=>t(a),a);return()=>n.revert()}function i(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"[data-animate]";if(s())return;let a=r.os.utils.toArray(t,e);a.length&&r.os.fromTo(a,{autoAlpha:0,y:14},{autoAlpha:1,y:0,duration:.28,ease:n,stagger:.045,clearProps:"transform,opacity,visibility"})}function u(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;!e||s()||r.os.fromTo(e,{autoAlpha:0,y:t},{autoAlpha:1,y:0,duration:.28,ease:n,clearProps:"transform,opacity,visibility"})}function l(e){!e||s()||r.os.fromTo(e,{scale:.985},{scale:1,duration:.22,ease:n,clearProps:"transform"})}}},e=>{e.O(0,[592,274,271,441,255,358],()=>e(e.s=820)),_N_E=e.O()}]);