8 lines
13 KiB
JavaScript
8 lines
13 KiB
JavaScript
import{r as f,j as e,i as _}from"./router-zNjPR4CY.js";import{u as $,a as H,p as U,c as L,C as I,b as q,d as z,e as O,f as Y,L as Q,I as V,g as G,B as K,D as X,h as Z,i as J,j as ee,k as se,l as te,A as re,m as ae,n as ne,o as oe,q as ie,r as le,s as ce,t as de,v as he,w as ue}from"./index-CuOHsLf7.js";import{u as me}from"./use-animation--6lc2CfN.js";import{K as xe,O as fe,U as R,V as ge,W,Y as pe,Z as ye,F as ve,_ as P}from"./icons-DTcdLw9j.js";import"./misc-BwRzHX8c.js";import"./radix-C-ZuImoP.js";import"./utils-DjBw3JGv.js";const we=Date.now()%1e6;class je{grad3;p;perm;constructor(i=0){this.grad3=[[1,1,0],[-1,1,0],[1,-1,0],[-1,-1,0],[1,0,1],[-1,0,1],[1,0,-1],[-1,0,-1],[0,1,1],[0,-1,1],[0,1,-1],[0,-1,-1]],this.p=[];for(let r=0;r<256;r++)this.p[r]=Math.floor(Math.random()*256);this.perm=[];for(let r=0;r<512;r++)this.perm[r]=this.p[r&255]}dot(i,r,g){return i[0]*r+i[1]*g}mix(i,r,g){return(1-g)*i+g*r}fade(i){return i*i*i*(i*(i*6-15)+10)}perlin2(i,r){const g=Math.floor(i)&255,v=Math.floor(r)&255;i-=Math.floor(i),r-=Math.floor(r);const p=this.fade(i),b=this.fade(r),h=this.perm[g]+v,w=this.perm[h],t=this.perm[h+1],N=this.perm[g+1]+v,A=this.perm[N],M=this.perm[N+1];return this.mix(this.mix(this.dot(this.grad3[w%12],i,r),this.dot(this.grad3[A%12],i-1,r),p),this.mix(this.dot(this.grad3[t%12],i,r-1),this.dot(this.grad3[M%12],i-1,r-1),p),b)}}function F(){const T=f.useRef(null),i=f.useRef(null),r=f.useRef(void 0),[g]=f.useState(()=>new je(we)),v=f.useRef({mouse:{x:-10,y:0,lx:0,ly:0,sx:0,sy:0,v:0,vs:0,a:0,set:!1},lines:[],paths:[],noise:g,bounding:null});return f.useEffect(()=>{const p=i.current,b=T.current;if(!p||!b)return;const h=v.current;h.noise=g;const w=()=>{const o=p.getBoundingClientRect();h.bounding=o,b.style.width=`${o.width}px`,b.style.height=`${o.height}px`},t=()=>{if(!h.bounding)return;const{width:o,height:s}=h.bounding;h.lines=[],h.paths.forEach(d=>d.remove()),h.paths=[];const n=10,y=32,m=o+200,a=s+30,l=Math.ceil(m/n),u=Math.ceil(a/y),c=(o-n*l)/2,x=(s-y*u)/2;for(let d=0;d<=l;d++){const j=[];for(let S=0;S<=u;S++){const B={x:c+n*d,y:x+y*S,wave:{x:0,y:0},cursor:{x:0,y:0,vx:0,vy:0}};j.push(B)}const k=document.createElementNS("http://www.w3.org/2000/svg","path");b.appendChild(k),h.paths.push(k),h.lines.push(j)}},N=o=>{const{lines:s,mouse:n,noise:y}=h;s.forEach(m=>{m.forEach(a=>{const l=y.perlin2((a.x+o*.0125)*.002,(a.y+o*.005)*.0015)*12;a.wave.x=Math.cos(l)*32,a.wave.y=Math.sin(l)*16;const u=a.x-n.sx,c=a.y-n.sy,x=Math.hypot(u,c),d=Math.max(175,n.vs);if(x<d){const j=1-x/d,k=Math.cos(x*.001)*j;a.cursor.vx+=Math.cos(n.a)*k*d*n.vs*65e-5,a.cursor.vy+=Math.sin(n.a)*k*d*n.vs*65e-5}a.cursor.vx+=(0-a.cursor.x)*.005,a.cursor.vy+=(0-a.cursor.y)*.005,a.cursor.vx*=.925,a.cursor.vy*=.925,a.cursor.x+=a.cursor.vx*2,a.cursor.y+=a.cursor.vy*2,a.cursor.x=Math.min(100,Math.max(-100,a.cursor.x)),a.cursor.y=Math.min(100,Math.max(-100,a.cursor.y))})})},A=(o,s=!0)=>{const n={x:o.x+o.wave.x+(s?o.cursor.x:0),y:o.y+o.wave.y+(s?o.cursor.y:0)};return n.x=Math.round(n.x*10)/10,n.y=Math.round(n.y*10)/10,n},M=()=>{const{lines:o,paths:s}=h;o.forEach((n,y)=>{let m=A(n[0],!1),a=`M ${m.x} ${m.y}`;n.forEach((l,u)=>{const c=u===n.length-1;m=A(l,!c),a+=`L ${m.x} ${m.y}`}),s[y].setAttribute("d",a)})},E=o=>{const{mouse:s}=h;s.sx+=(s.x-s.sx)*.1,s.sy+=(s.y-s.sy)*.1;const n=s.x-s.lx,y=s.y-s.ly,m=Math.hypot(n,y);s.v=m,s.vs+=(m-s.vs)*.1,s.vs=Math.min(100,s.vs),s.lx=s.x,s.ly=s.y,s.a=Math.atan2(y,n),p&&(p.style.setProperty("--x",`${s.sx}px`),p.style.setProperty("--y",`${s.sy}px`)),N(o),M(),r.current=requestAnimationFrame(E)},D=o=>{if(!h.bounding)return;const{mouse:s}=h;s.x=o.pageX-h.bounding.left,s.y=o.pageY-h.bounding.top+window.scrollY,s.set||(s.sx=s.x,s.sy=s.y,s.lx=s.x,s.ly=s.y,s.set=!0)},C=()=>{w(),t()};return w(),t(),window.addEventListener("resize",C),window.addEventListener("mousemove",D),r.current=requestAnimationFrame(E),()=>{window.removeEventListener("resize",C),window.removeEventListener("mousemove",D),r.current&&cancelAnimationFrame(r.current)}},[g]),e.jsxs("div",{ref:i,className:"waves-background",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",overflow:"hidden",pointerEvents:"none"},children:[e.jsx("div",{className:"waves-cursor",style:{position:"absolute",top:0,left:0,width:"0.5rem",height:"0.5rem",background:"hsl(var(--color-primary) / 0.3)",borderRadius:"50%",transform:"translate3d(calc(var(--x, -0.5rem) - 50%), calc(var(--y, 50%) - 50%), 0)",willChange:"transform",pointerEvents:"none"}}),e.jsx("svg",{ref:T,style:{display:"block",width:"100%",height:"100%"},children:e.jsx("style",{children:`
|
|
path {
|
|
fill: none;
|
|
stroke: hsl(var(--color-primary) / 0.20);
|
|
stroke-width: 1px;
|
|
}
|
|
`})})]})}function Ce(){const[T,i]=f.useState(""),[r,g]=f.useState(!1),[v,p]=f.useState(""),[b,h]=f.useState(!0),w=_(),{t}=$(),{enableWavesBackground:N,setEnableWavesBackground:A}=me(),{theme:M,setTheme:E}=H(),D=f.useRef(!1),C=f.useCallback(()=>{if(typeof window>"u")return"";const l=new URLSearchParams(window.location.search).get("token");if(l&&l.trim())return l.trim();const u=window.location.hash.replace(/^#/,"");if(!u)return"";const c=u.indexOf("?"),x=c>=0?u.slice(c+1):u,d=new URLSearchParams(x).get("token");return d&&d.trim()?d.trim():""},[]),o=f.useCallback(()=>{if(!(typeof window>"u"))try{const l=new URL(window.location.href);let u=!1;l.searchParams.has("token")&&(l.searchParams.delete("token"),u=!0);const c=l.hash.replace(/^#/,"");if(c){const x=c.indexOf("?");if(x>=0){const d=c.slice(0,x),j=new URLSearchParams(c.slice(x+1));if(j.has("token")){j.delete("token");const k=j.toString();l.hash=k?`#${d}?${k}`:`#${d}`,u=!0}}else/^token=/.test(c)&&(l.hash="",u=!0)}u&&window.history.replaceState(null,"",l.toString())}catch{}},[]),n=M==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":M,y=()=>{E(n==="dark"?"light":"dark")},m=f.useCallback(async l=>{const u=l.trim();if(p(""),!u)return p(t("auth.tokenRequired")),!1;g(!0),console.log("开始验证 token...");try{const c=await fetch("/api/webui/auth/verify",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({token:u})});console.log("Token 验证响应状态:",c.status);const x=await U(c);if(!x.success)return console.error("Token 验证失败:",x.error),p(x.error),!1;const d=x.data;if(console.log("Token 验证响应数据:",d),d.valid){console.log("Token 验证成功,准备跳转..."),console.log("is_first_setup:",d.is_first_setup),await new Promise(k=>setTimeout(k,100));const j=await L();return console.log("跳转前认证状态检查:",j),d.is_first_setup?(console.log("跳转到首次配置页面"),w({to:"/setup"})):(console.log("跳转到首页"),w({to:"/"})),!0}return console.error("Token 验证失败:",d.message),p(d.message||t("auth.verifyFailed")),!1}catch(c){return console.error("Token 验证错误:",c),p(c instanceof Error?c.message:t("auth.connFailed")),!1}finally{g(!1)}},[w,t]),a=async l=>{l.preventDefault(),await m(T)};return f.useEffect(()=>{(async()=>{try{if(await L()){o(),w({to:"/"});return}const c=C();c&&!D.current&&(D.current=!0,o(),i(c),m(c))}catch{}finally{h(!1)}})()},[w,C,o,m]),b?e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background p-4",children:[N&&e.jsx(F,{}),e.jsx("div",{className:"text-muted-foreground",children:t("auth.checkingAuth")})]}):e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-background p-4",children:[N&&e.jsx(F,{}),e.jsxs(I,{className:"relative z-10 w-full max-w-md shadow-2xl backdrop-blur-xl bg-card/80 border-border/50",children:[e.jsx("button",{onClick:y,className:"absolute right-4 top-4 rounded-lg p-2 hover:bg-accent transition-colors z-10 text-foreground",title:t(n==="dark"?"auth.switchToLight":"auth.switchToDark"),children:n==="dark"?e.jsx(xe,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"}):e.jsx(fe,{className:"h-5 w-5",strokeWidth:2.5,fill:"none"})}),e.jsxs(q,{className:"space-y-4 text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-2xl bg-primary/10",children:e.jsx(R,{className:"h-8 w-8 text-primary",strokeWidth:2,fill:"none"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{className:"text-2xl font-bold",children:t("auth.welcome")}),e.jsx(O,{className:"text-base",children:t("auth.accessDesc")})]})]}),e.jsx(Y,{children:e.jsxs("form",{onSubmit:a,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{htmlFor:"token",className:"text-sm font-medium",children:"Access Token"}),e.jsxs("div",{className:"relative",children:[e.jsx(ge,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground",strokeWidth:2,fill:"none"}),e.jsx(V,{id:"token",type:"password",placeholder:t("auth.tokenPlaceholder"),value:T,onChange:l=>i(l.target.value),className:G("pl-10",v&&"border-red-500 focus-visible:ring-red-500"),disabled:r,autoFocus:!0,autoComplete:"off","aria-invalid":v?!0:void 0,"aria-describedby":v?"token-error":void 0})]})]}),v&&e.jsxs("div",{id:"token-error",role:"alert",className:"flex items-center gap-2 rounded-md bg-red-50 p-3 text-sm text-red-600 dark:bg-red-950/50 dark:text-red-400",children:[e.jsx(W,{className:"h-4 w-4 flex-shrink-0",strokeWidth:2,fill:"none"}),e.jsx("span",{children:v})]}),e.jsx(K,{type:"submit",className:"w-full",disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),t("auth.verifyingLabel")]}):t("auth.verifyEnter")}),e.jsxs(X,{children:[e.jsx(Z,{asChild:!0,children:e.jsxs("button",{className:"w-full text-center text-sm text-primary hover:text-primary/80 transition-colors underline-offset-4 hover:underline flex items-center justify-center gap-1",children:[e.jsx(pe,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),t("auth.helpLink")]})}),e.jsxs(J,{className:"sm:max-w-md",children:[e.jsxs(ee,{children:[e.jsxs(se,{className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),t("auth.helpTitle")]}),e.jsx(te,{children:t("auth.helpDesc")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4 space-y-2",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ye,{className:"h-5 w-5 text-primary flex-shrink-0 mt-0.5",strokeWidth:2,fill:"none"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("h4",{className:"font-semibold text-sm",children:t("auth.method1Title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("auth.method1Desc")}),e.jsxs("div",{className:"rounded bg-background p-2 font-mono text-xs",children:[e.jsx("p",{className:"text-muted-foreground",children:t("auth.method1Example1")}),e.jsx("p",{className:"text-muted-foreground",children:t("auth.method1Example2")})]})]})]})}),e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4 space-y-2",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ve,{className:"h-5 w-5 text-primary flex-shrink-0 mt-0.5",strokeWidth:2,fill:"none"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("h4",{className:"font-semibold text-sm",children:t("auth.method2Title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("auth.method2Desc")}),e.jsx("div",{className:"rounded bg-background p-2 font-mono text-xs break-all",children:e.jsx("code",{className:"text-primary",children:"data/webui.json"})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t("auth.method2FileHint")," ",e.jsx("code",{className:"px-1 py-0.5 bg-background rounded",children:"access_token"})]})]})]})}),e.jsx("div",{className:"rounded-lg border border-yellow-200 dark:border-yellow-900 bg-yellow-50 dark:bg-yellow-950/30 p-3",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(W,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-500 flex-shrink-0 mt-0.5",strokeWidth:2,fill:"none"}),e.jsxs("div",{className:"text-sm text-yellow-800 dark:text-yellow-300 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:t("auth.securityTipTitle")}),e.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-xs",children:[e.jsx("li",{children:t("auth.securityTip1")}),e.jsx("li",{children:t("auth.securityTip2")})]})]})]})})]})]})]}),e.jsxs(re,{children:[e.jsx(ae,{asChild:!0,children:e.jsxs("button",{className:"w-full text-center text-sm text-muted-foreground hover:text-foreground transition-colors underline-offset-4 hover:underline flex items-center justify-center gap-1",children:[e.jsx(P,{className:"h-4 w-4",strokeWidth:2,fill:"none"}),t("auth.slowLink")]})}),e.jsxs(ne,{children:[e.jsxs(oe,{children:[e.jsxs(ie,{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-5 w-5 text-primary",strokeWidth:2,fill:"none"}),t("auth.disableAnimTitle")]}),e.jsx(le,{children:t("auth.disableAnimDesc")})]}),e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4 space-y-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:t("auth.disableAnimDetail")})}),e.jsxs(ce,{children:[e.jsx(de,{children:t("common.cancel")}),e.jsx(he,{onClick:()=>A(!1),children:t("auth.disableAnimBtn")})]})]})]})]})})]}),e.jsx("div",{className:"absolute bottom-4 left-0 right-0 text-center text-xs text-muted-foreground",children:e.jsx("p",{children:ue})})]})}export{Ce as AuthPage};
|