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
|
|
|
|
2023-02-06 22:53:37 +01:00
|
|
|
import { TwoFactorComponent as BaseTwoFactorComponent } from "@bitwarden/angular/auth/components/two-factor.component";
|
2022-06-14 17:10:53 +02:00
|
|
|
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 { 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";
|
2023-02-06 22:53:37 +01:00
|
|
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
|
|
|
import { LoginService } from "@bitwarden/common/auth/abstractions/login.service";
|
|
|
|
import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor.service";
|
|
|
|
import { TwoFactorProviderType } from "@bitwarden/common/auth/enums/two-factor-provider-type";
|
2021-08-27 14:50:58 +02:00
|
|
|
|
2023-02-06 22:53:37 +01:00
|
|
|
import { RouterService } from "../app/core";
|
2022-04-25 15:41:44 +02:00
|
|
|
|
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",
|
|
|
|
})
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2018-06-05 21:02:53 +02:00
|
|
|
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,
|
2022-10-28 20:54:55 +02:00
|
|
|
private routerService: RouterService,
|
|
|
|
loginService: LoginService
|
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,
|
2022-10-28 20:54:55 +02:00
|
|
|
appIdService,
|
|
|
|
loginService
|
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) => {
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onProviderSelected.subscribe(async (provider: TwoFactorProviderType) => {
|
|
|
|
modal.close();
|
|
|
|
this.selectedProviderType = provider;
|
|
|
|
await this.init();
|
2018-06-11 17:43:10 +02:00
|
|
|
});
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
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-10-28 20:54:55 +02:00
|
|
|
this.loginService.clearValues();
|
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
|
|
|
}
|