"use strict";(self["webpackChunkplatypush"]=self["webpackChunkplatypush"]||[]).push([[6966,8224],{20992:function(e,t,s){s.r(t),s.d(t,{default:function(){return C}});var r=s(20641),i=s(90033);const a={key:1,class:"login-container"},n={class:"row"},o=["type","disabled"],d={class:"row"},l=["type","disabled"],c={key:0,class:"row"},u=["disabled"],h={key:1,class:"row"},p=["disabled"],k={class:"row buttons"},g=["disabled"],f={key:2,class:"auth-error"};function m(e,t,s,m,y,b){const w=(0,r.g2)("Loading");return y.initialized?((0,r.uX)(),(0,r.CE)("div",a,[y.isAuthenticated?(0,r.Q3)("",!0):((0,r.uX)(),(0,r.CE)("form",{key:0,class:"login",method:"POST",onSubmit:t[0]||(t[0]=(...e)=>b.submitForm&&b.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:y.requires2fa?"hidden":"text",name:"username",disabled:y.authenticating,placeholder:"Username",ref:"username"},null,8,o)])]),(0,r.Lk)("div",d,[(0,r.Lk)("label",null,[(0,r.Lk)("input",{type:y.requires2fa?"hidden":"password",name:"password",disabled:y.authenticating,placeholder:"Password"},null,8,l)])]),y.requires2fa?((0,r.uX)(),(0,r.CE)("div",c,[(0,r.Lk)("label",null,[(0,r.Lk)("input",{type:"text",name:"code",disabled:y.authenticating,placeholder:"2FA code",ref:"code"},null,8,u)])])):(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:y.authenticating,placeholder:"Confirm password"},null,8,p)])])):(0,r.Q3)("",!0),(0,r.Lk)("div",k,[(0,r.Lk)("button",{type:"submit",class:(0,i.C4)(["btn btn-primary",{loading:y.authenticating}]),disabled:y.authenticating},[y.authenticating?((0,r.uX)(),(0,r.Wv)(w,{key:0})):(0,r.Q3)("",!0),(0,r.eW)(" "+(0,i.v_)(s.register?"Register":"Login"),1)],10,g)]),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)),y.authError?((0,r.uX)(),(0,r.CE)("div",f,(0,i.v_)(y.authError),1)):(0,r.Q3)("",!0)],32))])):((0,r.uX)(),(0,r.Wv)(w,{key:0}))}s(74423);var y=s(81350),b=s(91387),w=s(85975),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,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,i=e?.data?.csrf_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}),i?this.setCookie("csrf_token",i,{expires:s}):this.deleteCookie("csrf_token"),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,403].includes(e?.response?.status)?(this.authError=this.authError||"Invalid credentials",this.deleteCookie("session_token"),this.deleteCookie("csrf_token")):(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");if(e.data.session_token){const t=e?.data?.expires_at?new Date(e.data.expires_at):null;this.isAuthenticated=!0,e.data.csrf_token?this.setCookie("csrf_token",e.data.csrf_token,{expires:t}):this.deleteCookie("csrf_token"),window.location.href=e.redirect||this.redirect}}catch(e){this.isAuthenticated=!1,this.deleteCookie("csrf_token")}finally{this.initialized=!0}}},async created(){await this.checkAuth()},async mounted(){this.$nextTick(()=>{this.$refs.username?.focus()})}},L=s(66262);const _=(0,L.A)(v,[["render",m],["__scopeId","data-v-76679006"]]);var C=_},90655:function(e,t,s){s.r(t),s.d(t,{default:function(){return l}});var r=s(20641);function i(e,t,s,i,a,n){const o=(0,r.g2)("Login");return(0,r.uX)(),(0,r.Wv)(o,{register:!0})}var a=s(20992),n={name:"Register",mixins:[a["default"]],components:{Login:a["default"]},props:{register:{type:Boolean,required:!1,default:!0}}},o=s(66262);const d=(0,o.A)(n,[["render",i]]);var l=d}}]);
//# sourceMappingURL=register.e375c1d1.js.map