"use strict";(self["webpackChunkplatypush"]=self["webpackChunkplatypush"]||[]).push([[8224,6966],{3787:function(e,t,r){r.r(t),r.d(t,{default:function(){return A}});var s=r(641),a=r(33);const i={key:1,class:"login-container"},n={class:"row"},o=["type","disabled"],u={class:"row"},d=["type","disabled"],l={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 f(e,t,r,f,y,b){const w=(0,s.g2)("Loading");return y.initialized?((0,s.uX)(),(0,s.CE)("div",i,[y.isAuthenticated?(0,s.Q3)("",!0):((0,s.uX)(),(0,s.CE)("form",{key:0,class:"login",method:"POST",onSubmit:t[0]||(t[0]=(...e)=>b.submitForm&&b.submitForm(...e))},[t[1]||(t[1]=(0,s.Lk)("div",{class:"header"},[(0,s.Lk)("span",{class:"logo"},[(0,s.Lk)("img",{src:"/logo.svg",alt:"logo"})]),(0,s.Lk)("span",{class:"text"},"Platypush")],-1)),(0,s.Lk)("div",n,[(0,s.Lk)("label",null,[(0,s.Lk)("input",{type:y.requires2fa?"hidden":"text",name:"username",disabled:y.authenticating,placeholder:"Username",ref:"username"},null,8,o)])]),(0,s.Lk)("div",u,[(0,s.Lk)("label",null,[(0,s.Lk)("input",{type:y.requires2fa?"hidden":"password",name:"password",disabled:y.authenticating,placeholder:"Password"},null,8,d)])]),y.requires2fa?((0,s.uX)(),(0,s.CE)("div",l,[(0,s.Lk)("label",null,[(0,s.Lk)("input",{type:"text",name:"code",disabled:y.authenticating,placeholder:"2FA code",ref:"code"},null,8,c)])])):(0,s.Q3)("",!0),r.register?((0,s.uX)(),(0,s.CE)("div",h,[(0,s.Lk)("label",null,[(0,s.Lk)("input",{type:"password",name:"confirm_password",disabled:y.authenticating,placeholder:"Confirm password"},null,8,p)])])):(0,s.Q3)("",!0),(0,s.Lk)("div",g,[(0,s.Lk)("button",{type:"submit",class:(0,a.C4)(["btn btn-primary",{loading:y.authenticating}]),disabled:y.authenticating},[y.authenticating?((0,s.uX)(),(0,s.Wv)(w,{key:0})):(0,s.Q3)("",!0),(0,s.eW)(" "+(0,a.v_)(r.register?"Register":"Login"),1)],10,k)]),t[2]||(t[2]=(0,s.Lk)("div",{class:"row pull-right"},[(0,s.Lk)("label",{class:"checkbox"},[(0,s.Lk)("input",{type:"checkbox",name:"remember"}),(0,s.eW)("  Keep me logged in on this device   ")])],-1)),y.authError?((0,s.uX)(),(0,s.CE)("div",m,(0,a.v_)(y.authError),1)):(0,s.Q3)("",!0)],32))])):((0,s.uX)(),(0,s.Wv)(w,{key:0}))}var y=r(9828),b=r(2002),w=r(4335),v={name:"Login",mixins:[b.A],components:{Loading:y.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,r=new FormData(t),s="/auth?type="+(this.register?"register":"login");if(this.register&&r.get("password")!==r.get("confirm_password"))this.authError="Passwords don't match";else{this.authError=null;try{const e=await w.A.post(s,r),t=e?.data?.session_token;if(t){const r=e?.data?.expires_at?new Date(e.data.expires_at):null;this.isAuthenticated=!0,this.setCookie("session_token",t,{expires:r}),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()}))}},L=r(6262);const E=(0,L.A)(v,[["render",f],["__scopeId","data-v-60300e68"]]);var A=E},3036:function(e,t,r){r.r(t),r.d(t,{default:function(){return d}});var s=r(641);function a(e,t,r,a,i,n){const o=(0,s.g2)("Login");return(0,s.uX)(),(0,s.Wv)(o,{register:!0})}var i=r(3787),n={name:"Register",mixins:[i["default"]],components:{Login:i["default"]},props:{register:{type:Boolean,required:!1,default:!0}}},o=r(6262);const u=(0,o.A)(n,[["render",a]]);var d=u}}]);
//# sourceMappingURL=register.558a674a.js.map