zwave-js-ui
Version:
Z-Wave Control Panel and MQTT Gateway
3 lines (2 loc) • 4.35 kB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ColorScheme-RD00g_MN.js","./index-B9yS4Bcc.js","./index-Bm7DxUwf.css"])))=>i.map(i=>d[i]);
import{_ as c,L as h,d as _,ap as w,a as V,u,C as y,aq as b,l as S,w as a,V as v,r as m,o as x,b as s,N as C,n as L,ar as M,U as I,as as U,k as n,O as T,a0 as A,p as P,W as d,R as k,at as q,h as N,X as B,t as O,f as z,z as D}from"./index-B9yS4Bcc.js";const R=h.get("Login"),J={components:{ColorScheme:_(()=>D(()=>import("./ColorScheme-RD00g_MN.js"),__vite__mapDeps([0,1,2]),import.meta.url)),Logo:w},data(){return{username:"",password:"",rememberMe:!1,error_text:"",error_type:"error",showPsw:!1,error:!1,valid_login:!0,rules:{required(o){return!!o||"This field is required."}}}},watch:{error:function(o){o&&setTimeout(function(){this.error=!1},5e3)}},mounted(){if(this.isLocalStorageSupported()){const o=localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")):null,e=!!localStorage.getItem("logged");o&&o.rememberMe?(this.username=o.username||this.username,this.password=o.password||this.password,this.rememberMe=o.rememberMe,e&&this.login(!0)):localStorage.removeItem("user"),this.initColorScheme()}else this.error=!0,this.error_type="error",this.error_text="Local storage not supported"},methods:{...V(u,["initColorScheme"]),isLocalStorageSupported(){const o="test",e=window.localStorage;try{return e.setItem(o,"1"),e.removeItem(o),!0}catch{return!1}},async login(o){if(!this.isLocalStorageSupported()){this.error=!0,this.error_type="error",this.error_text="Local storage not supported";return}const e=await this.$refs.form.validate();if(o===!0||e.valid)try{let t={username:this.username,password:this.password};const i=await y.login(t);i.success?(t=Object.assign(t,i.user),t.rememberMe=this.rememberMe,localStorage.setItem("user",JSON.stringify(t)),localStorage.setItem("logged","true"),u().onUserLogged(t),this.$route.params.nextUrl!=null?this.$router.push(this.$route.params.nextUrl):this.$router.push(b.main)):(i.message&&(this.error=!0),this.error_type="error",this.error_text=i.message)}catch(t){R.error(t),this.error=!0,this.error_type="error",this.error_text=t.message}}}},j={class:"d-flex align-center"};function E(o,e,t,i,r,p){const f=m("Logo"),g=m("color-scheme");return x(),S(v,{class:"pa-0 background",fluid:"","fill-height":""},{default:a(()=>[s(z,{elevation:"12",cols:"12",class:"pa-0 fill-height"},{default:a(()=>[s(C,{class:L(["mx-auto",o.$vuetify.display.smAndDown?"":"ml-10"]),width:o.$vuetify.display.smAndDown?"100%":"500",height:"100%",tile:""},{default:a(()=>[s(M,null,{default:a(()=>[I("div",j,[s(f,{size:"50"}),s(U,{style:{"margin-left":"20px"}},{default:a(()=>e[6]||(e[6]=[n("Z-Wave JS UI")])),_:1,__:[6]})])]),_:1}),s(T,null,{default:a(()=>[s(A,{modelValue:r.valid_login,"onUpdate:modelValue":e[4]||(e[4]=l=>r.valid_login=l),id:"login-form",onSubmit:P(p.login,["prevent"]),ref:"form","validate-on":"lazy"},{default:a(()=>[s(d,{required:"",rules:[r.rules.required],modelValue:r.username,"onUpdate:modelValue":e[0]||(e[0]=l=>r.username=l),modelModifiers:{trim:!0},autocomplete:"","prepend-icon":"person",name:"username",label:"Username",type:"text"},null,8,["rules","modelValue"]),s(d,{required:"",rules:[r.rules.required],modelValue:r.password,"onUpdate:modelValue":e[1]||(e[1]=l=>r.password=l),"prepend-icon":"lock",name:"password",label:"Password",autocomplete:"",type:r.showPsw?"text":"password","append-icon":r.showPsw?"visibility":"visibility_off","onClick:append":e[2]||(e[2]=l=>r.showPsw=!r.showPsw)},null,8,["rules","modelValue","type","append-icon"]),s(k,{modelValue:r.rememberMe,"onUpdate:modelValue":e[3]||(e[3]=l=>r.rememberMe=l),"prepend-icon":"null",name:"rememberMe","hide-details":"",label:"Remember Me"},null,8,["modelValue"]),s(g,{"hide-details":""})]),_:1},8,["modelValue","onSubmit"])]),_:1}),s(q,{class:"justify-center"},{default:a(()=>[s(N,{color:"primary",style:{"min-width":"150px",margin:"10px"},rounded:"",variant:"flat",class:"mb-6",type:"submit",form:"login-form"},{default:a(()=>e[7]||(e[7]=[n("Login")])),_:1,__:[7]})]),_:1}),s(B,{closable:"",type:r.error_type,modelValue:r.error,"onUpdate:modelValue":e[5]||(e[5]=l=>r.error=l)},{default:a(()=>[n(O(r.error_text),1)]),_:1},8,["type","modelValue"])]),_:1},8,["class","width"])]),_:1})]),_:1})}const W=c(J,[["render",E],["__scopeId","data-v-3e5554d2"]]);export{W as default};