2018-01-16 21:58:17 +01:00
|
|
|
import {
|
|
|
|
Component,
|
2018-02-02 18:31:21 +01:00
|
|
|
ComponentFactoryResolver,
|
2020-11-04 18:09:21 +01:00
|
|
|
NgZone,
|
2021-02-03 19:21:22 +01:00
|
|
|
OnDestroy,
|
2018-02-02 18:31:21 +01:00
|
|
|
ViewChild,
|
|
|
|
ViewContainerRef,
|
2018-01-16 21:58:17 +01:00
|
|
|
} from '@angular/core';
|
2020-08-21 15:50:36 +02:00
|
|
|
|
2018-01-23 22:58:32 +01:00
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
2018-02-08 16:37:54 +01:00
|
|
|
import { EnvironmentComponent } from './environment.component';
|
2018-02-02 18:31:21 +01:00
|
|
|
|
2021-06-07 19:26:36 +02:00
|
|
|
import { AuthService } from 'jslib-common/abstractions/auth.service';
|
|
|
|
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-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 { StorageService } from 'jslib-common/abstractions/storage.service';
|
|
|
|
import { SyncService } from 'jslib-common/abstractions/sync.service';
|
|
|
|
|
|
|
|
import { BroadcasterService } from 'jslib-angular/services/broadcaster.service';
|
|
|
|
|
|
|
|
import { LoginComponent as BaseLoginComponent } from 'jslib-angular/components/login.component';
|
|
|
|
import { ModalComponent } from 'jslib-angular/components/modal.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;
|
2018-02-02 18:31:21 +01:00
|
|
|
|
2019-04-02 15:15:58 +02:00
|
|
|
showingModal = false;
|
|
|
|
|
2021-07-05 00:06:24 +02:00
|
|
|
private deferFocus: boolean = null;
|
|
|
|
|
2020-08-18 22:13:15 +02:00
|
|
|
constructor(authService: AuthService, router: Router, i18nService: I18nService,
|
|
|
|
syncService: SyncService, private componentFactoryResolver: ComponentFactoryResolver,
|
|
|
|
platformUtilsService: PlatformUtilsService, stateService: StateService,
|
|
|
|
environmentService: EnvironmentService, passwordGenerationService: PasswordGenerationService,
|
2020-11-04 18:09:21 +01:00
|
|
|
cryptoFunctionService: CryptoFunctionService, storageService: StorageService,
|
2021-07-05 00:06:24 +02:00
|
|
|
private broadcasterService: BroadcasterService, private ngZone: NgZone,
|
|
|
|
private messagingService: MessagingService) {
|
2020-08-21 15:50:36 +02:00
|
|
|
super(authService, router, platformUtilsService, i18nService, stateService, environmentService,
|
2020-11-02 23:11:56 +01:00
|
|
|
passwordGenerationService, cryptoFunctionService, storageService);
|
2018-07-13 16:45:15 +02:00
|
|
|
super.onSuccessfulLogin = () => {
|
2018-04-25 18:08:21 +02:00
|
|
|
return syncService.fullSync(true);
|
|
|
|
};
|
2018-01-23 22:58:32 +01:00
|
|
|
}
|
2018-02-02 18:31:21 +01:00
|
|
|
|
2020-11-04 18:09:21 +01:00
|
|
|
async ngOnInit() {
|
|
|
|
await super.ngOnInit();
|
|
|
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
|
|
|
|
this.ngZone.run(() => {
|
|
|
|
switch (message.command) {
|
|
|
|
case 'windowHidden':
|
|
|
|
this.onWindowHidden();
|
|
|
|
break;
|
2021-07-05 00:06:24 +02:00
|
|
|
case 'windowIsFocused':
|
|
|
|
if (this.deferFocus === null) {
|
|
|
|
this.deferFocus = !message.windowIsFocused;
|
|
|
|
if (!this.deferFocus) {
|
|
|
|
this.focusInput();
|
|
|
|
}
|
|
|
|
} else if (this.deferFocus && message.windowIsFocused) {
|
|
|
|
this.focusInput();
|
|
|
|
this.deferFocus = false;
|
|
|
|
}
|
|
|
|
break;
|
2020-11-04 18:09:21 +01:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2021-07-05 00:06:24 +02:00
|
|
|
this.messagingService.send('getWindowIsFocused');
|
2020-11-04 18:09:21 +01:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:00:44 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
|
|
|
}
|
|
|
|
|
2018-02-02 18:31:21 +01:00
|
|
|
settings() {
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
const modal = this.environmentModal.createComponent(factory).instance;
|
2019-04-02 15:15:58 +02:00
|
|
|
modal.onShown.subscribe(() => {
|
|
|
|
this.showingModal = true;
|
|
|
|
});
|
|
|
|
modal.onClosed.subscribe(() => {
|
|
|
|
this.showingModal = false;
|
|
|
|
modal.onShown.unsubscribe();
|
|
|
|
modal.onClosed.unsubscribe();
|
|
|
|
});
|
|
|
|
|
2018-02-02 18:31:21 +01:00
|
|
|
const childComponent = modal.show<EnvironmentComponent>(EnvironmentComponent,
|
|
|
|
this.environmentModal);
|
|
|
|
childComponent.onSaved.subscribe(() => {
|
|
|
|
modal.close();
|
|
|
|
});
|
|
|
|
}
|
2020-11-04 18:09:21 +01:00
|
|
|
|
|
|
|
onWindowHidden() {
|
|
|
|
this.showPassword = false;
|
|
|
|
}
|
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');
|
|
|
|
}
|
|
|
|
}
|
2018-01-16 21:58:17 +01:00
|
|
|
}
|