1import{d as Oe,r,c as re,w as Z,o as ze,X as He,Z as We,D as $e,K as we,B as o,k as xe,G as l,u as s,z as p,E as D,L as R,$ as Ae,F as O,M as J,Y as Q,_ as je,C as h}from"./vendor-vue-BVJWaRIf.js";import"./AppHeader.vue_vue_type_style_index_0_scoped_59fb3e77_lang-BAGlNg6f.js";import{u as Ge,a as Xe,q as Ce,s as Te,T as Ye,S as Ze,f as le,V as Je,C as Qe}from"./index-DGTjV__i.js";import"./vendor-misc-WKm5Kdig.js";import"./useClipboard-DW3Oc4kG.js";/* empty css */import{A as et}from"./AuthLayout-DcEKhMt1.js";import{P as tt}from"./PendingOAuthCreateAccountForm-B_EDtON4.js";import{c as ee,l as Fe,o as Se}from"./oauthAffiliate-CrlUwkd1.js";import{u as at}from"./vendor-i18n-pgwztqC8.js";import"./CaptchaChallenge.vue_vue_type_script_setup_true_lang-ChMLm7uf.js";const nt={class:"space-y-6"},ot={class:"text-center"},st={class:"text-2xl font-bold text-gray-900 dark:text-white"},it={class:"mt-2 text-sm text-gray-500 dark:text-dark-400"},rt={key:0,class:"space-y-4"},lt={key:0,class:"rounded-xl border border-gray-200 bg-gray-50 p-4 dark:border-dark-600 dark:bg-dark-800/60"},ut={class:"space-y-3"},ct={class:"space-y-1"},dt={class:"text-sm font-medium text-gray-900 dark:text-white"},vt={class:"text-xs text-gray-500 dark:text-dark-400"},ht={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"},gt={class:"space-y-1"},_t={class:"block font-medium text-gray-900 dark:text-white"},pt={class:"block text-gray-500 dark:text-dark-400"},ft={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"},mt=["src","alt"],bt={class:"space-y-1"},kt={class:"block font-medium text-gray-900 dark:text-white"},yt={class:"block break-all text-gray-500 dark:text-dark-400"},wt={class:"text-sm text-gray-700 dark:text-gray-300"},xt=["placeholder","disabled"],At=["disabled"],Ct={class:"text-sm text-gray-700 dark:text-gray-300"},Tt=["disabled"],Ft={key:3,class:"rounded-xl border border-gray-200 bg-gray-50 p-4 dark:border-dark-600 dark:bg-dark-800/60"},St={class:"space-y-4"},Pt={class:"space-y-1"},qt={class:"text-sm font-medium text-gray-900 dark:text-white"},Nt={class:"text-xs text-gray-500 dark:text-dark-400"},Dt={class:"grid gap-3 sm:grid-cols-2"},Rt=["disabled"],Et=["disabled"],Lt={class:"text-sm text-gray-700 dark:text-gray-300"},Bt={class:"text-sm text-gray-700 dark:text-gray-300"},Vt={class:"space-y-3"},Mt=["placeholder","disabled"],Ut=["placeholder","disabled"],It=["disabled"],Kt=["disabled"],Ot={class:"text-sm text-gray-700 dark:text-gray-300"},zt={class:"space-y-3"},Ht=["disabled"],Wt=["disabled"],$t=Oe({__name:"DingTalkCallbackView",setup(jt){const z=He(),S=We(),{t:n,te:Pe}=at(),E=Ge(),k=Xe(),v=r(!0),H=r(""),y=r(!1),L=r(""),i=r(!1),te=r(""),B=r("/dashboard"),ae=r(!1),V=r(""),P=r(""),W=r(!0),$=r(!0),w=r(!1),g=r("none"),x=r(""),f=r(""),A=r(""),ue=r(""),m=r(""),F=r(!1),qe=n("profile.authBindings.bindSuccess"),j=r(!1),G=r(""),q=r(""),M=r(""),ne=r(""),N=n("auth.dingtalkProviderName"),ce=re(()=>g.value==="create_account"),de=re(()=>g.value==="choose_account_action"),ve=re(()=>g.value==="bind_login");Z(te,e=>{e&&k.showError(e)}),Z(m,e=>{e&&k.showError(e)}),Z(M,e=>{e&&k.showError(e)}),Z(H,e=>{e&&k.showError(e)});function b(e){E.setPendingAuthSession({token:"",token_field:"pending_oauth_token",provider:"dingtalk",redirect:U(e||B.value)})}function he(){E.clearPendingAuthSession()}function Ne(){const e=typeof window<"u"?window.location.hash:"",t=e.startsWith("#")?e.slice(1):e;return new URLSearchParams(t)}function De(e){var T,d,_,K;const t=((T=e.get("access_token"))==null?void 0:T.trim())||"";if(!t)return null;const a={access_token:t},u=((d=e.get("refresh_token"))==null?void 0:d.trim())||"";u&&(a.refresh_token=u);const c=Number.parseInt(((_=e.get("expires_in"))==null?void 0:_.trim())||"",10);Number.isFinite(c)&&c>0&&(a.expires_in=c);const C=((K=e.get("token_type"))==null?void 0:K.trim())||"";return C&&(a.token_type=C),a}function U(e){return!e||!e.startsWith("/")||e.startsWith("//")||e.includes("://")||e.includes(` 2`)||e.includes("\r")?"/dashboard":e}function X(){return{adoptDisplayName:W.value,adoptAvatar:$.value}}function oe(e){const t={};return typeof e.adoptDisplayName=="boolean"&&(t.adopt_display_name=e.adoptDisplayName),typeof e.adoptAvatar=="boolean"&&(t.adopt_avatar=e.adoptAvatar),t}function ge(e){ae.value=e.adoption_required===!0,V.value=e.suggested_display_name||"",P.value=e.suggested_avatar_url||"",V.value||(W.value=!1),P.value||($.value=!1)}function Re(e){return!!(e.suggested_display_name||e.suggested_avatar_url)}function Ee(e){return(e==null?void 0:e.trim().toLowerCase())||""}function Le(e){return(e.pending_email||e.existing_account_email||e.email||e.resolved_email||e.suggested_email||"").trim()}function Be(e){const t=Ee(e.step||e.error||e.intent);
2return t==="choice"||t==="choose_account_action_required"||t==="choose_account_action"||t==="choose_account"||t==="choose"?"choose_account_action":t==="email_required"||t==="create_account_required"||t==="create_account"?"create_account":t==="bind_login_required"||t==="bind_login"||t==="existing_account"||t==="existing_account_required"||t==="existing_account_binding_required"||t==="adopt_existing_user_by_email"?"bind_login":"none"}function _e(e){const t=Be(e);g.value=t,m.value="",j.value=!1,G.value="",q.value="",M.value="",ne.value="";const a=Le(e);if(t==="choose_account_action"){x.value=a,f.value=a,A.value="",F.value=!1;return}if(t==="create_account"){x.value=a,F.value=!0;return}if(t==="bind_login"){f.value=a,A.value="",F.value=!1;return}F.value=!1}function pe(e){return e.requires_2fa!==!0||!e.temp_token?!1:(g.value="none",y.value=!1,w.value=!1,j.value=!0,G.value=e.temp_token,q.value="",M.value="",ne.value=e.user_email_masked||"",v.value=!1,!0)}function se(e){g.value="bind_login",f.value=f.value.trim()||(e==null?void 0:e.trim())||x.value.trim(),A.value="",m.value="",F.value=!0}function fe(){g.value="create_account",x.value=x.value.trim()||f.value.trim(),m.value=""}function I(e,t){var u,c,C,T;const a=e;return((c=(u=a.response)==null?void 0:u.data)==null?void 0:c.detail)||((T=(C=a.response)==null?void 0:C.data)==null?void 0:T.message)||a.message||t}function Ve(e){var u;const t=(u=e.response)==null?void 0:u.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(c=>c==null?void 0:c.trim().toLowerCase()).filter(c=>!!c);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 me(e,t){if(Ye(e)==="bind"){const a=U(e.redirect||"/profile");he(),ee(),k.showSuccess(qe),await S.replace(a);return}if(!Ze(e))throw new Error(n("auth.dingtalk.callbackMissingToken"));Ce(e),await E.setToken(e.access_token),ee(),k.showSuccess(n("auth.loginSuccess")),await S.replace(t)}async function Y(e){ge(e);const t=U(e.redirect||B.value);if(e.step==="email_completion"||e.requires_email_completion===!0){await S.replace("/auth/dingtalk/email-completion?redirect="+encodeURIComponent(t));return}if(e.error==="invitation_required"){g.value="none",y.value=!0,w.value=!1,v.value=!1,b(t);return}if(pe(e)){b(t);return}if(_e(e),g.value!=="none"){y.value=!1,w.value=!1,v.value=!1,b(t);return}if(e.auth_result==="pending_session"){y.value=!1,w.value=!1,v.value=!1,b(t);return}await me(e,t)}async function be(){var e,t;if(te.value="",!!L.value.trim()){i.value=!0;try{const a=Fe(),u=X(),{data:c}=await le.post("/auth/oauth/dingtalk/complete-registration",{pending_oauth_token:ue.value||void 0,invitation_code:L.value.trim(),...Se(a),...oe(u)});await Y(c)}catch(a){const u=a;te.value=((t=(e=u.response)==null?void 0:e.data)==null?void 0:t.message)||u.message||n("auth.dingtalk.completeRegistrationFailed")}finally{i.value=!1}}}async function Me(){i.value=!0;try{const e=await Te(X());await Y(e)}catch(e){H.value=I(e,n("auth.loginFailed")),w.value=!1}finally{i.value=!1}}async function Ue(e){if(m.value="",!(!e.email||!e.password)){i.value=!0;try{const{data:t}=await le.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,...Se(Fe()),...oe(X())});await Y(t)}catch(t){if(Ve(t)){se(e.email.trim());return}m.value=I(t,n("auth.loginFailed"))}finally{i.value=!1}}}async function ie(){m.value="";const e=f.value.trim(),t=A.value;if(!(!e||!t)){i.value=!0;try{const{data:a}=await le.post("/auth/oauth/pending/bind-login",{email:e,password:t,...oe(X())});await Y(a)}catch(a){m.value=I(a,n("auth.loginFailed"))}finally{i.value=!1}}}async function ke(){M.value="";const e=q.value.trim();if(!(!G.value||e.length!==6)){i.value=!0;try{const t=await Je({temp_token:G.value,totp_code:e});await E.setToken(t.access_token),ee(),k.showSuccess(n("auth.loginSuccess")),await S.replace(B.value)}catch(t){M.value=I(t,n("auth.loginFailed"))}finally{i.value=!1}}}return ze(async()=>{var T;const e=Ne(),t=De(e),a=((T=e.get("pending_oauth_token"))==null?void 0:T.trim())||"",u=e.get("error"),c=e.get("error_description")||e.get("error_message")||"",C=U(e.get("redirect")||z.query.redirect||"/dashboard");try{if(t){Ce(t),await E.setToken(t.access_token),ee(),k.showSuccess(n("auth.loginSuccess")),await S.replace(C);return}if(u==="invitation_required"&&a){ue.value=a,B.value=C,y.value=!0,v.value=!1;return}if(u){const ye=`auth.dingtalk.error.${u}`;H.value=Pe(ye)?n(ye):c||u,v.value=!1;return}const d=await Te(),_=U(d.redirect||z.query.redirect||"/dashboard");ge(d),B.value=_;const K=d,Ie=z.query.bind==="1",Ke=(z.query.email||"").trim();if(K.step==="email_completion"||K.requires_email_completion===!0){if(Ie){g.value="bind_login",f.value=Ke,A.value="",F.value=!0,v.value=!1,b(_);return}await S.replace("/auth/dingtalk/email-completion?redirect="+encodeURIComponent(_));return}if(d.error==="invitation_required"){y.value=!0,v.value=!1,b(_);return}if(pe(d)){b(_);return}if(_e(d),g.value!=="none"){v.value=!1,b(_);return}if(ae.value&&Re(d)){w.value=!0,v.value=!1,b(_);return}await me(d,_)}catch(d){he(),H.value=I(d,n("auth.loginFailed")),v.value=!1}}),(e,t)=>(h(),$e(s(et),null,{default:we(()=>[o("div",nt,[o("div",ot,[o("h2",st,l(s(n)("auth.dingtalk.callbackTitle")),1),o("p",it,l(v.value?s(n)("auth.dingtalk.callbackProcessing"):s(n)("auth.dingtalk.callbackHint")),1)]),xe(je,{name:"fade"},{default:we(()=>[y.value||w.value||de.value||ce.value||ve.value||j.value?(h(),p("div",rt,[ae.value&&(V.value||P.value)?(h(),p("div",lt,[o("div",ut,[o("div",ct,[o("p",dt,l(s(n)("auth.oauth
2Flow.profileDetailsTitle",{providerName:s(N)})),1),o("p",vt,l(s(n)("auth.oauthFlow.profileDetailsDescription",{providerName:s(N)})),1)]),V.value?(h(),p("label",ht,[R(o("input",{"onUpdate:modelValue":t[0]||(t[0]=a=>W.value=a),type:"checkbox",class:"mt-1 h-4 w-4"},null,512),[[Ae,W.value]]),o("span",gt,[o("span",_t,l(s(n)("auth.oauthFlow.useDisplayName")),1),o("span",pt,l(V.value),1)])])):D("",!0),P.value?(h(),p("label",ft,[R(o("input",{"onUpdate:modelValue":t[1]||(t[1]=a=>$.value=a),type:"checkbox",class:"mt-1 h-4 w-4"},null,512),[[Ae,$.value]]),o("img",{src:P.value,alt:s(n)("auth.oauthFlow.avatarAlt",{providerName:s(N)}),class:"h-10 w-10 rounded-full border border-gray-200 object-cover dark:border-dark-600"},null,8,mt),o("span",bt,[o("span",kt,l(s(n)("auth.oauthFlow.useAvatar")),1),o("span",yt,l(P.value),1)])])):D("",!0)])])):D("",!0),y.value?(h(),p(O,{key:1},[o("p",wt,l(s(n)("auth.dingtalk.invitationRequired")),1),o("div",null,[R(o("input",{"onUpdate:modelValue":t[2]||(t[2]=a=>L.value=a),type:"text",class:"input w-full",placeholder:s(n)("auth.invitationCodePlaceholder"),disabled:i.value,onKeyup:Q(be,["enter"])},null,40,xt),[[J,L.value]])]),o("button",{class:"btn btn-primary w-full",disabled:i.value||!L.value.trim(),onClick:be},l(i.value?s(n)("auth.dingtalk.completing"):s(n)("auth.dingtalk.completeRegistration")),9,At)],64)):w.value?(h(),p(O,{key:2},[o("p",Ct,l(s(n)("auth.oauthFlow.reviewProfileBeforeContinue",{providerName:s(N)})),1),o("button",{class:"btn btn-primary w-full",disabled:i.value,onClick:Me},l(i.value?s(n)("common.processing"):s(n)("auth.continue")),9,Tt)],64)):de.value?(h(),p("div",Ft,[o("div",St,[o("div",Pt,[o("p",qt,l(s(n)("auth.oauthFlow.chooseHowToContinue")),1),o("p",Nt,l(x.value?s(n)("auth.oauthFlow.suggestedEmail",{email:x.value}):s(n)("auth.oauthFlow.chooseAccountActionHint")),1)]),o("div",Dt,[o("button",{class:"btn btn-secondary w-full",disabled:i.value,onClick:t[3]||(t[3]=a=>se())},l(s(n)("auth.oauthFlow.bindExistingAccount")),9,Rt),o("button",{class:"btn btn-primary w-full",disabled:i.value,onClick:fe},l(s(n)("auth.oauthFlow.createNewAccount")),9,Et)])])])):ce.value?(h(),p(O,{key:4},[o("p",Lt,l(s(n)("auth.oauthFlow.createAccountHint")),1),xe(tt,{"test-id-prefix":"dingtalk","initial-email":x.value,"is-submitting":i.value,"error-message":m.value,onSubmit:Ue,onSwitchToBind:se},null,8,["initial-email","is-submitting","error-message"])],64)):ve.value?(h(),p(O,{key:5},[o("p",Bt,l(s(n)("auth.oauthFlow.bindLoginHint",{providerName:s(N)})),1),o("div",Vt,[R(o("input",{"onUpdate:modelValue":t[4]||(t[4]=a=>f.value=a),"data-testid":"dingtalk-bind-login-email",type:"email",class:"input w-full",placeholder:s(n)("auth.emailPlaceholder"),disabled:i.value,onKeyup:Q(ie,["enter"])},null,40,Mt),[[J,f.value]]),R(o("input",{"onUpdate:modelValue":t[5]||(t[5]=a=>A.value=a),"data-testid":"dingtalk-bind-login-password",type:"password",class:"input w-full",placeholder:s(n)("auth.passwordPlaceholder"),disabled:i.value,onKeyup:Q(ie,["enter"])},null,40,Ut),[[J,A.value]]),o("button",{"data-testid":"dingtalk-bind-login-submit",class:"btn btn-primary w-full",disabled:i.value||!f.value.trim()||!A.value,onClick:ie},l(i.value?s(n)("common.processing"):s(n)("auth.oauthFlow.logInAndBind")),9,It),F.value?(h(),p("button",{key:0,class:"btn btn-secondary w-full",disabled:i.value,onClick:fe},l(s(n)("auth.oauthFlow.useDifferentEmail")),9,Kt)):D("",!0)])],64)):j.value?(h(),p(O,{key:6},[o("p",Ot,l(s(n)("auth.oauthFlow.totpHint",{providerName:s(N),account:ne.value||s(n)("auth.oauthFlow.yourAccount")})),1),o("div",zt,[R(o("input",{"onUpdate:modelValue":t[6]||(t[6]=a=>q.value=a),"data-testid":"dingtalk-bind-login-totp",type:"text",inputmode:"numeric",maxlength:"6",class:"input w-full",placeholder:"123456",disabled:i.value,onKeyup:Q(ke,["enter"])},null,40,Ht),[[J,q.value]]),o("button",{"data-testid":"dingtalk-bind-login-totp-submit",class:"btn btn-primary w-full",disabled:i.value||q.value.trim().length!==6,onClick:ke},l(i.value?s(n)("common.processing"):s(n)("auth.oauthFlow.verifyAndContinue")),9,Wt)])],64)):D("",!0)])):D("",!0)]),_:1})])]),_:1}))}}),sa=Qe($t,[["__scopeId","data-v-f236ebf6"]]);export{sa 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.