homebridge-config-ui-x
Version:
A web based management, configuration and control platform for Homebridge.
1 lines • 7.86 kB
JavaScript
import {g,n as ne,a as ae$1,l as le$1,z as zt,B as BH,W,$,S as Se,v as ve,b as B8,r as rp,p as pe,H as Hf,A as An,E,F as Fn,c as Eo,J as Ja,K as Kn,d as zn,Y as Ye,e as Hn,L as Ln,f as pt,h as zt$1,i as Jn,C as Cn,_ as _n,j as a$,k as K8,m as La,o as dy,q as rc,s as At,t as f_,R as Rd,u as Re,w as Kt,x as Cy,y as ie,D as ly,N as Ny,G as h_,O as Oe,I as Rt,M as Ey,P as ST,Q as KC,T as JC,U as ye,V as Ha}from'./main-ONDCASUV.js';var oe=["password"],ae=["username"],re=["otp"];function se(i,S){if(i&1&&(La(0,"div",8)(1,"span",12),dy(2,"i",13),Rd(),dy(3,"input",14,0),f_(5,"translate"),KC(),Rd(),La(6,"div",8)(7,"span",12),dy(8,"i",15),Rd(),dy(9,"input",16,1),f_(11,"translate"),KC(),Rd()),i&2){let e=ye();ie(3),Cy("is-invalid",e.form.controls.username.dirty&&e.form.controls.username.errors),ly("placeholder",h_(5,6,"users.label_username")),JC(),ie(6),Cy("is-invalid",e.form.controls.password.dirty&&e.form.controls.password.errors),ly("placeholder",h_(11,8,"users.label_password")),JC();}}function le(i,S){i&1&&(La(0,"div",8)(1,"span",12),dy(2,"i",17),Rd(),dy(3,"input",18,2),f_(5,"translate"),KC(),Rd()),i&2&&(ie(3),ly("placeholder",h_(5,1,"login.label_2fa_code")),JC());}function de(i,S){i&1&&(La(0,"div",9)(1,"div",12),dy(2,"i",19),Rd(),La(3,"div",20)(4,"div",21),At(5),f_(6,"translate"),Rd(),dy(7,"div",22),f_(8,"translate"),Rd()()),i&2&&(ie(5),Ny(h_(6,2,"login.invalid_credentials")),ie(2),ly("innerHTML",h_(8,4,"login.invalid_credentials_2"),Ha));}function me(i,S){i&1&&(La(0,"div",9)(1,"div",12),dy(2,"i",19),Rd(),La(3,"div",20)(4,"div",21),At(5),f_(6,"translate"),Rd(),dy(7,"div",22),f_(8,"translate"),Rd()()),i&2&&(ie(5),Ny(h_(6,2,"login.invalid_code")),ie(2),ly("innerHTML",h_(8,4,"login.invalid_credentials_2"),Ha));}var Me=(()=>{class i{destroyRef=g(ne);$auth=g(ae$1);$router=g(le$1);$settings=g(zt);targetRoute;validNonAdminRoutes=["/accessories","/plugins","/logs","/support"];passwordInput=BH("password");usernameInput=BH("username");otpInput=BH("otp");backgroundStyle=W("");invalidCredentials=W(false);invalid2faCode=W(false);twoFactorCodeRequired=W(false);inProgress=W(false);form=new $({username:new Se("",{nonNullable:true,validators:[ve.required]}),password:new Se("",{nonNullable:true,validators:[ve.required]}),otp:new Se("",{nonNullable:true})});formInvalid=B8(this.form.statusChanges.pipe(rp(this.form.status),pe(()=>this.form.invalid)),{initialValue:this.form.invalid});ngOnInit(){this.form.valueChanges.pipe(Hf(500),An(this.destroyRef)).subscribe(()=>{let e=this.passwordInput()?.nativeElement.value;e&&e!==this.form.controls.password.value&&this.form.controls.password.setValue(e);}),this.targetRoute=window.sessionStorage.getItem("target_route")||"/",window.sessionStorage.removeItem("target_route"),this.setBackground();}ngAfterViewInit(){window.matchMedia("(hover: none) and (pointer: coarse)").matches||this.usernameInput()?.nativeElement.focus();}onSubmit(){return E(this,null,function*(){this.invalidCredentials.set(false),this.invalid2faCode.set(false),this.inProgress.set(true),document.getElementById("submit-button")?.blur();let e=this.passwordInput()?.nativeElement.value;e&&e!==this.form.controls.password.value&&this.form.controls.password.setValue(e);let s=this.usernameInput()?.nativeElement.value;if(s&&s!==this.form.controls.username.value&&this.form.controls.username.setValue(s),this.twoFactorCodeRequired()){let t=this.otpInput()?.nativeElement.value;t&&t!==this.form.controls.otp.value&&this.form.controls.otp.setValue(t);}try{yield this.$auth.login(this.form.getRawValue()),!this.$auth.user.admin&&!this.validNonAdminRoutes.includes(this.targetRoute)&&(this.targetRoute="/"),this.$router.navigateByUrl(this.targetRoute);}catch(t){if(t.status===412){let f=this.form.controls.otp;this.twoFactorCodeRequired()?(f.setErrors({invalidCode:true}),this.invalid2faCode.set(true)):(f.setValidators([ve.required,ve.minLength(6),ve.maxLength(6)]),f.updateValueAndValidity()),this.twoFactorCodeRequired.set(true),setTimeout(()=>{document.getElementById("form-ota")?.focus();},100);}else this.invalidCredentials.set(true);}this.inProgress.set(false);})}setBackground(){return E(this,null,function*(){if(this.$settings.settingsLoaded||(yield Fn(this.$settings.onSettingsLoaded)),this.$settings.env.customWallpaperHash){let e=`${Eo.api.base}/auth/wallpaper/${this.$settings.env.customWallpaperHash}`;this.backgroundStyle.set(`url('${e}') center/cover`);}})}static \u0275fac=function(s){return new(s||i)};static \u0275cmp=Ja({type:i,selectors:[["app-login"]],viewQuery:function(s,t){s&1&&Ey(t.passwordInput,oe,5)(t.usernameInput,ae,5)(t.otpInput,re,5),s&2&&ST(3);},decls:15,vars:15,consts:[["username",""],["password",""],["otp",""],[1,"login-container","gradient","d-flex","align-items-start","justify-content-center"],[1,"w-100","login-card","d-flex","py-4","flex-column"],["ngSrc","assets/homebridge-color-round.webp","alt","Homebridge Logo","height","100","width","100","priority","true",1,"homebridge-logo","mx-auto","my-3"],["novalidate","",3,"ngSubmit","formGroup"],[1,"mb-4","text-center"],[1,"input-group","mb-4"],[1,"input-group","no-border","mb-4"],[1,"text-center"],["tabindex","0","id","submit-button","type","submit",1,"btn","btn-primary","mb-2",3,"disabled"],[1,"input-group-text","custom-input"],["aria-hidden","true",1,"fas","fa-user","primary-text","fa-lg"],["formControlName","username","name","username","type","text","id","form-username","autocomplete","username","autocapitalize","none","tabindex","0","required","",1,"form-control","custom-input",3,"placeholder"],["aria-hidden","true",1,"fas","fa-lock","primary-text","fa-lg"],["formControlName","password","name","password","type","password","id","form-pass","autocomplete","current-password","tabindex","0","required","",1,"form-control","custom-input",3,"placeholder"],["aria-hidden","true",1,"fas","fa-key","primary-text","fa-lg"],["formControlName","otp","type","text","id","form-ota","autocomplete","one-time-code","autocapitalize","none","inputmode","numeric","pattern","[0-9]*","tabindex","0",1,"form-control","custom-input",3,"placeholder"],["aria-hidden","true",1,"fas","fa-exclamation-triangle","pink-text","fa-lg"],[1,"form-control","custom-input"],[1,"small","grey-text","fw-semibold"],[1,"small","grey-text",3,"innerHTML"]],template:function(s,t){s&1&&(La(0,"div",3)(1,"div",4),dy(2,"img",5),La(3,"form",6),rc("ngSubmit",function(){return t.onSubmit()}),La(4,"h4",7),At(5),f_(6,"translate"),Rd(),Re(7,se,12,10)(8,le,6,3,"div",8),Re(9,de,9,6,"div",9),Re(10,me,9,6,"div",9),La(11,"div",10)(12,"button",11),At(13),f_(14,"translate"),Rd()()()()()),s&2&&(Kt("background",t.backgroundStyle()),Cy("anim",!t.backgroundStyle()),ie(3),ly("formGroup",t.form),ie(2),Ny(h_(6,11,"setup.welcome_to_homebridge")),ie(2),Oe(t.twoFactorCodeRequired()?8:7),ie(2),Oe(t.invalidCredentials()?9:-1),ie(),Oe(t.invalid2faCode()?10:-1),ie(2),ly("disabled",t.formInvalid()),ie(),Rt(" ",h_(14,13,"form.button_continue")," "));},dependencies:[Kn,zn,Ye,Hn,Ln,pt,zt$1,Jn,Cn,_n,a$,K8],styles:[".login-container[_ngcontent-%COMP%]{z-index:-1;padding-top:2em;padding-bottom:2em;min-height:100%;background-size:300% 300%}.anim[_ngcontent-%COMP%]{-webkit-animation:_ngcontent-%COMP%_gradient 20s ease infinite;-moz-animation:gradient 20s ease infinite;animation:_ngcontent-%COMP%_gradient 20s ease infinite}@keyframes _ngcontent-%COMP%_gradient{0%{background-position:0 50%}50%{background-position:100% 50%}to{background-position:0 50%}}.login-card[_ngcontent-%COMP%]{max-width:550px;border-radius:1rem;padding-right:25px;padding-left:25px;background-color:#ffffffe6}.login-card[_ngcontent-%COMP%] .form-control[_ngcontent-%COMP%]:focus{background-color:inherit!important}@media screen and (max-width:575px){.login-card[_ngcontent-%COMP%]{margin-left:1em;margin-right:1em}}.homebridge-logo[_ngcontent-%COMP%]{margin-bottom:10px}"]})}return i})();export{Me as LoginComponent};