"use strict";(self["webpackChunkplatypush"]=self["webpackChunkplatypush"]||[]).push([[4535],{8137:function(e,t,s){s.r(t),s.d(t,{default:function(){return A}});var r=s(6252),i=s(3577);const a=e=>((0,r.dD)("data-v-1b764fc6"),e=e(),(0,r.Cn)(),e),n={key:1,class:"login-container"},o=a((()=>(0,r._)("div",{class:"header"},[(0,r._)("span",{class:"logo"},[(0,r._)("img",{src:"/logo.svg",alt:"logo"})]),(0,r._)("span",{class:"text"},"Platypush")],-1))),l={class:"row"},d=["type","disabled"],c={class:"row"},u=["type","disabled"],h={key:0,class:"row"},p=["disabled"],g={key:1,class:"row"},m=["disabled"],w={class:"row buttons"},b=["disabled"],_=a((()=>(0,r._)("div",{class:"row pull-right"},[(0,r._)("label",{class:"checkbox"},[(0,r._)("input",{type:"checkbox",name:"remember"}),(0,r.Uk)("  Keep me logged in on this device   ")])],-1))),f={key:2,class:"auth-error"};function y(e,t,s,a,y,k){const v=(0,r.up)("Loading");return y.initialized?((0,r.wg)(),(0,r.iD)("div",n,[y.isAuthenticated?(0,r.kq)("",!0):((0,r.wg)(),(0,r.iD)("form",{key:0,class:"login",method:"POST",onSubmit:t[0]||(t[0]=(...e)=>k.submitForm&&k.submitForm(...e))},[o,(0,r._)("div",l,[(0,r._)("label",null,[(0,r._)("input",{type:y.requires2fa?"hidden":"text",name:"username",disabled:y.authenticating,placeholder:"Username",ref:"username"},null,8,d)])]),(0,r._)("div",c,[(0,r._)("label",null,[(0,r._)("input",{type:y.requires2fa?"hidden":"password",name:"password",disabled:y.authenticating,placeholder:"Password"},null,8,u)])]),y.requires2fa?((0,r.wg)(),(0,r.iD)("div",h,[(0,r._)("label",null,[(0,r._)("input",{type:"text",name:"code",disabled:y.authenticating,placeholder:"2FA code",ref:"code"},null,8,p)])])):(0,r.kq)("",!0),s.register?((0,r.wg)(),(0,r.iD)("div",g,[(0,r._)("label",null,[(0,r._)("input",{type:"password",name:"confirm_password",disabled:y.authenticating,placeholder:"Confirm password"},null,8,m)])])):(0,r.kq)("",!0),(0,r._)("div",w,[(0,r._)("button",{type:"submit",class:(0,i.C_)(["btn btn-primary",{loading:y.authenticating}]),disabled:y.authenticating},[y.authenticating?((0,r.wg)(),(0,r.j4)(v,{key:0})):(0,r.kq)("",!0),(0,r.Uk)(" "+(0,i.zw)(s.register?"Register":"Login"),1)],10,b)]),_,y.authError?((0,r.wg)(),(0,r.iD)("div",f,(0,i.zw)(y.authError),1)):(0,r.kq)("",!0)],32))])):((0,r.wg)(),(0,r.j4)(v,{key:0}))}var k=s(6791),v=s(8637),q=s(7066),E={name:"Login",mixins:[v.Z],components:{Loading:k.Z},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 q.Z.post(r,s),t=e?.data?.session_token;if(t){const s=e.expires_at?Date.parse(e.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,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 q.Z.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()}))}},x=s(3744);const D=(0,x.Z)(E,[["render",y],["__scopeId","data-v-1b764fc6"]]);var A=D}}]);
//# sourceMappingURL=login.184d8b7d.js.map