2018-06-05 21:02:53 +02:00
|
|
|
import { Component, ViewChild, ViewContainerRef } from "@angular/core";
|
2020-10-14 18:13:13 +02:00
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
2018-06-05 21:02:53 +02:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { TwoFactorComponent as BaseTwoFactorComponent } from "@bitwarden/angular/components/two-factor.component";
|
|
|
|
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { AppIdService } from "@bitwarden/common/abstractions/appId.service";
|
|
|
|
import { AuthService } from "@bitwarden/common/abstractions/auth.service";
|
|
|
|
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
|
|
|
import { TwoFactorService } from "@bitwarden/common/abstractions/twoFactor.service";
|
|
|
|
import { TwoFactorProviderType } from "@bitwarden/common/enums/twoFactorProviderType";
|
2021-08-27 14:50:58 +02:00
|
|
|
|
2022-04-25 15:41:44 +02:00
|
|
|
import { RouterService } from "../services/router.service";
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
import { TwoFactorOptionsComponent } from "./two-factor-options.component";
|
|
|
|
|
2018-06-05 21:02:53 +02:00
|
|
|
@Component({
|
|
|
|
selector: "app-two-factor",
|
|
|
|
templateUrl: "two-factor.component.html",
|
|
|
|
})
|
|
|
|
export class TwoFactorComponent extends BaseTwoFactorComponent {
|
2020-08-17 16:04:38 +02:00
|
|
|
@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,
|
2021-08-27 14:50:58 +02:00
|
|
|
environmentService: EnvironmentService,
|
|
|
|
private modalService: ModalService,
|
2021-12-14 17:10:26 +01:00
|
|
|
route: ActivatedRoute,
|
2022-02-07 20:24:49 +01:00
|
|
|
logService: LogService,
|
2022-04-25 15:41:44 +02:00
|
|
|
twoFactorService: TwoFactorService,
|
2022-04-29 18:05:05 +02:00
|
|
|
appIdService: AppIdService,
|
|
|
|
private routerService: RouterService
|
2021-12-14 17:10:26 +01:00
|
|
|
) {
|
2019-07-02 14:44:29 +02:00
|
|
|
super(
|
|
|
|
authService,
|
|
|
|
router,
|
|
|
|
i18nService,
|
|
|
|
apiService,
|
|
|
|
platformUtilsService,
|
|
|
|
window,
|
|
|
|
environmentService,
|
2021-12-14 17:10:26 +01:00
|
|
|
stateService,
|
|
|
|
route,
|
2022-02-07 20:24:49 +01:00
|
|
|
logService,
|
2022-04-29 09:45:47 +02:00
|
|
|
twoFactorService,
|
|
|
|
appIdService
|
2021-12-14 17:10:26 +01:00
|
|
|
);
|
2018-07-13 16:51:52 +02:00
|
|
|
this.onSuccessfulLoginNavigate = this.goAfterLogIn;
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async anotherMethod() {
|
|
|
|
const [modal] = await this.modalService.openViewRef(
|
|
|
|
TwoFactorOptionsComponent,
|
|
|
|
this.twoFactorOptionsModal,
|
|
|
|
(comp) => {
|
|
|
|
comp.onProviderSelected.subscribe(async (provider: TwoFactorProviderType) => {
|
|
|
|
modal.close();
|
|
|
|
this.selectedProviderType = provider;
|
|
|
|
await this.init();
|
2018-06-11 17:43:10 +02:00
|
|
|
});
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onRecoverSelected.subscribe(() => {
|
|
|
|
modal.close();
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
|
|
|
}
|
2018-07-13 16:51:52 +02:00
|
|
|
|
|
|
|
async goAfterLogIn() {
|
2022-04-25 15:41:44 +02:00
|
|
|
const previousUrl = this.routerService.getPreviousUrl();
|
|
|
|
if (previousUrl) {
|
|
|
|
this.router.navigateByUrl(previousUrl);
|
2018-07-13 16:51:52 +02:00
|
|
|
} else {
|
2021-06-15 21:02:04 +02:00
|
|
|
this.router.navigate([this.successRoute], {
|
|
|
|
queryParams: {
|
|
|
|
identifier: this.identifier,
|
|
|
|
},
|
|
|
|
});
|
2018-07-13 16:51:52 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|