2018-06-21 17:43:50 +02:00
|
|
|
import { Component, OnInit } from "@angular/core";
|
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from "jslib-common/abstractions/api.service";
|
|
|
|
import { CryptoService } from "jslib-common/abstractions/crypto.service";
|
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
2021-11-09 19:24:26 +01:00
|
|
|
import { KeyConnectorService } from "jslib-common/abstractions/keyConnector.service";
|
2021-10-20 18:30:04 +02:00
|
|
|
import { LogService } from "jslib-common/abstractions/log.service";
|
2021-12-07 20:41:45 +01:00
|
|
|
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
2021-12-14 17:10:26 +01:00
|
|
|
import { StateService } from "jslib-common/abstractions/state.service";
|
2021-06-07 20:13:58 +02:00
|
|
|
import { UpdateProfileRequest } from "jslib-common/models/request/updateProfileRequest";
|
|
|
|
import { ProfileResponse } from "jslib-common/models/response/profileResponse";
|
2018-06-21 17:43:50 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-profile",
|
|
|
|
templateUrl: "profile.component.html",
|
|
|
|
})
|
|
|
|
export class ProfileComponent implements OnInit {
|
|
|
|
loading = true;
|
|
|
|
profile: ProfileResponse;
|
2018-11-15 05:13:50 +01:00
|
|
|
fingerprint: string;
|
2021-11-09 19:24:26 +01:00
|
|
|
hidePasswordHint = false;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-06-21 17:43:50 +02:00
|
|
|
formPromise: Promise<any>;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-12-14 17:10:26 +01:00
|
|
|
constructor(
|
|
|
|
private apiService: ApiService,
|
|
|
|
private i18nService: I18nService,
|
|
|
|
private platformUtilsService: PlatformUtilsService,
|
|
|
|
private cryptoService: CryptoService,
|
|
|
|
private logService: LogService,
|
|
|
|
private keyConnectorService: KeyConnectorService,
|
|
|
|
private stateService: StateService
|
|
|
|
) {}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-06-21 17:43:50 +02:00
|
|
|
async ngOnInit() {
|
|
|
|
this.profile = await this.apiService.getProfile();
|
|
|
|
this.loading = false;
|
2021-12-14 17:10:26 +01:00
|
|
|
const fingerprint = await this.cryptoService.getFingerprint(
|
|
|
|
await this.stateService.getUserId()
|
|
|
|
);
|
2018-11-15 05:13:50 +01:00
|
|
|
if (fingerprint != null) {
|
|
|
|
this.fingerprint = fingerprint.join("-");
|
2018-06-21 17:43:50 +02:00
|
|
|
}
|
2021-11-09 19:24:26 +01:00
|
|
|
this.hidePasswordHint = await this.keyConnectorService.getUsesKeyConnector();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 17:43:50 +02:00
|
|
|
async submit() {
|
|
|
|
try {
|
|
|
|
const request = new UpdateProfileRequest(this.profile.name, this.profile.masterPasswordHint);
|
|
|
|
this.formPromise = this.apiService.putProfile(request);
|
|
|
|
await this.formPromise;
|
2021-12-07 20:41:45 +01:00
|
|
|
this.platformUtilsService.showToast("success", null, this.i18nService.t("accountUpdated"));
|
2021-10-20 18:30:04 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
2018-06-21 17:43:50 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-06-21 17:43:50 +02:00
|
|
|
}
|