2018-04-06 21:33:20 +02:00
|
|
|
import {
|
|
|
|
ChangeDetectorRef,
|
|
|
|
Component,
|
|
|
|
NgZone,
|
|
|
|
} from '@angular/core';
|
2018-04-04 16:08:30 +02:00
|
|
|
|
2020-10-14 15:58:36 +02:00
|
|
|
import {
|
|
|
|
ActivatedRoute,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
2018-04-04 16:08:30 +02:00
|
|
|
|
2018-04-04 22:53:41 +02:00
|
|
|
import { TwoFactorProviderType } from 'jslib/enums/twoFactorProviderType';
|
|
|
|
|
2018-04-04 16:08:30 +02:00
|
|
|
import { ApiService } from 'jslib/abstractions/api.service';
|
|
|
|
import { AuthService } from 'jslib/abstractions/auth.service';
|
2018-04-04 22:29:43 +02:00
|
|
|
import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
2018-04-04 16:08:30 +02:00
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
2019-07-02 14:26:33 +02:00
|
|
|
import { StateService } from 'jslib/abstractions/state.service';
|
|
|
|
import { StorageService } from 'jslib/abstractions/storage.service';
|
2018-04-04 16:08:30 +02:00
|
|
|
import { SyncService } from 'jslib/abstractions/sync.service';
|
|
|
|
|
2018-04-06 21:33:20 +02:00
|
|
|
import { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
|
|
|
|
|
2018-04-04 16:08:30 +02:00
|
|
|
import { TwoFactorComponent as BaseTwoFactorComponent } from 'jslib/angular/components/two-factor.component';
|
|
|
|
|
2018-12-03 19:47:40 +01:00
|
|
|
import { PopupUtilsService } from '../services/popup-utils.service';
|
|
|
|
|
2018-04-06 21:33:20 +02:00
|
|
|
const BroadcasterSubscriptionId = 'TwoFactorComponent';
|
|
|
|
|
2018-04-04 16:08:30 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-two-factor',
|
2018-04-06 17:48:45 +02:00
|
|
|
templateUrl: 'two-factor.component.html',
|
2018-04-04 16:08:30 +02:00
|
|
|
})
|
|
|
|
export class TwoFactorComponent extends BaseTwoFactorComponent {
|
2018-04-04 22:53:41 +02:00
|
|
|
showNewWindowMessage = false;
|
|
|
|
|
2018-04-04 16:08:30 +02:00
|
|
|
constructor(authService: AuthService, router: Router,
|
|
|
|
i18nService: I18nService, apiService: ApiService,
|
2018-04-04 22:29:43 +02:00
|
|
|
platformUtilsService: PlatformUtilsService, syncService: SyncService,
|
2018-04-06 21:33:20 +02:00
|
|
|
environmentService: EnvironmentService, private ngZone: NgZone,
|
2018-12-03 19:47:40 +01:00
|
|
|
private broadcasterService: BroadcasterService, private changeDetectorRef: ChangeDetectorRef,
|
2019-07-02 14:26:33 +02:00
|
|
|
private popupUtilsService: PopupUtilsService, stateService: StateService,
|
2020-10-14 15:58:36 +02:00
|
|
|
storageService: StorageService, route: ActivatedRoute) {
|
2019-07-02 14:26:33 +02:00
|
|
|
super(authService, router, i18nService, apiService, platformUtilsService, window, environmentService,
|
2020-10-14 15:58:36 +02:00
|
|
|
stateService, storageService, route);
|
2018-07-13 16:50:32 +02:00
|
|
|
super.onSuccessfulLogin = () => {
|
2018-04-25 18:08:23 +02:00
|
|
|
return syncService.fullSync(true);
|
|
|
|
};
|
|
|
|
super.successRoute = '/tabs/vault';
|
2018-04-04 16:08:30 +02:00
|
|
|
}
|
|
|
|
|
2018-04-04 22:53:41 +02:00
|
|
|
async ngOnInit() {
|
2019-07-03 16:37:13 +02:00
|
|
|
const isFirefox = this.platformUtilsService.isFirefox();
|
|
|
|
if (this.popupUtilsService.inPopup(window) && isFirefox &&
|
|
|
|
this.win.navigator.userAgent.indexOf('Windows NT 10.0;') > -1) {
|
|
|
|
// ref: https://bugzilla.mozilla.org/show_bug.cgi?id=1562620
|
|
|
|
this.initU2f = false;
|
|
|
|
}
|
2018-12-03 19:47:40 +01:00
|
|
|
const isSafari = this.platformUtilsService.isSafari();
|
2018-04-04 22:53:41 +02:00
|
|
|
await super.ngOnInit();
|
|
|
|
if (this.selectedProviderType == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-21 16:05:17 +02:00
|
|
|
if (!isSafari && this.selectedProviderType === TwoFactorProviderType.Email &&
|
2018-12-03 19:47:40 +01:00
|
|
|
this.popupUtilsService.inPopup(window)) {
|
|
|
|
const confirmed = await this.platformUtilsService.showDialog(this.i18nService.t('popup2faCloseMessage'),
|
|
|
|
null, this.i18nService.t('yes'), this.i18nService.t('no'));
|
|
|
|
if (confirmed) {
|
|
|
|
this.popupUtilsService.popOut(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 16:37:13 +02:00
|
|
|
if (!this.initU2f && this.selectedProviderType === TwoFactorProviderType.U2f &&
|
|
|
|
this.popupUtilsService.inPopup(window)) {
|
|
|
|
const confirmed = await this.platformUtilsService.showDialog(this.i18nService.t('popupU2fCloseMessage'),
|
|
|
|
null, this.i18nService.t('yes'), this.i18nService.t('no'));
|
|
|
|
if (confirmed) {
|
|
|
|
this.popupUtilsService.popOut(window);
|
|
|
|
}
|
|
|
|
}
|
2018-04-06 21:33:20 +02:00
|
|
|
}
|
2018-04-04 22:53:41 +02:00
|
|
|
|
2018-04-06 21:33:20 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
|
|
|
super.ngOnDestroy();
|
2018-04-04 22:53:41 +02:00
|
|
|
}
|
|
|
|
|
2018-04-04 16:08:30 +02:00
|
|
|
anotherMethod() {
|
|
|
|
this.router.navigate(['2fa-options']);
|
|
|
|
}
|
|
|
|
}
|