bitwarden-estensione-browser/src/app/accounts/two-factor.component.ts

84 lines
3.4 KiB
TypeScript
Raw Normal View History

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 {
ActivatedRoute,
Router,
} from '@angular/router';
2018-06-05 21:02:53 +02:00
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';
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 {
@ViewChild('twoFactorOptions', { read: ViewContainerRef, static: true }) 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, route: ActivatedRoute) {
2019-07-02 14:44:29 +02:00
super(authService, router, i18nService, apiService, platformUtilsService, window, environmentService,
stateService, storageService, route);
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
}
async goAfterLogIn() {
const orgInvite = await this.stateService.get<any>('orgInvitation');
const emergencyInvite = await this.stateService.get<any>('emergencyInvitation');
if (orgInvite != null) {
this.router.navigate(['accept-organization'], { queryParams: orgInvite });
} else if (emergencyInvite != null) {
this.router.navigate(['accept-emergency'], { queryParams: emergencyInvite });
} else {
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], {
queryParams: {
identifier: this.identifier,
},
});
}
}
}
2018-06-05 21:02:53 +02:00
}