2018-02-01 04:54:13 +01:00
|
|
|
import { Component, ViewChild, ViewContainerRef } from "@angular/core";
|
2020-10-14 15:58:23 +02:00
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
2018-02-01 04:54:13 +01: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";
|
2022-10-28 20:54:55 +02:00
|
|
|
import { LoginService } from "@bitwarden/common/abstractions/login.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
2022-08-29 20:14:59 +02:00
|
|
|
import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { TwoFactorService } from "@bitwarden/common/abstractions/twoFactor.service";
|
|
|
|
import { TwoFactorProviderType } from "@bitwarden/common/enums/twoFactorProviderType";
|
2021-06-07 19:26:36 +02:00
|
|
|
|
2022-02-24 20:50:19 +01:00
|
|
|
import { TwoFactorOptionsComponent } from "./two-factor-options.component";
|
2018-02-01 04:54:13 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-two-factor",
|
2018-04-06 18:25:22 +02:00
|
|
|
templateUrl: "two-factor.component.html",
|
2018-02-01 04:54:13 +01:00
|
|
|
})
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2018-04-04 15:47:49 +02:00
|
|
|
export class TwoFactorComponent extends BaseTwoFactorComponent {
|
2020-08-18 22:13:15 +02:00
|
|
|
@ViewChild("twoFactorOptions", { read: ViewContainerRef, static: true })
|
|
|
|
twoFactorOptionsModal: ViewContainerRef;
|
2018-02-02 18:01:55 +01:00
|
|
|
|
2019-04-02 15:15:58 +02:00
|
|
|
showingModal = false;
|
|
|
|
|
2018-04-04 15:47:49 +02:00
|
|
|
constructor(
|
|
|
|
authService: AuthService,
|
|
|
|
router: Router,
|
|
|
|
i18nService: I18nService,
|
|
|
|
apiService: ApiService,
|
2018-10-03 15:42:11 +02:00
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
syncService: SyncService,
|
2021-08-27 15:30:44 +02:00
|
|
|
environmentService: EnvironmentService,
|
|
|
|
private modalService: ModalService,
|
2021-12-15 23:32:00 +01:00
|
|
|
stateService: StateService,
|
|
|
|
route: ActivatedRoute,
|
2022-02-08 00:26:53 +01:00
|
|
|
logService: LogService,
|
2022-04-29 09:48:44 +02:00
|
|
|
twoFactorService: TwoFactorService,
|
2022-10-28 20:54:55 +02:00
|
|
|
appIdService: AppIdService,
|
|
|
|
loginService: LoginService
|
2021-10-21 11:10:36 +02:00
|
|
|
) {
|
2019-07-02 14:18:42 +02:00
|
|
|
super(
|
|
|
|
authService,
|
|
|
|
router,
|
|
|
|
i18nService,
|
|
|
|
apiService,
|
|
|
|
platformUtilsService,
|
|
|
|
window,
|
|
|
|
environmentService,
|
2021-12-15 23:32:00 +01:00
|
|
|
stateService,
|
|
|
|
route,
|
2022-02-08 00:26:53 +01:00
|
|
|
logService,
|
2022-04-29 09:48:44 +02:00
|
|
|
twoFactorService,
|
2022-10-28 20:54:55 +02:00
|
|
|
appIdService,
|
|
|
|
loginService
|
2021-12-15 23:32:00 +01:00
|
|
|
);
|
2018-07-13 16:50:05 +02:00
|
|
|
super.onSuccessfulLogin = () => {
|
2022-10-28 20:54:55 +02:00
|
|
|
this.loginService.clearValues();
|
2021-09-24 15:33:57 +02:00
|
|
|
return syncService.fullSync(true);
|
2018-04-25 18:08:21 +02:00
|
|
|
};
|
2018-02-02 04:59:04 +01:00
|
|
|
}
|
|
|
|
|
2021-08-27 15:30:44 +02:00
|
|
|
async anotherMethod() {
|
|
|
|
const [modal, childComponent] = await this.modalService.openViewRef(
|
|
|
|
TwoFactorOptionsComponent,
|
|
|
|
this.twoFactorOptionsModal
|
|
|
|
);
|
|
|
|
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2019-04-02 15:15:58 +02:00
|
|
|
modal.onShown.subscribe(() => {
|
|
|
|
this.showingModal = true;
|
|
|
|
});
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2019-04-02 15:15:58 +02:00
|
|
|
modal.onClosed.subscribe(() => {
|
|
|
|
this.showingModal = false;
|
|
|
|
});
|
|
|
|
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2018-02-02 18:01:55 +01:00
|
|
|
childComponent.onProviderSelected.subscribe(async (provider: TwoFactorProviderType) => {
|
|
|
|
modal.close();
|
|
|
|
this.selectedProviderType = provider;
|
|
|
|
await this.init();
|
|
|
|
});
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2018-02-02 18:01:55 +01:00
|
|
|
childComponent.onRecoverSelected.subscribe(() => {
|
|
|
|
modal.close();
|
|
|
|
});
|
2018-02-01 04:54:13 +01:00
|
|
|
}
|
2022-03-04 01:20:29 +01:00
|
|
|
|
|
|
|
async submit() {
|
|
|
|
await super.submit();
|
|
|
|
if (this.captchaSiteKey) {
|
|
|
|
const content = document.getElementById("content") as HTMLDivElement;
|
|
|
|
content.setAttribute("style", "width:335px");
|
|
|
|
}
|
|
|
|
}
|
2018-02-01 04:54:13 +01:00
|
|
|
}
|