2018-06-21 17:43:50 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
|
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-10-20 18:30:04 +02:00
|
|
|
import { LogService } from 'jslib-common/abstractions/log.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;
|
2018-06-21 17:43:50 +02:00
|
|
|
|
|
|
|
formPromise: Promise<any>;
|
|
|
|
|
|
|
|
constructor(private apiService: ApiService, private i18nService: I18nService,
|
2021-04-14 23:43:40 +02:00
|
|
|
private toasterService: ToasterService, private userService: UserService,
|
2021-10-20 18:30:04 +02:00
|
|
|
private cryptoService: CryptoService, private logService: LogService) { }
|
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('-');
|
|
|
|
}
|
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;
|
|
|
|
this.toasterService.popAsync('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
|
|
|
}
|
|
|
|
}
|