1import{d as at,r as u,c as te,w as ae,o as nt,X as ot,Z as st,H as it,J as Ne,B as s,k as Re,G as r,u as o,z as v,D as P,R,$ as Be,F as H,W as K,Y as ne,_ as rt,C as h}from"./vendor-vue-CNokyTVe.js";import"./AppHeader.vue_vue_type_style_index_0_scoped_e9be4349_lang-xG_yv2rf.js";import{u as ut,a as lt,Q as pe,s as ge,v as Le,R as Me,r as De,p as ct,N as dt,M as ht,f as fe,S as Ee,P as vt,D as pt}from"./index-DP2Z749b.js";import"./vendor-misc-CSmvsGIg.js";import"./useClipboard-CR8lmECi.js";/* empty css */import{A as gt}from"./AuthLayout-zkNlM3YK.js";import{P as ft}from"./PendingOAuthCreateAccountForm-DpGv5FQC.js";import{c as oe,l as Oe,o as Ue}from"./oauthAffiliate-CrlUwkd1.js";import{u as _t}from"./vendor-i18n-CJe1LeE7.js";import"./TurnstileWidget-B6skts-H.js";const mt={class:"space-y-6"},bt={class:"text-center"},yt={class:"text-2xl font-bold text-gray-900 dark:text-white"},wt={class:"mt-2 text-sm text-gray-500 dark:text-dark-400"},kt={key:0,class:"space-y-4"},xt={key:0,class:"rounded-xl border border-gray-200 bg-gray-50 p-4 dark:border-dark-600 dark:bg-dark-800/60"},At={class:"space-y-3"},Ct={class:"space-y-1"},St={class:"text-sm font-medium text-gray-900 dark:text-white"},Ft={class:"text-xs text-gray-500 dark:text-dark-400"},Pt={key:0,class:"flex items-start gap-3 rounded-lg border border-gray-200 bg-white p-3 text-sm dark:border-dark-600 dark:bg-dark-900/50"},Tt={class:"space-y-1"},qt={class:"block font-medium text-gray-900 dark:text-white"},Nt={class:"block text-gray-500 dark:text-dark-400"},Rt={key:1,class:"flex items-start gap-3 rounded-lg border border-gray-200 bg-white p-3 text-sm dark:border-dark-600 dark:bg-dark-900/50"},Bt=["src","alt"],Lt={class:"space-y-1"},Mt={class:"block font-medium text-gray-900 dark:text-white"},Dt={class:"block break-all text-gray-500 dark:text-dark-400"},Et={class:"text-sm text-gray-700 dark:text-gray-300"},Ot=["placeholder","disabled"],Ut=["disabled"],Wt={class:"rounded-xl border border-gray-200 bg-gray-50 p-4 dark:border-dark-600 dark:bg-dark-800/60"},Vt={class:"space-y-3"},$t={class:"space-y-1"},It={class:"text-sm font-medium text-gray-900 dark:text-white"},zt={class:"text-xs text-gray-500 dark:text-dark-400"},Ht=["placeholder","disabled"],Kt=["disabled"],jt={key:2,class:"rounded-xl border border-gray-200 bg-gray-50 p-4 dark:border-dark-600 dark:bg-dark-800/60"},Gt={class:"space-y-4"},Jt={class:"space-y-1"},Qt={class:"text-sm font-medium text-gray-900 dark:text-white"},Xt={class:"text-xs text-gray-500 dark:text-dark-400"},Yt=["disabled"],Zt=["disabled"],ea={class:"text-sm text-gray-700 dark:text-gray-300"},ta=["disabled"],aa={class:"text-sm text-gray-700 dark:text-gray-300"},na=["disabled"],oa={class:"text-sm text-gray-700 dark:text-gray-300"},sa={key:0,class:"rounded-xl border border-gray-200 bg-gray-50 p-4 dark:border-dark-600 dark:bg-dark-800/60"},ia={class:"space-y-3"},ra={class:"space-y-1"},ua={class:"text-sm font-medium text-gray-900 dark:text-white"},la={class:"text-xs text-gray-500 dark:text-dark-400"},ca=["disabled"],da={key:1,class:"space-y-3"},ha=["placeholder","disabled"],va=["placeholder","disabled"],pa=["disabled"],ga=["disabled"],fa={class:"text-sm text-gray-700 dark:text-gray-300"},_a={class:"space-y-3"},ma=["disabled"],ba=["disabled"],ya=at({__name:"WechatCallbackView",setup(wa){const b=ot(),B=st(),{t:n}=_t(),V=ut(),p=lt(),g=u(!0),k=u(""),x=u(!1),T=u(!1),q=u(""),i=u(!1),se=u(""),L=u("/dashboard"),ie=u(!1),$=u(""),M=u(""),D=u(""),j=u(!0),G=u(!0),A=u(!1),m=u("none"),E=u(""),y=u(""),N=u(""),re=u(""),w=u(""),J=u(!1),Q=u(""),O=u(""),I=u(""),ue=u(""),We=n("profile.authBindings.bindSuccess"),f=n("auth.wechatProviderName"),_e=te(()=>m.value==="create_account"||m.value==="bind_login"),me=te(()=>m.value==="create_account"),be=te(()=>m.value==="bind_login"),X=te(()=>!!pe());ae(se,e=>{e&&p.showError(e)}),ae(w,e=>{e&&p.showError(e)}),ae(I,e=>{e&&p.showError(e)}),ae(k,e=>{e&&p.showError(e)});function C(e){V.setPendingAuthSession({token:"",token_field:"pending_oauth_token",provider:"wechat",redirect:U(e||L.value)})}function ye(){V.clearPendingAuthSession()}function Ve(){const e=typeof window<"u"?window.location.hash:"",t=e.startsWith("#")?e.slice(1):e;return new URLSearchParams(t)}function $e(e){var F,c,_,z;const t=((F=e.get("access_token"))==null?void 0:F.trim())||"";if(!t)return null;const a={access_token:t},l=((c=e.get("refresh_token"))==null?void 0:c.trim())||"";l&&(a.refresh_token=l);const d=Number.parseInt(((_=e.get("expires_in"))==null?void 0:_.trim())||"",10);Number.isFinite(d)&&d>0&&(a.expires_in=d);const S=((z=e.get("token_type"))==null?void 0:z.trim())||"";return S&&(a.token_type=S),a}function U(e){return!e||!e.startsWith("/")||e.startsWith("//")||e.includes("://")||e.includes(` 2`)||e.includes("\r")?"/dashboard":e}async function Ie(){Me(p.cachedPublicSettings)||p.publicSettingsLoaded||await p.fetchPublicSettings()}function we(){return Me(p.cachedPublicSettings)?De(p.cachedPublicSettings).mode:null}function Y(){switch(De(p.cachedPublicSettings).unavailableReason){case"capability_unknown":return n("auth.oauth
2Flow.wechatAvailabilityUnknown");case"external_browser_required":return n("auth.oauthFlow.wechatSystemBrowserOnly");case"wechat_browser_required":return n("auth.oauthFlow.wechatBrowserOnly");case"native_app_required":return"This WeChat sign-in flow is only available from the native mobile app.";case"not_configured":return n("auth.oauthFlow.wechatNotConfigured");default:return n("auth.loginFailed")}}function ze(){return typeof navigator>"u"?"open":/MicroMessenger/i.test(navigator.userAgent)?"mp":"open"}function He(e){return e==="open"||e==="mp"?e:null}function ke(){const e=we();if(e)return e;const t=He(b.query.mode);return t||ze()}function xe(){return U(b.query.redirect||L.value||"/dashboard")}function Ke(e){const a="/api/v1".replace(/\/$/,""),l=ke();if(!l)return null;const d=new URLSearchParams({mode:l,redirect:xe(),intent:e});return`${a}/auth/oauth/wechat/start?${d.toString()}`}function Ae(){const e=ke();if(!e)return null;const t=new URLSearchParams({wechat_bind_existing:"1",redirect:xe(),mode:e}),a=D.value.trim();return a&&t.set("email",a),`/auth/wechat/callback?${t.toString()}`}function Z(){return{adoptDisplayName:j.value,adoptAvatar:G.value}}function je(){return typeof b.query.email=="string"?b.query.email.trim():""}function le(e){const t={};return typeof e.adoptDisplayName=="boolean"&&(t.adopt_display_name=e.adoptDisplayName),typeof e.adoptAvatar=="boolean"&&(t.adopt_avatar=e.adoptAvatar),t}async function ce(){const e=we()===null?Y():"",t=Ke("bind_current_user");if(!t){k.value=e||Y();return}try{await ct(),window.location.href=t}catch(a){k.value=W(a,n("auth.loginFailed"))}}async function Ge(){if(pe()){await ce();return}const e=Ae();if(!e){k.value=Y();return}const t=new URLSearchParams({redirect:e}),a=D.value.trim();a&&t.set("email",a),await B.replace(`/login?${t.toString()}`)}function Ce(e){ie.value=e.adoption_required===!0,$.value=e.suggested_display_name||"",M.value=e.suggested_avatar_url||"",$.value||(j.value=!1),M.value||(G.value=!1)}function Je(e){return!!(e.suggested_display_name||e.suggested_avatar_url)}function Qe(e){return(e==null?void 0:e.trim().toLowerCase())||""}function Xe(e){return(e.pending_email||e.existing_account_email||e.resolved_email||e.email||je()||"").trim()}function Ye(e){const t=Qe(e.step||e.status||e.state||e.error||e.intent);return t==="choice"||t==="choose_account_action_required"||t==="choose_account_action"||t==="choose_account"||t==="choose"?"choice":t==="email_required"||t==="create_account_required"||t==="create_account"?"create_account":t==="existing_account"||t==="existing_account_required"||t==="existing_account_binding_required"||t==="adopt_existing_user_by_email"||t==="bind_login_required"||t==="bind_login"?"bind_login":"none"}function Se(e){const t=Ye(e);m.value=t,w.value="",T.value=!1,J.value=!1,Q.value="",O.value="",I.value="",ue.value="";const a=Xe(e);if(E.value=a,t!=="create_account"){if(t==="bind_login"){y.value=a,N.value="";return}if(t==="choice"){T.value=!0,N.value="";return}}}function Fe(e){return e.requires_2fa!==!0||!e.temp_token?!1:(m.value="none",T.value=!1,x.value=!1,A.value=!1,J.value=!0,Q.value=e.temp_token,O.value="",I.value="",ue.value=e.user_email_masked||"",g.value=!1,!0)}function de(e){m.value="bind_login",T.value=!1,y.value=y.value.trim()||(e==null?void 0:e.trim())||E.value.trim(),N.value="",w.value=""}function he(){m.value="create_account",T.value=!1,E.value=E.value.trim()||y.value.trim(),w.value=""}function W(e,t){var l,d,S,F;const a=e;return((d=(l=a.response)==null?void 0:l.data)==null?void 0:d.detail)||((F=(S=a.response)==null?void 0:S.data)==null?void 0:F.message)||a.message||t}function Ze(e){var l;const t=(l=e.response)==null?void 0:l.data,a=[t==null?void 0:t.reason,t==null?void 0:t.error,t==null?void 0:t.code,t==null?void 0:t.step,t==null?void 0:t.intent].map(d=>d==null?void 0:d.trim().toLowerCase()).filter(d=>!!d);return a.includes("email_exists")||a.includes("bind_login_required")||a.includes("bind_login")||a.includes("adopt_existing_user_by_email")||a.includes("existing_account_required")||a.includes("existing_account_binding_required")}async function Pe(e,t){if(dt(e)==="bind"){const a=U(e.redirect||"/profile");ye(),oe(),p.showSuccess(We),await B.replace(a);return}if(!ht(e))throw new Error(n("auth.oidc.callbackMissingToken"));ge(e),await V.setToken(e.access_token),oe(),p.showSuccess(n("auth.loginSuccess")),await B.replace(t)}async function ee(e){Ce(e);const t=U(e.redirect||L.value);if(e.error==="invitation_required"){m.value="none",x.value=!0,A.value=!1,g.value=!1,C(t);return}if(Fe(e)){C(t);return}if(Se(e),m.value!=="none"){x.value=!1,A.value=!1,g.value=!1,C(t);return}if(e.auth_result==="pending_session"){x.value=!1,A.value=!1,g.value=!1,C(t);return}await Pe(e,t)}async function Te(){var e,t;if(se.value="",!!q.value.trim()){i.value=!0;try{const a=Oe(),l=Z(),d=re.value?(await fe.post("/auth/oauth/wechat/complete-registration",{pending_oauth_token:re.value,invitation_code:q.value.trim(),...Ue(a),...le(l)})).data:a?await Ee(q.value.trim(),l,a):await Ee(q.value.trim(),l);await ee(d)}catch(a){const l=a;se.value=((t=(e=l.response)==null?void 0:e.data)==null?void 0:t.message)||l.message||n("auth.oidc.completeRegistrationFailed")}finally{i.value=!1}}}async function et(){i.value=!0;try{const e=await Le(Z());await ee(e)}catch(e){k.value=W(e,n("auth.loginFailed")),A.value=!1}finally{i.value=!1}}async function tt(e){if(w.value="",!(!e.email||!e.password)){i.value=!0;try{const{data:t}=await fe.post("/auth/oauth/pending/create-account",{email:e.email,password:e.password,verify_code:e.verifyCode||void 0,invitation_code:e.invitationCode||void 0,...Ue(Oe()),...le(Z())});await ee(t)}catch(t){if(Ze(t)){de(e.email.trim());return}w.value=W(t,n("auth.loginFailed"))}finally{i.value=!1}}}async function ve(){w.value="";const e=y.value.trim(),t=N.value;if(!(!e||!t)){i.value=!0;try{const{data:a}=await fe.post("/auth/oauth/pending/bind-login",{email:e,password:t,...le(Z())});await ee(a)}catch(a){w.value=W(a,n("auth.loginFailed"))}finally{i.value=!1}}}async function qe(){I.value="";const e=O.value.trim();if(!(!Q.value||e.length!==6)){i.value=!0;try{const t=await vt({temp_token:Q.value,totp_code:e});ge(t),await V.setToken(t.access_token),oe(),p.showSuccess(n("auth.loginSuccess")),await B.replace(L.value)}catch(t){I.value=W(t,n("auth.loginFailed"))}finally{i.value=!1}}}return nt(async()=>{var F;try{await Ie()}catch{}if(typeof b.query.email=="string"){const c=b.query.email.trim();D.value=c,y.value=c,E.value=c}if(b.query.wechat_bind_existing==="1"){if(pe()){await ce();return}const c=Ae();if(!c){k.value=Y(),g.value=!1;return}const _=new URLSearchParams({redirect:c}
2),z=D.value.trim();z&&_.set("email",z),await B.replace(`/login?${_.toString()}`);return}const e=Ve(),t=$e(e),a=((F=e.get("pending_oauth_token"))==null?void 0:F.trim())||"",l=e.get("error"),d=e.get("error_description")||e.get("error_message")||"",S=U(e.get("redirect")||b.query.redirect||"/dashboard");try{if(t){ge(t),await V.setToken(t.access_token),oe(),p.showSuccess(n("auth.loginSuccess")),await B.replace(S);return}if(l==="invitation_required"&&a){re.value=a,L.value=S,x.value=!0,g.value=!1;return}if(l){k.value=d||l,g.value=!1;return}const c=await Le(),_=U(c.redirect||b.query.redirect||"/dashboard");if(Ce(c),L.value=_,c.error==="invitation_required"){x.value=!0,g.value=!1,C(_);return}if(Fe(c)){C(_);return}if(Se(c),m.value!=="none"){g.value=!1,C(_);return}if(ie.value&&Je(c)){A.value=!0,g.value=!1,C(_);return}await Pe(c,_)}catch(c){ye(),k.value=W(c,n("auth.loginFailed")),g.value=!1}}),(e,t)=>(h(),it(o(gt),null,{default:Ne(()=>[s("div",mt,[s("div",bt,[s("h2",yt,r(o(n)("auth.oidc.callbackTitle",{providerName:o(f)})),1),s("p",wt,r(g.value?o(n)("auth.oidc.callbackProcessing",{providerName:o(f)}):o(n)("auth.oidc.callbackHint")),1)]),Re(rt,{name:"fade"},{default:Ne(()=>[x.value||T.value||A.value||me.value||be.value||J.value?(h(),v("div",kt,[ie.value&&($.value||M.value)?(h(),v("div",xt,[s("div",At,[s("div",Ct,[s("p",St,r(o(n)("auth.oauthFlow.profileDetailsTitle",{providerName:o(f)})),1),s("p",Ft,r(o(n)("auth.oauthFlow.profileDetailsDescription",{providerName:o(f)})),1)]),$.value?(h(),v("label",Pt,[R(s("input",{"onUpdate:modelValue":t[0]||(t[0]=a=>j.value=a),type:"checkbox",class:"mt-1 h-4 w-4"},null,512),[[Be,j.value]]),s("span",Tt,[s("span",qt,r(o(n)("auth.oauthFlow.useDisplayName")),1),s("span",Nt,r($.value),1)])])):P("",!0),M.value?(h(),v("label",Rt,[R(s("input",{"onUpdate:modelValue":t[1]||(t[1]=a=>G.value=a),type:"checkbox",class:"mt-1 h-4 w-4"},null,512),[[Be,G.value]]),s("img",{src:M.value,alt:o(n)("auth.oauthFlow.avatarAlt",{providerName:o(f)}),class:"h-10 w-10 rounded-full border border-gray-200 object-cover dark:border-dark-600"},null,8,Bt),s("span",Lt,[s("span",Mt,r(o(n)("auth.oauthFlow.useAvatar")),1),s("span",Dt,r(M.value),1)])])):P("",!0)])])):P("",!0),x.value?(h(),v(H,{key:1},[s("p",Et,r(o(n)("auth.oidc.invitationRequired",{providerName:o(f)})),1),s("div",null,[R(s("input",{"onUpdate:modelValue":t[2]||(t[2]=a=>q.value=a),type:"text",class:"input w-full",placeholder:o(n)("auth.invitationCodePlaceholder"),disabled:i.value,onKeyup:ne(Te,["enter"])},null,40,Ot),[[K,q.value]])]),s("button",{class:"btn btn-primary w-full",disabled:i.value||!q.value.trim(),onClick:Te},r(i.value?o(n)("auth.oidc.completing"):o(n)("auth.oidc.completeRegistration")),9,Ut),s("div",Wt,[s("div",Vt,[s("div",$t,[s("p",It,r(o(n)("auth.alreadyHaveAccount")),1),s("p",zt,r(X.value?o(n)("auth.oauthFlow.bindCurrentAccountDescription",{providerName:o(f)}):o(n)("auth.oauthFlow.signInThenBindDescription",{providerName:o(f)})),1)]),X.value?P("",!0):R((h(),v("input",{key:0,"onUpdate:modelValue":t[3]||(t[3]=a=>D.value=a),"data-testid":"existing-account-email",type:"email",class:"input w-full",placeholder:o(n)("auth.emailPlaceholder"),disabled:i.value},null,8,Ht)),[[K,D.value]]),s("button",{"data-testid":"existing-account-submit",type:"button",class:"btn btn-secondary w-full",disabled:i.value,onClick:Ge},r(X.value?o(n)("auth.oauthFlow.bindCurrentAccount"):o(n)("auth.signIn")),9,Kt)])])],64)):T.value?(h(),v("div",jt,[s("div",Gt,[s("div",Jt,[s("p",Qt,r(o(n)("auth.oauthFlow.chooseHowToContinue")),1),s("p",Xt,r(o(n)("auth.oauthFlow.chooseAccountActionHint")),1)]),s("button",{"data-testid":"wechat-choice-bind-existing",type:"button",class:"btn btn-primary w-full",disabled:i.value,onClick:t[4]||(t[4]=a=>de())},r(o(n)("auth.oauthFlow.bindExistingAccount")),9,Yt),s("button",{"data-testid":"wechat-choice-create-account",type:"button",class:"btn btn-secondary w-full",disabled:i.value,onClick:t[5]||(t[5]=a=>he())},r(o(n)("auth.oauthFlow.createNewAccount")),9,Zt)])])):A.value?(h(),v(H,{key:3},[s("p",ea,r(o(n)("auth.oauthFlow.reviewProfileBeforeContinue",{providerName:o(f)})),1),s("button",{class:"btn btn-primary w-full",disabled:i.value,onClick:et},r(i.value?o(n)("common.processing"):o(n)("auth.continue")),9,ta)],64)):me.value?(h(),v(H,{key:4}
2,[s("p",aa,r(o(n)("auth.oauthFlow.createAccountHint")),1),Re(ft,{"test-id-prefix":"wechat","initial-email":E.value,"is-submitting":i.value,"error-message":w.value,onSubmit:tt,onSwitchToBind:de},null,8,["initial-email","is-submitting","error-message"]),_e.value?(h(),v("button",{key:0,class:"btn btn-secondary w-full",disabled:i.value,onClick:t[6]||(t[6]=a=>he())},r(o(n)("auth.oauthFlow.createNewAccount")),9,na)):P("",!0)],64)):be.value?(h(),v(H,{key:5},[s("p",oa,r(o(n)("auth.oauthFlow.bindSignInToExistingAccount",{providerName:o(f)})),1),X.value?(h(),v("div",sa,[s("div",ia,[s("div",ra,[s("p",ua,r(o(n)("auth.oauthFlow.bindCurrentAccountTitle")),1),s("p",la,r(o(n)("auth.oauthFlow.bindCurrentAccountDescription",{providerName:o(f)})),1)]),s("button",{"data-testid":"existing-account-submit",type:"button",class:"btn btn-primary w-full",disabled:i.value,onClick:ce},r(i.value?o(n)("common.processing"):o(n)("auth.oauthFlow.bindCurrentAccount")),9,ca)])])):(h(),v("div",da,[R(s("input",{"onUpdate:modelValue":t[7]||(t[7]=a=>y.value=a),"data-testid":"wechat-bind-login-email",type:"email",class:"input w-full",placeholder:o(n)("auth.emailPlaceholder"),disabled:i.value,onKeyup:ne(ve,["enter"])},null,40,ha),[[K,y.value]]),R(s("input",{"onUpdate:modelValue":t[8]||(t[8]=a=>N.value=a),"data-testid":"wechat-bind-login-password",type:"password",class:"input w-full",placeholder:o(n)("auth.passwordPlaceholder"),disabled:i.value,onKeyup:ne(ve,["enter"])},null,40,va),[[K,N.value]]),s("button",{"data-testid":"wechat-bind-login-submit",class:"btn btn-primary w-full",disabled:i.value||!y.value.trim()||!N.value,onClick:ve},r(i.value?o(n)("common.processing"):o(n)("auth.oauthFlow.logInAndBind")),9,pa)])),_e.value?(h(),v("button",{key:2,class:"btn btn-secondary w-full",disabled:i.value,onClick:t[9]||(t[9]=a=>he())},r(o(n)("auth.oauthFlow.createNewAccount")),9,ga)):P("",!0)],64)):J.value?(h(),v(H,{key:6},[s("p",fa,r(o(n)("auth.oauthFlow.totpHint",{providerName:o(f),account:ue.value||o(n)("auth.oauthFlow.yourAccount")})),1),s("div",_a,[R(s("input",{"onUpdate:modelValue":t[10]||(t[10]=a=>O.value=a),"data-testid":"wechat-bind-login-totp",type:"text",inputmode:"numeric",maxlength:"6",class:"input w-full",placeholder:"123456",disabled:i.value,onKeyup:ne(qe,["enter"])},null,40,ma),[[K,O.value]]),s("button",{"data-testid":"wechat-bind-login-totp-submit",class:"btn btn-primary w-full",disabled:i.value||O.value.trim().length!==6,onClick:qe},r(i.value?o(n)("common.processing"):o(n)("auth.oauthFlow.verifyAndContinue")),9,ba)])],64)):P("",!0)])):P("",!0)]),_:1})])]),_:1}))}}),Ba=pt(ya,[["__scopeId","data-v-705a2fcb"]]);export{Ba as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.