2018-06-05 21:02:53 +02:00
|
|
|
import {
|
|
|
|
Component,
|
2018-06-11 17:43:10 +02:00
|
|
|
ComponentFactoryResolver,
|
|
|
|
ViewChild,
|
|
|
|
ViewContainerRef,
|
2018-06-05 21:02:53 +02:00
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
2018-06-11 17:43:10 +02:00
|
|
|
import { TwoFactorOptionsComponent } from './two-factor-options.component';
|
|
|
|
|
|
|
|
import { ModalComponent } from '../modal.component';
|
|
|
|
|
2018-06-05 21:02:53 +02:00
|
|
|
import { TwoFactorProviderType } from 'jslib/enums/twoFactorProviderType';
|
|
|
|
|
|
|
|
import { ApiService } from 'jslib/abstractions/api.service';
|
|
|
|
import { AuthService } from 'jslib/abstractions/auth.service';
|
|
|
|
import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
2018-07-13 16:51:52 +02:00
|
|
|
import { StateService } from 'jslib/abstractions/state.service';
|
2019-07-02 14:44:29 +02:00
|
|
|
import { StorageService } from 'jslib/abstractions/storage.service';
|
2018-06-05 21:02:53 +02:00
|
|
|
|
|
|
|
import { TwoFactorComponent as BaseTwoFactorComponent } from 'jslib/angular/components/two-factor.component';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-two-factor',
|
|
|
|
templateUrl: 'two-factor.component.html',
|
|
|
|
})
|
|
|
|
export class TwoFactorComponent extends BaseTwoFactorComponent {
|
2018-06-11 17:43:10 +02:00
|
|
|
@ViewChild('twoFactorOptions', { read: ViewContainerRef }) twoFactorOptionsModal: ViewContainerRef;
|
2018-06-05 21:02:53 +02:00
|
|
|
|
|
|
|
constructor(authService: AuthService, router: Router,
|
|
|
|
i18nService: I18nService, apiService: ApiService,
|
2019-07-02 14:44:29 +02:00
|
|
|
platformUtilsService: PlatformUtilsService, stateService: StateService,
|
|
|
|
environmentService: EnvironmentService, private componentFactoryResolver: ComponentFactoryResolver,
|
|
|
|
storageService: StorageService) {
|
|
|
|
super(authService, router, i18nService, apiService, platformUtilsService, window, environmentService,
|
|
|
|
stateService, storageService);
|
2018-07-13 16:51:52 +02:00
|
|
|
this.onSuccessfulLoginNavigate = this.goAfterLogIn;
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
anotherMethod() {
|
2018-06-11 17:43:10 +02:00
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
const modal = this.twoFactorOptionsModal.createComponent(factory).instance;
|
|
|
|
const childComponent = modal.show<TwoFactorOptionsComponent>(TwoFactorOptionsComponent,
|
|
|
|
this.twoFactorOptionsModal);
|
|
|
|
|
|
|
|
childComponent.onProviderSelected.subscribe(async (provider: TwoFactorProviderType) => {
|
|
|
|
modal.close();
|
|
|
|
this.selectedProviderType = provider;
|
|
|
|
await this.init();
|
|
|
|
});
|
|
|
|
childComponent.onRecoverSelected.subscribe(() => {
|
|
|
|
modal.close();
|
|
|
|
});
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|
2018-07-13 16:51:52 +02:00
|
|
|
|
|
|
|
async goAfterLogIn() {
|
|
|
|
const invite = await this.stateService.get<any>('orgInvitation');
|
|
|
|
if (invite != null) {
|
|
|
|
this.router.navigate(['accept-organization'], { queryParams: invite });
|
|
|
|
} else {
|
2018-07-20 16:29:40 +02:00
|
|
|
const loginRedirect = await this.stateService.get<any>('loginRedirect');
|
|
|
|
if (loginRedirect != null) {
|
|
|
|
this.router.navigate([loginRedirect.route], { queryParams: loginRedirect.qParams });
|
|
|
|
await this.stateService.remove('loginRedirect');
|
|
|
|
} else {
|
|
|
|
this.router.navigate([this.successRoute]);
|
|
|
|
}
|
2018-07-13 16:51:52 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|