2021-12-17 15:57:11 +01:00
|
|
|
import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
|
2020-12-22 16:57:44 +01:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
import { ApiService } from "jslib-common/abstractions/api.service";
|
|
|
|
import { CryptoService } from "jslib-common/abstractions/crypto.service";
|
|
|
|
import { LogService } from "jslib-common/abstractions/log.service";
|
|
|
|
import { StateService } from "jslib-common/abstractions/state.service";
|
|
|
|
import { Utils } from "jslib-common/misc/utils";
|
2020-12-22 16:57:44 +01:00
|
|
|
|
|
|
|
@Component({
|
2021-12-17 15:57:11 +01:00
|
|
|
selector: "emergency-access-confirm",
|
|
|
|
templateUrl: "emergency-access-confirm.component.html",
|
2020-12-22 16:57:44 +01:00
|
|
|
})
|
|
|
|
export class EmergencyAccessConfirmComponent implements OnInit {
|
2021-12-17 15:57:11 +01:00
|
|
|
@Input() name: string;
|
|
|
|
@Input() userId: string;
|
|
|
|
@Input() emergencyAccessId: string;
|
|
|
|
@Input() formPromise: Promise<any>;
|
|
|
|
@Output() onConfirmed = new EventEmitter();
|
|
|
|
|
|
|
|
dontAskAgain = false;
|
|
|
|
loading = true;
|
|
|
|
fingerprint: string;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private apiService: ApiService,
|
|
|
|
private cryptoService: CryptoService,
|
|
|
|
private stateService: StateService,
|
|
|
|
private logService: LogService
|
|
|
|
) {}
|
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
try {
|
|
|
|
const publicKeyResponse = await this.apiService.getUserPublicKey(this.userId);
|
|
|
|
if (publicKeyResponse != null) {
|
|
|
|
const publicKey = Utils.fromB64ToArray(publicKeyResponse.publicKey);
|
|
|
|
const fingerprint = await this.cryptoService.getFingerprint(this.userId, 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
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
2020-12-22 16:57:44 +01:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
this.loading = false;
|
|
|
|
}
|
2020-12-22 16:57:44 +01:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
async submit() {
|
|
|
|
if (this.loading) {
|
|
|
|
return;
|
|
|
|
}
|
2020-12-22 16:57:44 +01:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
if (this.dontAskAgain) {
|
|
|
|
await this.stateService.setAutoConfirmFingerprints(true);
|
|
|
|
}
|
2020-12-22 16:57:44 +01:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
try {
|
|
|
|
this.onConfirmed.emit();
|
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
2020-12-22 16:57:44 +01:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2020-12-22 16:57:44 +01:00
|
|
|
}
|