2018-01-16 21:58:17 +01:00
|
|
|
import { Component, NgZone, OnDestroy, ViewChild, ViewContainerRef } from "@angular/core";
|
2018-01-23 22:58:32 +01:00
|
|
|
import { Router } from "@angular/router";
|
|
|
|
|
2022-02-24 20:50:19 +01:00
|
|
|
import { LoginComponent as BaseLoginComponent } from "jslib-angular/components/login.component";
|
|
|
|
import { ModalService } from "jslib-angular/services/modal.service";
|
2021-06-07 19:26:36 +02:00
|
|
|
import { AuthService } from "jslib-common/abstractions/auth.service";
|
2021-12-06 12:03:02 +01:00
|
|
|
import { BroadcasterService } from "jslib-common/abstractions/broadcaster.service";
|
2021-06-07 19:26:36 +02:00
|
|
|
import { CryptoFunctionService } from "jslib-common/abstractions/cryptoFunction.service";
|
|
|
|
import { EnvironmentService } from "jslib-common/abstractions/environment.service";
|
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
2021-10-21 11:10:36 +02:00
|
|
|
import { LogService } from "jslib-common/abstractions/log.service";
|
2021-07-05 00:06:24 +02:00
|
|
|
import { MessagingService } from "jslib-common/abstractions/messaging.service";
|
2021-06-07 19:26:36 +02:00
|
|
|
import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service";
|
|
|
|
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
|
|
|
import { StateService } from "jslib-common/abstractions/state.service";
|
|
|
|
import { SyncService } from "jslib-common/abstractions/sync.service";
|
|
|
|
|
2022-02-24 20:50:19 +01:00
|
|
|
import { EnvironmentComponent } from "./environment.component";
|
2018-04-04 15:19:39 +02:00
|
|
|
|
2020-11-04 18:09:21 +01:00
|
|
|
const BroadcasterSubscriptionId = "LoginComponent";
|
|
|
|
|
2018-01-16 21:58:17 +01:00
|
|
|
@Component({
|
|
|
|
selector: "app-login",
|
2018-04-06 18:25:22 +02:00
|
|
|
templateUrl: "login.component.html",
|
2018-01-16 21:58:17 +01:00
|
|
|
})
|
2020-11-04 20:00:44 +01:00
|
|
|
export class LoginComponent extends BaseLoginComponent implements OnDestroy {
|
2020-08-18 22:13:15 +02:00
|
|
|
@ViewChild("environment", { read: ViewContainerRef, static: true })
|
|
|
|
environmentModal: ViewContainerRef;
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2019-04-02 15:15:58 +02:00
|
|
|
showingModal = false;
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2022-02-24 20:50:19 +01:00
|
|
|
protected alwaysRememberEmail = true;
|
2022-01-25 19:00:49 +01:00
|
|
|
|
2021-07-05 00:06:24 +02:00
|
|
|
private deferFocus: boolean = null;
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2020-08-18 22:13:15 +02:00
|
|
|
constructor(
|
|
|
|
authService: AuthService,
|
|
|
|
router: Router,
|
|
|
|
i18nService: I18nService,
|
2021-08-27 15:30:44 +02:00
|
|
|
syncService: SyncService,
|
|
|
|
private modalService: ModalService,
|
2020-08-18 22:13:15 +02:00
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
stateService: StateService,
|
|
|
|
environmentService: EnvironmentService,
|
2021-12-15 23:32:00 +01:00
|
|
|
passwordGenerationService: PasswordGenerationService,
|
|
|
|
cryptoFunctionService: CryptoFunctionService,
|
2020-11-04 18:09:21 +01:00
|
|
|
private broadcasterService: BroadcasterService,
|
|
|
|
ngZone: NgZone,
|
2021-07-05 00:06:24 +02:00
|
|
|
private messagingService: MessagingService,
|
2021-12-15 23:32:00 +01:00
|
|
|
logService: LogService
|
2021-07-05 00:06:24 +02:00
|
|
|
) {
|
2021-12-20 15:47:17 +01:00
|
|
|
super(
|
2021-07-05 00:06:24 +02:00
|
|
|
authService,
|
2021-12-20 15:47:17 +01:00
|
|
|
router,
|
2021-07-05 00:06:24 +02:00
|
|
|
platformUtilsService,
|
2020-08-21 15:50:36 +02:00
|
|
|
i18nService,
|
|
|
|
stateService,
|
2021-07-05 00:06:24 +02:00
|
|
|
environmentService,
|
|
|
|
passwordGenerationService,
|
2021-12-15 23:32:00 +01:00
|
|
|
cryptoFunctionService,
|
2021-07-05 00:06:24 +02:00
|
|
|
logService,
|
|
|
|
ngZone
|
2021-12-20 15:47:17 +01:00
|
|
|
);
|
2021-07-05 00:06:24 +02:00
|
|
|
super.onSuccessfulLogin = () => {
|
|
|
|
return syncService.fullSync(true);
|
2021-12-20 15:47:17 +01:00
|
|
|
};
|
2020-11-04 18:09:21 +01:00
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
|
2020-11-04 20:00:44 +01:00
|
|
|
async ngOnInit() {
|
|
|
|
await super.ngOnInit();
|
|
|
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
|
2018-02-02 18:31:21 +01:00
|
|
|
this.ngZone.run(() => {
|
|
|
|
switch (message.command) {
|
|
|
|
case "windowHidden":
|
2020-11-04 18:09:21 +01:00
|
|
|
this.onWindowHidden();
|
2021-12-20 15:47:17 +01:00
|
|
|
break;
|
2021-07-05 00:06:24 +02:00
|
|
|
case "windowIsFocused":
|
|
|
|
if (this.deferFocus === null) {
|
|
|
|
this.deferFocus = !message.windowIsFocused;
|
2020-11-04 18:09:21 +01:00
|
|
|
if (!this.deferFocus) {
|
2021-07-05 00:06:24 +02:00
|
|
|
this.focusInput();
|
2021-12-20 15:47:17 +01:00
|
|
|
}
|
2020-11-04 18:09:21 +01:00
|
|
|
} else if (this.deferFocus && message.windowIsFocused) {
|
2021-07-05 00:06:24 +02:00
|
|
|
this.focusInput();
|
2020-11-04 18:09:21 +01:00
|
|
|
this.deferFocus = false;
|
|
|
|
}
|
2021-07-23 20:48:10 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
});
|
|
|
|
});
|
2021-07-05 00:06:24 +02:00
|
|
|
this.messagingService.send("getWindowIsFocused");
|
2021-12-20 15:47:17 +01:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:00:44 +01:00
|
|
|
ngOnDestroy() {
|
2021-12-15 23:32:00 +01:00
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
2021-12-20 15:47:17 +01:00
|
|
|
}
|
|
|
|
|
2021-08-27 15:30:44 +02:00
|
|
|
async settings() {
|
|
|
|
const [modal, childComponent] = await this.modalService.openViewRef(
|
|
|
|
EnvironmentComponent,
|
|
|
|
this.environmentModal
|
2021-12-20 15:47:17 +01:00
|
|
|
);
|
|
|
|
|
2019-04-02 15:15:58 +02:00
|
|
|
modal.onShown.subscribe(() => {
|
|
|
|
this.showingModal = true;
|
2021-12-20 15:47:17 +01:00
|
|
|
});
|
2019-04-02 15:15:58 +02:00
|
|
|
modal.onClosed.subscribe(() => {
|
|
|
|
this.showingModal = false;
|
2021-12-20 15:47:17 +01:00
|
|
|
});
|
|
|
|
|
2018-02-02 18:31:21 +01:00
|
|
|
childComponent.onSaved.subscribe(() => {
|
|
|
|
modal.close();
|
2021-12-20 15:47:17 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-04 18:09:21 +01:00
|
|
|
onWindowHidden() {
|
2019-04-02 15:15:58 +02:00
|
|
|
this.showPassword = false;
|
2021-12-20 15:47:17 +01:00
|
|
|
}
|
|
|
|
|
2021-07-23 20:48:10 +02:00
|
|
|
async submit() {
|
|
|
|
await super.submit();
|
|
|
|
if (this.captchaSiteKey) {
|
|
|
|
const content = document.getElementById("content") as HTMLDivElement;
|
|
|
|
content.setAttribute("style", "width:335px");
|
|
|
|
}
|
2021-12-20 15:47:17 +01:00
|
|
|
}
|
2018-01-16 21:58:17 +01:00
|
|
|
}
|