1import{d as at,r as u,c as te,w as ae,o as nt,X as ot,Z as st,D as it,K as Ne,B as s,k as Re,G as r,u as o,z as v,E as P,Q as R,$ as Be,F as K,W as H,Y as ne,_ as rt,C as h}from"./vendor-vue-Dzwqm9Y9.js";import"./AppHeader.vue_vue_type_style_index_0_scoped_25b0c839_lang-B0lsvCqV.js";import{u as ut,a as lt,X as pe,s as ge,v as Le,Y as Me,r as De,p as ct,U as dt,T as ht,f as fe,Z as Ee,W as vt,D as pt}from"./index-Dg7iAOYr.js";import"./vendor-misc-B-nM3tYW.js";import"./useClipboard-DI2IZ1WO.js";/* empty css */import{A as gt}from"./AuthLayout-z7fxUHCk.js";import{P as ft}from"./PendingOAuthCreateAccountForm-CA04567l.js";import{c as oe,l as Ue,o as Oe}from"./oauthAffiliate-CrlUwkd1.js";import{u as _t}from"./vendor-i18n-BuoWFzps.js";import"./CaptchaChallenge.vue_vue_type_script_setup_true_lang-CcmCoDPI.js";const mt={class:"space-y-6"},bt={class:"text-center"},wt={class:"text-2xl font-bold text-gray-900 dark:text-white"},yt={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"},Ut=["placeholder","disabled"],Ot=["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"},Kt=["placeholder","disabled"],Ht=["disabled"],Xt={key:2,class:"rounded-xl border border-gray-200 bg-gray-50 p-4 dark:border-dark-600 dark:bg-dark-800/60"},Yt={class:"space-y-4"},Zt={class:"space-y-1"},jt={class:"text-sm font-medium text-gray-900 dark:text-white"},Gt={class:"text-xs text-gray-500 dark:text-dark-400"},Qt=["disabled"],Jt=["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"],wa=at({__name:"WechatCallbackView",setup(ya){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(""),X=u(!0),Y=u(!0),A=u(!1),m=u("none"),E=u(""),w=u(""),N=u(""),re=u(""),y=u(""),Z=u(!1),j=u(""),U=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"),G=te(()=>!!pe());ae(se,e=>{e&&p.showError(e)}),ae(y,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:O(e||L.value)})}function we(){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 O(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 ye(){return Me(p.cachedPublicSettings)?De(p.cachedPublicSettings).mode:null}function Q(){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 Ke(e){return e==="open"||e==="mp"?e:null}function ke(){const e=ye();if(e)return e;const t=Ke(b.query.mode);return t||ze()}function xe(){return O(b.query.redirect||L.value||"/dashboard")}function He(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/bind/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 J(){return{adoptDisplayName:X.value,adoptAvatar:Y.value}}function Xe(){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=ye()===null?Q():"",t=He("bind_current_user");if(!t){k.value=e||Q();return}try{await ct(),window.location.href=t}catch(a){k.value=W(a,n("auth.loginFailed"))}}async function Ye(){if(pe()){await ce();return}const e=Ae();if(!e){k.value=Q();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||(X.value=!1),M.value||(Y.value=!1)}function Ze(e){return!!(e.suggested_display_name||e.suggested_avatar_url)}function je(e){return(e==null?void 0:e.trim().toLowerCase())||""}function Ge(e){return(e.pending_email||e.existing_account_email||e.resolved_email||e.email||Xe()||"").trim()}function Qe(e){const t=je(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=Qe(e);m.value=t,y.value="",T.value=!1,Z.value=!1,j.value="",U.value="",I.value="",ue.value="";const a=Ge(e);if(E.value=a,t!=="create_account"){if(t==="bind_login"){w.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,Z.value=!0,j.value=e.temp_token,U.value="",I.value="",ue.value=e.user_email_masked||"",g.value=!1,!0)}function de(e){m.value="bind_login",T.value=!1,w.value=w.value.trim()||(e==null?void 0:e.trim())||E.value.trim(),N.value="",y.value=""}function he(){m.value="create_account",T.value=!1,E.value=E.value.trim()||w.value.trim(),y.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 Je(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=O(e.redirect||"/profile");we(),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=O(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=Ue(),l=J(),d=re.value?(await fe.post("/auth/oauth/wechat/complete-registration",{pending_oauth_token:re.value,invitation_code:q.value.trim(),...Oe(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(J());await ee(e)}catch(e){k.value=W(e,n("auth.loginFailed")),A.value=!1}finally{i.value=!1}}async function tt(e){if(y.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,...e.turnstileToken?{turnstile_token:e.turnstileToken}:{},...e.tencentCaptchaTicket?{tencent_captcha_ticket:e.tencentCaptchaTicket,tencent_captcha_randstr:e.tencentCaptchaRandstr}:{},invitation_code:e.invitationCode||void 0,...Oe(Ue()),...le(J())});await ee(t)}catch(t){if(Je(t)){de(e.email.trim());return}y.value=W(t,n("auth.loginFailed"))}finally{i.value=!1}}}async function ve(){y.value="";const e=w.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(J())});await ee(a)}catch(a){y.value=W(a,n("auth.loginFailed"))}finally{i.value=!1}}}async function qe(){I.value="";const e=U.value.trim();if(!(!j.value||e.length!==6)){i.value=!0;try{const t=await vt({temp_token:j.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,w.value=c,E.value=c}if(b.query.wechat_bind_existing==="1"){if(pe()){await ce();return}const c=Ae();if(!c){k.value=Q(),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=O(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(),_=O(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&&Ze(c)){A.value=!0,g.value=!1,C(_);return}await Pe(c,_)}catch(c){we(),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",wt,r(o(n)("auth.oidc.callbackTitle",{providerName:o(f)})),1),s("p",yt,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||Z.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=>X.value=a),type:"checkbox",class:"mt-1 h-4 w-4"},null,512),[[Be,X.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=>Y.value=a),type:"checkbox",class:"mt-1 h-4 w-4"},null,512),[[Be,Y.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(K,{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,Ut),[[H,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,Ot),s("div",Wt,[s("div",Vt,[s("div",$t,[s("p",It,r(o(n)("auth.alreadyHaveAccount")),1),s("p",zt,r(G.value?o(n)("auth.oauthFlow.bindCurrentAccountDescription",{providerName:o(f)}):o(n)("auth.oauthFlow.signInThenBindDescription",{providerName:o(f)})),1)]),G.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,Kt)),[[H,D.value]]),s("button",{"data-testid":"existing-account-submit",type:"button",class:"btn btn-secondary w-full",disabled:i.value,onClick:Ye},r(G.value?o(n)("auth.oauthFlow.bindCurrentAccount"):o(n)("auth.signIn")),9,Ht)])])],64)):T.value?(h(),v("div",Xt,[s("div",Yt,[s("div",Zt,[s("p",jt,r(o(n)("auth.oauthFlow.chooseHowToContinue")),1),s("p",Gt,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,Qt),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,Jt)])])):A.value?(h(),v(K,{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(K,{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":y.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(K,{key:5},[s("p",oa,r(o(n)("auth.oauthFlow.bindSignInToExistingAccount",{providerName:o(f)})),1),G.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=>w.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),[[H,w.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),[[H,N.value]]),s("button",{"data-testid":"wechat-bind-login-submit",class:"btn btn-primary w-full",disabled:i.value||!w.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)):Z.value?(h(),v(K,{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=>U.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),[[H,U.value]]),s("button",{"data-testid":"wechat-bind-login-totp-submit",class:"btn btn-primary w-full",disabled:i.value||U.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(wa,[["__scopeId","data-v-7e2cf347"]]);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.