1import{i as e,r as t,a,d as o,j as n,F as s,e as r,N as i,t as l,a9 as c,b as d,z as u,L as p,a1 as m,D as g,m as h,h as f,S as w,n as v}from"./index-r-KClxtY.js";import{F as b}from"./Form-BVeuzoPa.js";import y from"./Toast-DuPXoAKZ.js";import{S as x}from"./SocialLogin-CObhtTaE.js";import{H as _}from"./HelpText-djUlMn1P.js";/* empty css *//* empty css */const j=c=>{const d=c.texts,u=c.loginChallenge,p=e(),m=c.setVerifiedUsername,g=c.setLoader,[h,f]=t.useState(),[w,v]=t.useState(),{addNotice:y}=a(),x=e=>{if(!h)return console.log("captchaToken non presente");if(!w)return console.log("identityToken non presente");let t={...e,"g-recaptcha-response":h,rcpt:w};return g("loading"),r("/api/verify/username",t).then((t=>{if(403==(null==t?void 0:t.status)&&y({title:l.notices.error_user,type:i.error,timeout:5e3}),!1===t.data.success){const t=u?"/user/register?login_challenge=".concat(u):"/user/register";m("failed"),p(t,{state:{username:e.username}})}else!0===t.data.success&&m(e.username)})).catch((e=>{var t,a,o;const n=(null==(o=null==(a=null==(t=e.response)?void 0:t.data)?void 0:a.status)?void 0:o.message)||l.notices.generic_error;y({title:n,type:i.error,timeout:5e3})})).finally((()=>{g("loaded")}))},_={inputs:{username:{label:d.email_username,tag:"input",className:"username",type:"text",placeholder:d.email_username,regOptions:{required:{value:!0,message:d.validation.required}}}},defaultValues:{username:c.email||""}},j=o({defaultValues:_.defaultValues,mode:"onChange",criteriaMode:"all"});return t.useEffect((()=>{h&&w&&j&&c.email&&j.handleSubmit(x)()}),[j,c.email,h,w]),n.jsx("div",{className:"EmailForm-wrapper PageForm-wrapper",children:n.jsx(s,{...j,children:n.jsx(b,{schema:_,name:"EmailForm",onSubmit:x,cta:c.cta,methods:j,alertMessage:d.alertMessage,recaptcha:!0,setToken:f,setIdentityToken:v,actionName:"acc_username"})})})},S=c=>{var d;const u=c.texts,p=c.loginChallenge,m=null!=(d=c.username)?d:"",g=e(),h=c.setLoader,{addNotice:f}=a(),[w,v]=t.useState(),[y,x]=t.useState(),_={inputs:{username:{label:u.email_username,tag:"input",className:"username",type:"text",placeholder:u.email_username,disabled:!0,editable:!0,activateText:u.activate_text,regOptions:{required:{value:!0,message:u.validation.required}}},password:{label:"Password",tag:"input",className:"password",type:"password",placeholder:"Password",regOptions:{required:{value:!0,message:u.validation.required}}}},defaultValues:{username:m,password:""}},j=o({defaultValues:_.defaultValues,mode:"onChange",criteriaMode:"all"});return n.jsx("div",{className:"LoginForm-wrapper PageForm-wrapper",children:n.jsx(s,{...j,children:n.jsx(b,{schema:_,name:"LoginForm",onSubmit:e=>{if(!w)return console.log("captchaToken non presente");if(!y)return console.log("identityToken non presente");let t={...e,"g-recaptcha-response":w,rcpt:y,login_challenge:p};return h("loading"),r("/api/verify/credentials",t).then((e=>{!0===e.data.success&&e.data.redirect_uri&&(h("loaded"),window.location.href=e.data.redirect_uri)})).catch((e=>{if(e.response&&e.response.data){const t=e.response.data;switch(t.status&&console.warn(t.status.code,t.status.message),e.response.status){case 401:f({title:l.notices.invalid_credentials,type:i.error,timeout:5e3}),h("loaded");break;case 403:if("ERR_INVALID_CAPTCHA"===t.status.code){f({title:t.status.message,type:i.error,timeout:5e3}),h("loaded");break}f({title:l.notices.access_denied,type:i.error,timeout:5e3}),h("loaded");break;case 404:g("/sso/login");break;case 504:f({title:l.notices.generic_error,type:i.error,timeout:5e3}),h("loaded");break;default:console.log(e.response.status)}}})).finally((()=>{h("loaded")}))},cta:c.cta,methods:j,alertMessage:u.alertMessage,recaptcha:!0,setToken:v,setIdentityToken:x,actionName:"acc_credentials"})})})},k=({clientId:e,onAuthenticated:a})=>{const[o,s]=t.useState(""),r=e=>{const t=e.detail;if(!t)return s("C'è stato un errore durante la comunicazione con Apple, riprova più tardi"),!1;const o={source:"apple",token:t.authorization.code};a(o)},i=e=>{if(e.detail&&-1!=["popup_closed_by_user"].indexOf(e.detail.error))return!0;s("C'è stato un errore durante l'autenticazione Apple, riprova più tardi"),console.error("Autenticazione Apple fallita con errore",e)},l=()=>{AppleID.auth.init({clientId:e,scope:"email",redirectURI:location.origin+"/u
1ser/social/apple",state:""+Math.round(1e14*Math.random()),nonce:""+Math.round(1e7*Math.random()),usePopup:!0}),document.addEventListener("AppleIDSignInOnSuccess",r),document.addEventListener("AppleIDSignInOnFailure",i)};return t.useEffect((()=>(c("https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/it_IT/appleid.auth.js").then(l),()=>{document.removeEventListener("AppleIDSignInOnSuccess",r),document.removeEventListener("AppleIDSignInOnFailure",i)})),[]),n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"SocialLoginItem SocialLoginApple-wrapper",children:n.jsx("div",{id:"appleid-signin","data-mode":"logo-only","data-logo-size":"large","data-color":"white","data-border":"false","data-type":"sign in"})}),""!==o&&n.jsx(y,{label:o})]})},E=({clientId:e,onAuthenticated:a})=>{const[o,s]=t.useState(""),r=e=>{"connected"===e.status?(console.debug("FacebookLogin, user is already logged and authenticated!",e),l(e.authResponse.accessToken).then((e=>{console.debug("FacebookLogin, and this are his infos",e.userPayload)}))):"not_authorized"===e.status&&console.debug("FacebookLogin, user is already logged but not authenticated!",e)},i=()=>{FB.init({appId:e,cookie:!0,status:!0,xfbml:!1,version:"v19.0"}),FB.getLoginStatus(r)},l=e=>new Promise((t=>{FB.api("/me","get",{fields:"id,name,email,birthday,gender,location"},(a=>{var o,n;const s={source:"facebook",token:e,email:a.email},r={avatar:a.avatar||"https://graph.facebook.com/"+a.id+"/picture",name:a.name?a.name.replace(/ [^ ]+$/,""):"",surname:a.name?a.name.replace(/^.+ ([^ ]+)/,"$1"):"",email:a.email,location:"string"==typeof a.location?a.location:null!=(n=null==(o=a.location)?void 0:o.name)?n:""};t({authData:s,userPayload:r})}))}));return t.useEffect((()=>(c("https://connect.facebook.net/it_IT/sdk.js").then(i),()=>{})),[]),n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"SocialLoginItem SocialLoginFacebook-wrapper",children:n.jsx("input",{type:"button",id:"facebook_login",onClick:()=>{FB.login((e=>{e.authResponse?l(e.authResponse.accessToken).then((e=>{a(e.authData,e.userPayload)})).catch((e=>{console.error("Facebook login error",e),s("Si è verificato un errore nel recupero delle informazioni")}
1)):-1===["not_authorized","access_denied","unknown"].indexOf(e.status)&&s("Si è verificato un errore nel contattare il social network")}),{scope:"email"})},value:"Accedi con Facebook"})}),""!==o&&n.jsx(y,{label:o})]})};new TextEncoder;const I=new TextDecoder;class L extends Error{static get code(){return"ERR_JOSE_GENERIC"}constructor(e){var t;super(e),this.code="ERR_JOSE_GENERIC",this.name=this.constructor.name,null==(t=Error.captureStackTrace)||t.call(Error,this,this.constructor)}}class T extends L{constructor(){super(...arguments),this.code="ERR_JWT_INVALID"}static get code(){return"ERR_JWT_INVALID"}}const N=e=>{let t=e;t instanceof Uint8Array&&(t=I.decode(t)),t=t.replace(/-/g,"+").replace(/_/g,"/").replace(/\s/g,"");try{return(e=>{const t=atob(e),a=new Uint8Array(t.length);for(let o=0;o<t.length;o++)a[o]=t.charCodeAt(o);return a})(t)}catch(a){throw new TypeError("The input to be decoded is not correctly encoded.")}};function F(e){if("string"!=typeof e)throw new T("JWTs must use Compact JWS serialization, JWT must be a string");const{1:t,length:a}=e.split(".");if(5===a)throw new T("Only JWTs using Compact JWS serialization can be decoded");if(3!==a)throw new T("Invalid JWT");if(!t)throw new T("JWTs must contain a payload");let o,n;try{o=N(t)}catch(s){throw new T("Failed to base64url decode the payload")}try{n=JSON.parse(I.decode(o))}catch(s){throw new T("Failed to parse the decoded payload as JSON")}if(!function(e){if("object"!=typeof(t=e)||null===t||"[object Object]"!==Object.prototype.toString.call(e))return!1;var t;if(null===Object.getPrototypeOf(e))return!0;let a=e;for(;null!==Object.getPrototypeOf(a);)a=Object.getPrototypeOf(a);return Object.getPrototypeOf(e)===a}(n))throw new T("Invalid JWT Claims Set");return n}const A=({clientId:e,onAuthenticated:a})=>{const[o,s]=t.useState(""),r=t.useRef(null),{domain:i}=d(),l=()=>{clearTimeout(o),s(setTimeout((()=>{p()}),200).toString())},u=()=>{google.accounts.id.initialize({client_id:e,callback:async e=>{const t=F(e.credential);console.log("Response selected by: "+e.select_by);const o={source:"google",select_by:e.select_by,sub:t.sub,token:e.credential,email:t.email},n={avatar:t.picture,name:t.given_name,surname:t.family_name,email:t.email};a(o,n)},login_uri:"https://".concat(window.location.host,"/api/user/social/login/google"),ux_mode:"redirect"}),p(),window.addEventListener("resize",l)},p=()=>{var e;const t=null==(e=r.current)?void 0:e.clientWidth;google.accounts.id.renderButton(r.current,{theme:"outline",size:"large",text:"continue_with",width:Math.min(Math.floor(null!=t?t:400),400)}),google.accounts.id.prompt()};return t.useEffect((()=>(c("https://accounts.google.com/gsi/client").then(u),()=>{clearTimeout(o),window.removeEventListener("resize",l),"undefined"!=typeof google&&google.accounts&&google.accounts.id&&google.accounts.id.cancel()})),[]),n.jsxs("div",{className:"SocialLoginItem SocialLoginGoogle-wrapper",children:[n.jsx("div",{id:"google_login",ref:r}),n.jsx("div",{className:"google-overlay",children:n.jsx("span",{children:"Continua con Google"})})]})},O=()=>{const{addNotice:e}=a(),o=u(),[s,c]=t.useState(!1),d=(t,a)=>{c(!0),m(a),t.login_challenge=t.login_challenge||g("login_challenge",o.search)||"",r("/api/user/social/login",t).then((t=>{c(!1),!0===t.data.success?window.location.replace(t.data.redirect_uri):e({title:l.notices.generic_error,type:i.error,timeout:5e3})}))};return n.jsxs(n.Fragment,{children:[s&&n.jsx(p,{spinner:!0,labelPrimary:"",labelSecondary:""}),n.jsxs("div",{className:"SocialLogin-wrapper",children:[n.jsx(A,{clientId:"674805212279-g965g1h3ffofksdpun24pup4q7a0f3op.apps.googleusercontent.com",onAuthenticated:d}),n.jsx(E,{clientId:"680590016226629",onAuthenticated:d}),n.jsx(k,{clientId:"3F966LAK22",onAuthenticated:d}),n.jsx(x,{})]})]})},C=e=>n.jsx("div",{className:"Separator-wrapper",children:n.jsx("span",{children:e.label})}),R=()=>{const[o,s]=t.useState(""),[r,c]=t.useState(""),[d,u]=t.useState(!1),{loginChallenge:m,prefilledEmailStored:g,iframeLogin:b,popupUrl:y}=h(),x=l.sso,k=l.common,{user:E}=f(),I=e(),{auth:L,setAuth:T}=w(),{addNotice:N}=a();return t.useEffect((()=>{E&&I("/dashboard")}),[E]),t.useEffect((()=>{(null==L?void 0:L.id_token)&&(null==L?void 0:L.redirect_uri)&&window.location.replace(L.redirect_uri)}),[L]),t.useEffect((()=>
1{if(!b||!y||d)return;window.open(y,"sso-login-popup","popup=yes,width=520,height=760,noopener=no,noreferrer=no")?(u(!0),c("loading")):N({title:l.notices.no_popup,type:i.error,timeout:1e4})}),[b,d,y]),t.useEffect((()=>{if(!b)return;const e=e=>{var t;e.origin===window.location.origin&&"sso-login-result"===(null==(t=e.data)?void 0:t.type)&&(e.data.success?T(e.data.auth):(c(""),N({title:e.data.error||l.notices.invalid_session,type:i.error,timeout:5e3})))};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}}),[b,N,T]),n.jsx("div",{className:"Login-wrapper route-wrapper",children:n.jsxs("div",{className:"auth-wrapper",children:[n.jsx("h1",{className:"page-title centered",children:x.titles.login}),"loading"==r&&n.jsx(p,{}),!b&&!o&&n.jsx(j,{cta:k.forms.continueCta,texts:k.forms,setVerifiedUsername:s,setLoader:c,loginChallenge:m||"",email:g}),!b&&o&&"failed"!==o&&n.jsx(S,{username:o,cta:k.forms.continueCta,texts:k.forms,setLoader:c,loginChallenge:m||""}),!b&&o&&"failed"!==o&&n.jsx(v,{className:"lost-password",to:"/user/lost-password",children:x.lost_password}),!b&&n.jsx(C,{label:x.separator}),!b&&n.jsx(O,{}),n.jsx(_,{label:k.help.label,url:k.help.url,cta:k.help.cta})]})})};export{R 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.