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