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-06-07 20:13:58 +02:00
|
|
|
import { UserService } from 'jslib-common/abstractions/user.service';
|
2018-06-21 17:43:50 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { UpdateProfileRequest } from 'jslib-common/models/request/updateProfileRequest';
|
2018-06-21 17:43:50 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
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;
|
2018-06-21 17:43:50 +02:00
|
|
|
|
|
|
|
formPromise: Promise<any>;
|
|
|
|
|
|
|
|
constructor(private apiService: ApiService, private i18nService: I18nService,
|
2021-12-07 20:41:45 +01:00
|
|
|
private platformUtilsService: PlatformUtilsService, private userService: UserService,
|
2021-11-09 19:24:26 +01:00
|
|
|
private cryptoService: CryptoService, private logService: LogService,
|
|
|
|
private keyConnectorService: KeyConnectorService) { }
|
2018-06-21 17:43:50 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
this.profile = await this.apiService.getProfile();
|
|
|
|
this.loading = false;
|
2018-11-15 05:13:50 +01:00
|
|
|
const fingerprint = await this.cryptoService.getFingerprint(await this.userService.getUserId());
|
|
|
|
if (fingerprint != null) {
|
|
|
|
this.fingerprint = fingerprint.join('-');
|
|
|
|
}
|
2021-11-09 19:24:26 +01:00
|
|
|
this.hidePasswordHint = await this.keyConnectorService.getUsesKeyConnector();
|
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
|
|
|
}
|
|
|
|
}
|