"use strict";(self["webpackChunkplatypush"]=self["webpackChunkplatypush"]||[]).push([[6966],{3787:function(e,t,s){s.r(t),s.d(t,{default:function(){return A}});var r=s(641),a=s(33);const i={key:1,class:"login-container"},n={class:"row"},o=["type","disabled"],l={class:"row"},d=["type","disabled"],u={key:0,class:"row"},c=["disabled"],h={key:1,class:"row"},p=["disabled"],g={class:"row buttons"},k=["disabled"],m={key:2,class:"auth-error"};function y(e,t,s,y,b,f){const w=(0,r.g2)("Loading");return b.initialized?((0,r.uX)(),(0,r.CE)("div",i,[b.isAuthenticated?(0,r.Q3)("",!0):((0,r.uX)(),(0,r.CE)("form",{key:0,class:"login",method:"POST",onSubmit:t[0]||(t[0]=(...e)=>f.submitForm&&f.submitForm(...e))},[t[1]||(t[1]=(0,r.Lk)("div",{class:"header"},[(0,r.Lk)("span",{class:"logo"},[(0,r.Lk)("img",{src:"/logo.svg",alt:"logo"})]),(0,r.Lk)("span",{class:"text"},"Platypush")],-1)),(0,r.Lk)("div",n,[(0,r.Lk)("label",null,[(0,r.Lk)("input",{type:b.requires2fa?"hidden":"text",name:"username",disabled:b.authenticating,placeholder:"Username",ref:"username"},null,8,o)])]),(0,r.Lk)("div",l,[(0,r.Lk)("label",null,[(0,r.Lk)("input",{type:b.requires2fa?"hidden":"password",name:"password",disabled:b.authenticating,placeholder:"Password"},null,8,d)])]),b.requires2fa?((0,r.uX)(),(0,r.CE)("div",u,[(0,r.Lk)("label",null,[(0,r.Lk)("input",{type:"text",name:"code",disabled:b.authenticating,placeholder:"2FA code",ref:"code"},null,8,c)])])):(0,r.Q3)("",!0),s.register?((0,r.uX)(),(0,r.CE)("div",h,[(0,r.Lk)("label",null,[(0,r.Lk)("input",{type:"password",name:"confirm_password",disabled:b.authenticating,placeholder:"Confirm password"},null,8,p)])])):(0,r.Q3)("",!0),(0,r.Lk)("div",g,[(0,r.Lk)("button",{type:"submit",class:(0,a.C4)(["btn btn-primary",{loading:b.authenticating}]),disabled:b.authenticating},[b.authenticating?((0,r.uX)(),(0,r.Wv)(w,{key:0})):(0,r.Q3)("",!0),(0,r.eW)(" "+(0,a.v_)(s.register?"Register":"Login"),1)],10,k)]),t[2]||(t[2]=(0,r.Lk)("div",{class:"row pull-right"},[(0,r.Lk)("label",{class:"checkbox"},[(0,r.Lk)("input",{type:"checkbox",name:"remember"}),(0,r.eW)("  Keep me logged in on this device   ")])],-1)),b.authError?((0,r.uX)(),(0,r.CE)("div",m,(0,a.v_)(b.authError),1)):(0,r.Q3)("",!0)],32))])):((0,r.uX)(),(0,r.Wv)(w,{key:0}))}var b=s(9828),f=s(2002),w=s(4335),L={name:"Login",mixins:[f.A],components:{Loading:b.A},props:{register:{type:Boolean,required:!1,default:!1}},computed:{redirect(){return this.$route.query.redirect?.length?this.$route.query.redirect:"/"}},data(){return{authError:null,authenticating:!1,isAuthenticated:!1,initialized:!1,requires2fa:!1}},methods:{async submitForm(e){e.preventDefault();const t=e.target,s=new FormData(t),r="/auth?type="+(this.register?"register":"login");if(this.register&&s.get("password")!==s.get("confirm_password"))this.authError="Passwords don't match";else{this.authError=null;try{const e=await w.A.post(r,s),t=e?.data?.session_token;if(t){const s=e?.data?.expires_at?new Date(e.data.expires_at):null;this.isAuthenticated=!0,this.setCookie("session_token",t,{expires:s}),window.location.href=e.redirect||this.redirect}else this.authError="Invalid credentials"}catch(e){"MISSING_OTP_CODE"===e?.response?.data?.error?(this.requires2fa=!0,this.$nextTick((()=>{this.$refs.code?.focus()}))):(this.authError=e?.response?.data?.message||e?.response?.data?.error||e?.message||e?.toString(),401===e?.response?.status?this.authError=this.authError||"Invalid credentials":(this.authError=this.authError||"An error occurred while processing the request",e?.response?console.error(e.response.status,e.response.data):console.error(e)))}}},async checkAuth(){try{const e=await w.A.get("/auth");e.data.session_token&&(this.isAuthenticated=!0,window.location.href=e.redirect||this.redirect)}catch(e){this.isAuthenticated=!1}finally{this.initialized=!0}}},async created(){await this.checkAuth()},async mounted(){this.$nextTick((()=>{this.$refs.username?.focus()}))}},v=s(6262);const E=(0,v.A)(L,[["render",y],["__scopeId","data-v-60300e68"]]);var A=E}}]);
//# sourceMappingURL=login.de738cfb.js.map