2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
import{d as se,y as ae,z as le,A as ne,o as re,B as I,c as i,a as e,f as ie,h as ue,C as ce,D as n,E as s,n as de,G,F as j,g as L,H as T,I as B,J as R,r as u,j as X,k as pe,K as W,L as H,M as U,x as ve,u as he,s as K,q as c,t as ge}from"./index-DnbYEqLr.js";import{u as me}from"./loginTransition-Bm4PAghQ.js";const we={class:"min-h-screen flex items-center justify-center p-4 relative z-10 login-fly-perspective"},fe={class:"w-full max-w-md relative z-20"},be={class:"absolute -top-10 left-1/2 -translate-x-1/2 z-10"},ye={class:"logo-gradient-border w-20 h-20"},xe={class:"text-2xl font-semibold text-white/96 text-center mb-8 drop-shadow-[0_2px_6px_rgba(0,0,0,0.4)]"},_e={key:0},ke={key:1},Se={key:0,class:"mb-6",role:"status","aria-live":"polite"},Ce={class:"flex items-center justify-center gap-2 mb-3"},Ie={class:"text-sm text-white/60"},Le={class:"startup-progress-track"},Te={key:1,role:"alert",class:"mb-4 p-3 bg-red-500/20 border border-red-500/40 rounded-lg text-red-200 text-sm"},Be={class:"mb-4"},Pe={for:"setup-password",class:"block text-sm font-medium text-white/80 mb-2"},ze=["placeholder","disabled"],Ae={class:"mb-6"},Ve={for:"setup-confirm-password",class:"block text-sm font-medium text-white/80 mb-2"},Me=["placeholder","disabled"],Ee=["disabled"],je={key:0},Re={key:1,class:"flex items-center justify-center"},Xe={class:"mb-6 text-center"},He={class:"text-white/80 text-sm mb-1"},Ue={class:"text-white/50 text-xs"},Ke={class:"mb-4"},Ne=["aria-label","placeholder","disabled"],qe=["disabled"],Fe={key:0},Je={key:1,class:"flex items-center justify-center"},De={class:"mb-6"},Oe={for:"login-password",class:"block text-sm font-medium text-white/80 mb-2"},Ge=["placeholder","disabled"],We=["disabled"],$e={key:0},Qe={key:1,class:"flex items-center justify-center"},Ye={class:"mt-6 text-center text-sm text-white/40"},Ze={class:"mt-8 text-center flex items-center justify-center gap-4"},et=["disabled"],tt=se({__name:"Login",setup(ot){const{t:o}=ae(),k=ve(),$=he(),g=X(()=>$.query.redirect||"/dashboard"),P=le(),z=me(),r=u(""),f=u(""),l=u(!1),d=u(null),b=u(!1),m=u(!1),A=u(!1),v=u(""),y=u(!1),N=u(null),S=u(!1),q=u(!0),w=u(0);let V=null,x=null;const M=X(()=>!1),_=X(()=>!S.value);async function F(){try{const a=await fetch("/rpc/v1",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:"server.echo",params:{message:"ping"}}),signal:AbortSignal.timeout(5e3)});return a.status!==502&&a.status!==503}catch{return!1}}function Q(){return new Promise(a=>{x=setInterval(()=>{w.value<90&&(w.value+=Math.random()*8+2,w.value>90&&(w.value=90))},600);const t=async()=>{if(await F()){x&&clearInterval(x),w.value=100,await new Promise(oe=>setTimeout(oe,400)),S.value=!0,q.value=!1,a();return}V=setTimeout(t,2e3)};t()})}let h=null;function J(){h&&(document.removeEventListener("click",h),document.removeEventListener("touchstart",h),document.removeEventListener("keydown",h),h=null)}ne(()=>{J(),V&&clearTimeout(V),x&&clearInterval(x)}),re(async()=>{const a=sessionStorage.getItem("archipelago_from_splash")==="1";if(a&&sessionStorage.removeItem("archipelago_from_splash"),h=()=>{a||(pe(),K()),J()},document.addEventListener("click",h,{once:!0}),document.addEventListener("touchstart",h,{once:!0}),document.addEventListener("keydown",h,{once:!0}),await F()?(S.value=!0,q.value=!1):await Q(),M.value)try{const p=await I.call({method:"auth.isSetup",params:{},timeout:8e3});b.value=!!p}catch{b.value=!1}else b.value=!0});function E(){!l.value&&r.value&&r.value===f.value&&W(),Y()}async function Y(){if(!r.value||r.value.length<8){d.value=o("login.errorMinLength");return}if(r.value!==f.value){d.value=o("login.errorMismatch");return}l.value=!0,d.value=null;try{await I.call({method:"auth.setup",params:{password:r.value}}),H(),m.value=!0,U(),z.setJustLoggedIn(!0),await P.login(r.value),await new Promise(a=>setTimeout(a,520)),await k.replace(g.value).catch(()=>{window.location.href=g.value})}catch(a){m.value=!1;const t=a instanceof Error?a.message:"";/502|503|Bad Gateway|timeout|fetch|network/i.test(t)?d.value=o("login.errorServerStarting"):d.value=t||o("login.errorSetupFailed"),K()}finally{l.value=!1}}function D(){!l.value&&r.value&&W(),Z()}async function Z(){if(r.value){l.value=!0,d.value=null;try{if((await P.login(r.value))?.requires_totp){A.value=!0,l.value=!1,setTimeout(()=>N.value?.focus(),100);return}H(),m.value=!0,U(),z.setJustLoggedIn(!0),await new Promise(t=>setTimeout(t,520)),await k.replace(g.value).catch(()=>{window.location.href=g.value})}catch(a){m.value=!1;const t=a instanceof Error?a.message:"";/502|503|Bad Gateway|timeout|fetch|network/i.test(t)?d.value=o("login.errorServerStarting"):d.value=t||o("login.errorLoginFailed"),K()}finally{l.value=!1}}}async function O(){if(v.value){l.value=!0,d.value=null;try{y.value?await I.loginBackup(v.value):await I.loginTotp(v.value),await P.completeLoginAfterTotp(),H(),m.value=!0,U(),z.setJustLoggedIn(!0),await new Promise(a=>setTimeout(a,520)),await k.replace(g.value).catch(()=>{window.location.href=g.value})}catch(a){const t=a instanceof Error?a.message:"";/expired|too many/i.test(t)?(A.value=!1,v.value="",d.value=t):d.value=t||o("login.errorInvalidCode"),v.value=""}finally{l.value=!1}}}function ee(){localStorage.removeItem("neode_intro_seen"),window.location.href="/"}const C=u(!1);async function te(){C.value||(C.value=!0,localStorage.removeItem("neode_onboarding_complete"),localStorage.removeItem("neode_did"),localStorage.removeItem("neode_did_state"),localStorage.removeItem("neode_backup_created"),k.push("/onboarding/intro").then(()=>{window.location.reload()}).catch(()=>{window.location.href="/onboarding/intro"}))}return(a,t)=>(c(),i("div",we,[e("div",fe,[e("div",{class:ie(["glass-card p-8 pt-20 relative login-card overflow-visible",{"login-fly-towards":m.value}])},[e("div",be,[e("div",ye,[ue(ce,{"no-border":"",fit:""})])]),e("h1",xe,[M.value&&!b.value?(c(),i("span",_e,n(s(o)("login.setupTitle")),1)):(c(),i("span",ke,n(s(o)("login.title")),1))]),S.value?G("",!0):(c(),i("div",Se,[e("div",Ce,[t[5]||(t[5]=e("svg",{class:"animate-spin h-4 w-4 text-orange-400","aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})],-1)),e("span",Ie,n(s(o)("login.serverStarting")),1)]),e("div",Le,[e("div",{class:"startup-progress-bar",style:de({width:w.value+"%"})},null,4)])])),d.value?(c(),i("div",Te,n(d.value),1)):G("",!0),M.value&&!b.value?(c(),i(j,{key:2},[t[7]||(t[7]=e("div",{class:"mb-4 p-4 bg-white/5 border border-white/10 rounded-lg text-white/80 text-sm"},[e("p",{class:"mb-2"},"Create a password to secure your Archipelago node."),e("p",{class:"text-white/60 text-xs"},"This password will be required to access your node.")],-1)),e("div",Be,[e("label",Pe,n(s(o)("login.password")),1),L(e("input",{id:"setup-password","onUpdate:modelValue":t[0]||(t[0]=p=>r.value=p),type:"password",class:"w-full px-4 py-3 bg-transparent border border-white/20 rounded-lg text-white placeholder-white/40 focus:outline-none focus:border-white/40 focus:ring-1 focus:ring-white/20 transition-colors",placeholder:s(o)("login.enterPasswordSetup"),onKeyup:B(E,["enter"]),disabled:l.value||_.value},null,40,ze),[[T,r.value]])]),e("div",Ae,[e("label",Ve,n(s(o)("login.confirmPassword")),1),L(e("input",{id:"setup-confirm-password","onUpdate:modelValue":t[1]||(t[1]=p=>f.value=p),type:"password",class:"w-full px-4 py-3 bg-transparent border border-white/20 rounded-lg text-white placeholder-white/40 focus:outline-none focus:border-white/40 focus:ring-1 focus:ring-white/20 transition-colors",placeholder:s(o)("login.confirmPasswordPlaceholder"),onKeyup:B(E,["enter"]),disabled:l.value||_.value},null,40,Me),[[T,f.value]])]),e("button",{onClick:E,disabled:l.value||_.value||!r.value||r.value.length<8||r.value!==f.value,class:"w-full glass-button px-6 py-3 rounded-lg font-medium transition-all hover:bg-black/70 hover:border-white/30 disabled:opacity-50 disabled:cursor-not-allowed"},[l.value?(c(),i("span",Re,[t[6]||(t[6]=e("svg",{class:"animate-spin h-5 w-5 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})],-1)),R(" "+n(s(o)("login.settingUp")),1)])):(c(),i("span",je,n(s(o)("login.setupButton")),1))],8,Ee)],64)):A.value?(c(),i(j,{key:3},[e("div",Xe,[t[8]||(t[8]=e("svg",{xmlns:"http://www.w3.org/2000/svg",class:"w-12 h-12 mx-auto mb-3 text-orange-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","stroke-width":"1.5"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M9 12.75L11.25 15 15 9.75m-3-7.036A11.959 11.959 0 013.598 6 11.99 11.99 0 003 9.749c0 5.592 3.824 10.29 9 11.623 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.571-.598-3.751h-.152c-3.196 0-6.1-1.248-8.25-3.285z"})],-1)),e("p",He,n(s(o)("login.twoFactorTitle")),1),e("p",Ue,n(s(o)("login.totpInstruction")),1)]),e("div",Ke,[L(e("input",{ref_key:"totpInputRef",ref:N,"onUpdate:modelValue":t[2]||(t[2]=p=>v.value=p),type:"text",inputmode:"numeric",pattern:"[0-9]*",maxlength:"8",autocomplete:"one-time-code","aria-label":s(o)("login.totpLabel"),class:"w-full px-4 py-3 bg-transparent border border-white/20 rounded-lg text-white text-center text-2xl tracking-[0.5em] placeholder-white/40 focus:outline-none focus:border-orange-400/60 focus:ring-1 focus:ring-orange-400/30 transition-colors",placeholder:y.value?"XXXX-XXXX":"000000",onKeyup:B(O,["enter"]),disabled:l.value},null,40,Ne),[[T,v.value]])]),e("button",{onClick:O,disabled:l.value||!v.value,class:"w-full glass-button px-6 py-3 rounded-lg font-medium transition-all hover:bg-black/70 hover:border-white/30 disabled:opacity-50 disabled:cursor-not-allowed mb-3"},[l.value?(c(),i("span",Je,[t[9]||(t[9]=e("svg",{class:"animate-spin h-5 w-5 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})],-1)),R(" "+n(s(o)("login.verifying")),1)])):(c(),i("span",Fe,n(s(o)("login.verifyButton")),1))],8,qe),e("button",{onClick:t[3]||(t[3]=p=>{y.value=!y.value,v.value=""}),class:"w-full text-white/50 text-sm hover:text-white/70 transition-colors py-2"},n(y.value?s(o)("login.useAuthCode"):s(o)("login.useBackupCode")),1)],64)):(c(),i(j,{key:4},[e("div",De,[e("label",Oe,n(s(o)("login.password")),1),L(e("input",{id:"login-password","onUpdate:modelValue":t[4]||(t[4]=p=>r.value=p),type:"password",class:"w-full px-4 py-3 bg-transparent border border-white/20 rounded-lg text-white placeholder-white/40 focus:outline-none focus:border-white/40 focus:ring-1 focus:ring-white/20 transition-colors",placeholder:s(o)("login.enterPasswordPlaceholder"),onKeyup:B(D,["enter"]),disabled:l.value||_.value},null,40,Ge),[[T,r.value]])]),e("button",{onClick:D,disabled:l.value||_.value||!r.value,class:"w-full glass-button px-6 py-3 rounded-lg font-medium transition-all hover:bg-black/70 hover:border-white/30 disabled:opacity-50 disabled:cursor-not-allowed"},[l.value?(c(),i("span",Qe,[t[10]||(t[10]=e("svg",{class:"animate-spin h-5 w-5 mr-2",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})],-1)),R(" "+n(s(o)("login.loggingIn")),1)])):(c(),i("span",$e,n(s(o)("login.loginButton")),1))],8,We)],64)),e("div",Ye,n(s(o)("login.recoveryNote")),1)],2),e("div",Ze,[e("button",{onClick:ee,class:"text-xs text-white/50 hover:text-white/70 transition-colors underline-offset-2 hover:underline"},n(s(o)("login.replayIntro")),1),t[11]||(t[11]=e("span",{class:"text-white/30"},"|",-1)),e("button",{onClick:te,disabled:C.value,class:"text-xs text-white/50 hover:text-white/70 transition-colors underline-offset-2 hover:underline disabled:opacity-50 disabled:cursor-not-allowed"},n(C.value?s(o)("login.resetting"):s(o)("login.onboarding")),9,et)])])]))}}),lt=ge(tt,[["__scopeId","data-v-a59fcd7f"]]);export{lt as default};
|