2018-11-15 05:13:50 +01:00
|
|
|
import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
|
|
|
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
2018-11-15 05:13:50 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-user-confirm",
|
|
|
|
templateUrl: "user-confirm.component.html",
|
|
|
|
})
|
|
|
|
export class UserConfirmComponent implements OnInit {
|
|
|
|
@Input() name: string;
|
|
|
|
@Input() userId: string;
|
2021-07-21 11:32:27 +02:00
|
|
|
@Input() publicKey: Uint8Array;
|
2018-11-15 05:13:50 +01:00
|
|
|
@Output() onConfirmedUser = new EventEmitter();
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-11-15 05:13:50 +01:00
|
|
|
dontAskAgain = false;
|
|
|
|
loading = true;
|
|
|
|
fingerprint: string;
|
2021-09-13 14:46:16 +02:00
|
|
|
formPromise: Promise<any>;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-12-14 17:10:26 +01:00
|
|
|
constructor(
|
|
|
|
private cryptoService: CryptoService,
|
|
|
|
private logService: LogService,
|
|
|
|
private stateService: StateService
|
|
|
|
) {}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-11-15 05:13:50 +01:00
|
|
|
async ngOnInit() {
|
|
|
|
try {
|
2021-07-21 11:32:27 +02:00
|
|
|
if (this.publicKey != null) {
|
2018-11-15 05:13:50 +01:00
|
|
|
const fingerprint = await this.cryptoService.getFingerprint(
|
|
|
|
this.userId,
|
|
|
|
this.publicKey.buffer
|
|
|
|
);
|
|
|
|
if (fingerprint != null) {
|
|
|
|
this.fingerprint = fingerprint.join("-");
|
2021-10-20 18:30:04 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2021-10-20 18:30:04 +02:00
|
|
|
} catch (e) {
|
2018-11-15 05:13:50 +01:00
|
|
|
this.logService.error(e);
|
|
|
|
}
|
|
|
|
this.loading = false;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-11-15 05:13:50 +01:00
|
|
|
|
|
|
|
async submit() {
|
|
|
|
if (this.loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-21 11:32:27 +02:00
|
|
|
if (this.dontAskAgain) {
|
|
|
|
await this.stateService.setAutoConfirmFingerprints(true);
|
2018-11-15 05:13:50 +01:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-12-14 17:10:26 +01:00
|
|
|
this.onConfirmedUser.emit();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-11-15 05:13:50 +01:00
|
|
|
}
|