1import{BaseView as e}from"#views/base-view.8933a16d.js";import{Globals as i}from"#utils/globals.ad6d1f6a.js";import{ToastView as t}from"#views/toast-view.0c1463a5.js";import{GoogleLoginModel as o}from"#models/google-login-model.ae13b013.js";import{Onboarding as n}from"#utils/onboarding.c50968bc.js";import{AccountWelcomeView as r}from"#views/account-welcome-view.c066e63a.js";class a extends e{constructor(e){super(e)}connectedCallback(){this.query("form").addEventListener("submit",this.onSubmit.bind(this)),this.query("#magic-link-btn").addEventListener("click",this.sendMagicLink.bind(this)),this.initGoogleSignIn(),this.forwardActionToSignup()}forwardActionToSignup(){let e=new URLSearchParams(window.location.search).get("action");if(!e)return;let i=this.query(".signup a");i&&i.setAttribute("href",`/signup?action=${encodeURIComponent(e)}`)}initGoogleSignIn(){if(!i.GOOGLE_CLIENT_ID)return;let e=document.createElement("script");e.src="https://accounts.google.com/gsi/client",e.async=!0,e.defer=!0,e.onload=()=>{google.accounts.id.initialize({client_id:i.GOOGLE_CLIENT_ID,callback:this.onGoogleSignIn.bind(this)}),google.accounts.id.renderButton(this.query("#google-signin-btn"),{type:"standard",theme:"outline",size:"large",text:"signin_with",width:300})},document.head.appendChild(e)}async onGoogleSignIn(e){try{let i=new o({googleIdToken:e.credential}),n=await i.login();if(n){if(!0===n.isFirstLogin)return void(await this.onboard()&&this.showWelcome());!1!==n.isFirstLogin&&console.error("UPSx login response carried no usable isFirstLogin flag; treating as an existing account",n),this.redirect(this.getRedirectUrl())}else t.show("There was a problem signing in with Google. Please try again.",{type:"error"})}catch(e){t.show("There was a problem signing in with Google. Please try again.",{type:"error"}),console.error(e)}}async onboard(){try{return await n.run({authUrl:this.dataset.url}),!0}catch(e){return console.error(e),t.show("There was a problem. Please try again.",{type:"error"}),!1}}showWelcome(){r.show((()=>this.redirect(this.getRedirectUrl())))}redirect(e){window.location=e}getRedirectUrl(){return new URLSearchParams(window.location.search).get("action")||"/"}onSubmit(e){return e.preventDefault(),this.login(),!1}async login(){let e=this.query("#email").value.trim(),i=this.query("#password").value.trim();if(""!==e&&""!==i){this.query("button").disabled=!0;try{200===(await fetch(`${this.query("form").action}`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({email:e,password:i})})).status?this.redirect(this.getRedirectUrl()):t.show("Incorrect email or password. Please try again.",{type:"error"})}catch(e){t.show("There was a problem. Please try again.",{type:"error"}),console.error(e)}finally{this.query("button").disabled=!1}}}async sendMagicLink(){let e=this.query("#email").value.trim();if(""===e)return void t.show("Please enter your email address first.",{type:"error"});let o=this.query("#magic-link-btn");o.disabled=!0;let n=`${window.location.origin}/passwordless-login`;try{let r=await fetch(`${i.AUTH_URL}/passwordless/email/magic-link?passwordless_login_url=${encodeURIComponent(n)}&platform=wu`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e})});if(200===r.status)t.show("We just sent a login link to your email. Check your inbox and click the link to sign in.");else{let e="There was a problem. Please try again.";try{let i=await r.json();938===i.messageCode?e="No account found for this email. Please sign up or try a different email.":400===r.status&&i.message&&(e="Please enter a valid email address.")}catch(e){}t.show(e,{type:"error"}),o.disabled=!1}}catch(e){t.show("There was a problem. Please try again.",{type:"error"}),o.disabled=!1,console.error(e)}}get html(){return`\n <login-form-wc data-url="${i.AUTH_URL}">\n <form action="${i.AUTH_URL}/login">\n <h1>Log In</h1>\n <div class="input-labels">\n <label for="email">Email</label>\n </div>\n <input type="email" id="email" />\n <div class="input-labels">\n <label for="password">Password</label>\n <a href="/forgot-password" tabindex="-1">Forgot Password?</a>\n </div>\n <input type="password" id="password" />\n <div class="button-row">\n <button class="blue">Log In With Password</button>\n <button type="button" id="magic-link-btn" class="outline">Send Magic Link</button>\n </div>\n <div class="divider">or</div>\n <div class="instructions">\n By continuing, you confirm that you have read and agree to our <a href="https://weather.com/privacy/terms-of-use" target="_blank">Terms of Use</a> and <a href="https://weather.com/privacy/privacy-policy" target="_blank">Privacy Policy</a>.\n </div>\n <div id="google-signin-btn"></div>\n <div class="signup">Don't have an account? <a href="/signup">Sign up</a></div>\n </form>\n </login-form-wc>\n `}}a.register("login-form-wc");export{a as LoginFormView};
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.